2021-09-10 20:21:23 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# created by Tobias Powalowski <tpowa@archlinux.org>
|
2021-09-23 09:22:27 +02:00
|
|
|
_PWD="$(pwd)"
|
2021-09-10 20:21:23 +02:00
|
|
|
_BASENAME="$(basename "${0}")"
|
2022-01-21 11:59:06 +01:00
|
|
|
_CACHEDIR="$1/var/cache/pacman/pkg"
|
2021-09-25 13:45:22 +02:00
|
|
|
_CLEANUP_CACHE=""
|
|
|
|
_SAVE_RAM=""
|
2022-01-20 06:53:39 +01:00
|
|
|
_LINUX_FIRMWARE="linux-firmware"
|
2021-09-25 14:02:02 +02:00
|
|
|
_DIR=""
|
2021-09-23 09:14:28 +02:00
|
|
|
|
2021-09-10 20:21:23 +02:00
|
|
|
usage () {
|
2022-01-21 07:16:45 +01:00
|
|
|
echo "CREATE ARCHBOOT CONTAINER"
|
|
|
|
echo "-----------------------------"
|
|
|
|
echo "This will create an archboot container for an archboot image."
|
|
|
|
echo "Usage: ${_BASENAME} <directory> <options>"
|
|
|
|
echo " Options:"
|
|
|
|
echo " -cc Cleanup container eg. remove manpages, includes ..."
|
|
|
|
echo " -cp Cleanup container package cache"
|
|
|
|
exit 0
|
2021-09-10 20:21:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[[ -z "${1}" ]] && usage
|
|
|
|
|
2021-09-25 14:02:02 +02:00
|
|
|
_DIR="$1"
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
2022-01-21 07:16:45 +01:00
|
|
|
case ${1} in
|
|
|
|
-cc|--cc) _SAVE_RAM="1" ;;
|
|
|
|
-cp|--cp) _CLEANUP_CACHE="1" ;;
|
|
|
|
esac
|
|
|
|
shift
|
2021-09-25 13:45:22 +02:00
|
|
|
done
|
|
|
|
|
2021-09-10 20:21:23 +02:00
|
|
|
### check for root
|
|
|
|
if ! [[ ${UID} -eq 0 ]]; then
|
2022-01-21 07:16:45 +01:00
|
|
|
echo "ERROR: Please run as root user!"
|
|
|
|
exit 1
|
2021-09-10 20:21:23 +02:00
|
|
|
fi
|
2022-01-14 14:11:15 +01:00
|
|
|
### check for x86_64
|
|
|
|
if ! [[ "$(uname -m)" == "x86_64" ]]; then
|
|
|
|
echo "ERROR: Pleae run on x86_64 hardware."
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-09-23 09:14:28 +02:00
|
|
|
# prepare pacman dirs
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Starting container creation ..."
|
|
|
|
echo "Create directories in ${_DIR} ..."
|
2021-09-25 14:02:02 +02:00
|
|
|
mkdir -p "${_DIR}"/var/lib/pacman
|
2021-09-23 09:14:28 +02:00
|
|
|
mkdir -p "${_CACHEDIR}"
|
2021-10-08 07:57:49 +02:00
|
|
|
[[ -e "${_DIR}/proc" ]] || mkdir -m 555 "${_DIR}/proc"
|
|
|
|
[[ -e "${_DIR}/sys" ]] || mkdir -m 555 "${_DIR}/sys"
|
|
|
|
[[ -e "${_DIR}/dev" ]] || mkdir -m 755 "${_DIR}/dev"
|
2021-10-08 08:53:42 +02:00
|
|
|
# mount special filesystems to ${_DIR}
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Mount special filesystems in ${_DIR} ..."
|
2022-01-21 11:59:06 +01:00
|
|
|
mount proc "${_DIR}/proc" -t proc -o nosuid,noexec,nodev
|
|
|
|
mount sys "${_DIR}/sys" -t sysfs -o nosuid,noexec,nodev,ro
|
|
|
|
mount udev "${_DIR}/dev" -t devtmpfs -o mode=0755,nosuid
|
|
|
|
mount devpts "${_DIR}/dev/pts" -t devpts -o mode=0620,gid=5,nosuid,noexec
|
|
|
|
mount shm "${_DIR}/dev/shm" -t tmpfs -o mode=1777,nosuid,nodev
|
2021-09-21 19:40:33 +02:00
|
|
|
# install archboot
|
2022-02-03 00:10:37 +01:00
|
|
|
echo "Installing packages base linux and ${_LINUX_FIRMWARE} to ${_DIR} ..."
|
2022-02-02 23:55:52 +01:00
|
|
|
pacman --root "${_DIR}" -Sy base linux "${_LINUX_FIRMWARE}" --ignore systemd-resolvconf --noconfirm --cachedir "${_PWD}"/"${_CACHEDIR}" >/dev/null 2>&1
|
2022-02-03 13:10:52 +01:00
|
|
|
rm "${_DIR}"/boot/{initramfs-linux.img,initramfs-linux-fallback.img}
|
|
|
|
if [[ "${_CLEANUP_CACHE}" == "1" ]]; then
|
|
|
|
# clean cache
|
|
|
|
echo "Clean pacman cache from ${_DIR} ..."
|
|
|
|
rm -r "${_DIR}"/var/cache/pacman
|
|
|
|
fi
|
2022-02-02 23:55:52 +01:00
|
|
|
echo "Installing archboot to ${_DIR} ..."
|
|
|
|
pacman --root "${_DIR}" -Sy archboot --ignore systemd-resolvconf --noconfirm >/dev/null 2>&1
|
2022-02-03 13:10:52 +01:00
|
|
|
if [[ "${_SAVE_RAM}" == "1" ]]; then
|
|
|
|
# clean container from not needed files
|
|
|
|
echo "Clean container, delete not needed files from ${_DIR} ..."
|
|
|
|
rm -r "${_DIR}"/usr/include
|
2022-02-04 16:56:00 +01:00
|
|
|
rm -r "${_DIR}"/usr/share/{aclocal,applications,audit,avahi,awk,bash-completion,cmake,common-lisp,cracklib,dhclient,dhcpcd,dict,dnsmasq,emacs,et,fish,gdb,gettext,gettext-0.21,glib-2.0,gnupg,graphite2,gtk-doc,iana-etc,icons,icu,iptables,java,keyutils,libalpm,libgpg-error,makepkg-template,misc,mkinitcpio,ncat,ntp,p11-kit,readline,screen,smartmontools,ss,stoken,tabset,texinfo,vala,xml,xtables,zoneinfo-leaps,man,doc,info,perl5}
|
|
|
|
rm -r "${_DIR}"/usr/lib/{audit,avahi,awk,bash,bfd-plugins,binfmt.d,cifs-utils,cmake,coreutils,cryptsetup,cups,dracut,e2fsprogs,engines-1.1,environment.d,gawk,getconf,gettext,girepository-1.0,glib-2.0,gnupg,gssproxy,guile,icu,itcl4.2.2,iwd,kexec-tools,krb5,ldb,ldscripts,libnl,libproxy,named,ntfs-3g,openconnect,openssl-1.0,p11-kit,pcsc,perl5,pkcs11,pkgconfig,rsync,samba,sasl2,siconv,sysctl.d,sysusers.d,tar,tcl8.6,tcl8,tdbc1.1.3,tdbcmysql1.1.3,tdbcodbc1.1.3,tdbcpostgres1.1.3,terminfo,texinfo,thread2.8.7,valgrind,xfsprogs,xplc-0.3.13,xtables}
|
2022-02-03 13:10:52 +01:00
|
|
|
fi
|
2022-02-02 23:55:52 +01:00
|
|
|
# Clean cache on archboot environment
|
|
|
|
if [[ "$(cat /etc/hostname)" == "archboot" ]]; then
|
|
|
|
echo "Cleaning /var/cache/pacman/pkg ..."
|
|
|
|
rm -r /var/cache/pacman/pkg
|
|
|
|
fi
|
2021-10-08 08:53:42 +02:00
|
|
|
# umount special filesystems
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Umount special filesystems in to ${_DIR} ..."
|
2022-01-21 11:59:06 +01:00
|
|
|
umount -R "${_DIR}/proc"
|
|
|
|
umount -R "${_DIR}/sys"
|
|
|
|
umount -R "${_DIR}/dev"
|
2021-09-21 19:40:33 +02:00
|
|
|
# generate locales
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Create locales in container ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
systemd-nspawn -D "${_DIR}" /bin/bash -c "echo 'en_US ISO-8859-1' >> /etc/locale.gen" >/dev/null 2>&1
|
|
|
|
systemd-nspawn -D "${_DIR}" /bin/bash -c "echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen" >/dev/null 2>&1
|
|
|
|
systemd-nspawn -D "${_DIR}" locale-gen >/dev/null 2>&1
|
2022-02-04 16:56:00 +01:00
|
|
|
[[ "${_SAVE_RAM}" == "1" ]] && rm -r "${_DIR}"/usr/share/{i18n,locale}
|
2021-09-21 19:40:33 +02:00
|
|
|
# generate pacman keyring
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Generate pacman keyring in container ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
systemd-nspawn -D "${_DIR}" pacman-key --init >/dev/null 2>&1
|
|
|
|
systemd-nspawn -D "${_DIR}" pacman-key --populate archlinux >/dev/null 2>&1
|
2021-09-27 10:41:44 +02:00
|
|
|
# copy local mirrorlist to container
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Create pacman config and mirrorlist in container..."
|
2021-09-27 10:41:44 +02:00
|
|
|
cp /etc/pacman.d/mirrorlist "${_DIR}"/etc/pacman.d/mirrorlist
|
2021-09-27 11:33:47 +02:00
|
|
|
# only copy from archboot pacman.conf, else use default file
|
|
|
|
[[ "$(cat /etc/hostname)" == "archboot" ]] && cp /etc/pacman.conf "${_DIR}"/etc/pacman.conf
|
2021-09-21 19:40:33 +02:00
|
|
|
# disable checkspace option in pacman.conf, to allow to install packages in environment
|
2021-09-27 11:33:47 +02:00
|
|
|
sed -i -e 's:^CheckSpace:#CheckSpace:g' "${_DIR}"/etc/pacman.conf
|
2021-09-22 15:00:43 +02:00
|
|
|
# enable parallel downloads
|
2021-09-27 11:33:47 +02:00
|
|
|
sed -i -e 's:^#ParallelDownloads:ParallelDownloads:g' "${_DIR}"/etc/pacman.conf
|
|
|
|
# enable [testing] if enabled in host
|
2022-01-21 11:59:06 +01:00
|
|
|
if grep -q "^\[testing" /etc/pacman.conf; then
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Enable [testing] repository in container ..."
|
2022-01-21 11:59:06 +01:00
|
|
|
sed -i -e '/^#\[testing\]/ { n ; s/^#// }' "${_DIR}/etc/pacman.conf"
|
|
|
|
sed -i -e '/^#\[community-testing\]/ { n ; s/^#// }' "${_DIR}/etc/pacman.conf"
|
|
|
|
sed -i -e 's:^#\[testing\]:\[testing\]:g' -e 's:^#\[community-testing\]:\[community-testing\]:g' "${_DIR}/etc/pacman.conf"
|
2021-09-27 11:33:47 +02:00
|
|
|
fi
|
2022-01-08 09:04:11 +01:00
|
|
|
echo "Setting hostname to archboot ..."
|
2022-01-12 18:57:10 +01:00
|
|
|
systemd-nspawn -D "${_DIR}" /bin/bash -c "echo archboot > /etc/hostname" >/dev/null 2>&1
|
2021-10-15 09:16:30 +02:00
|
|
|
echo "Finished container setup in ${_DIR} ."
|