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}")"
|
2021-09-23 09:14:28 +02:00
|
|
|
_CACHEDIR=""$1"/var/cache/pacman/pkg"
|
2021-09-25 13:45:22 +02:00
|
|
|
_CLEANUP_CACHE=""
|
|
|
|
_SAVE_RAM=""
|
|
|
|
_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 () {
|
|
|
|
echo "CREATE ARCHBOOT CONTAINER"
|
|
|
|
echo "-----------------------------"
|
|
|
|
echo "This will create an archboot container for an archboot image."
|
2021-09-25 13:45:22 +02:00
|
|
|
echo "Usage: ${_BASENAME} <directory> <options>"
|
|
|
|
echo " Options:"
|
2021-09-25 17:29:40 +02:00
|
|
|
echo " -cc Cleanup container eg. remove manpages, includes ..."
|
2021-09-25 13:45:22 +02:00
|
|
|
echo " -cp Cleanup container package cache"
|
|
|
|
echo " -lf add linux-firmware to container"
|
|
|
|
echo " -alf add archboot-linux-firmware to container"
|
2021-09-10 20:21:23 +02:00
|
|
|
exit 0
|
|
|
|
}
|
|
|
|
|
|
|
|
[[ -z "${1}" ]] && usage
|
|
|
|
|
2021-09-25 14:02:02 +02:00
|
|
|
_DIR="$1"
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
2021-09-25 14:19:47 +02:00
|
|
|
case ${1} in
|
2021-09-25 13:45:22 +02:00
|
|
|
-cc|--cc) _SAVE_RAM="1" ;;
|
|
|
|
-cp|--cp) _CLEANUP_CACHE="1" ;;
|
|
|
|
-lf|--lf) _LINUX_FIRMWARE="linux-firmware" ;;
|
|
|
|
-alf|-alf) _LINUX_FIRMWARE="archboot-linux-firmware" ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-09-10 20:21:23 +02:00
|
|
|
### check for root
|
|
|
|
if ! [[ ${UID} -eq 0 ]]; then
|
|
|
|
echo "ERROR: Please run as root user!"
|
|
|
|
exit 1
|
|
|
|
fi
|
2021-09-23 09:14:28 +02:00
|
|
|
|
2021-09-25 13:45:22 +02:00
|
|
|
|
2021-09-23 09:14:28 +02:00
|
|
|
# prepare pacman dirs
|
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-09-21 19:40:33 +02:00
|
|
|
# install archboot
|
2021-09-25 14:02:02 +02:00
|
|
|
pacman --root "${_DIR}" -Sy base archboot --noconfirm --cachedir "${_PWD}"/"${_CACHEDIR}"
|
2021-09-21 19:40:33 +02:00
|
|
|
# generate locales
|
2021-09-25 14:02:02 +02:00
|
|
|
systemd-nspawn -D "${_DIR}" /bin/bash -c "echo 'en_US ISO-8859-1' >> /etc/locale.gen"
|
|
|
|
systemd-nspawn -D "${_DIR}" /bin/bash -c "echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen"
|
|
|
|
systemd-nspawn -D "${_DIR}" locale-gen
|
2021-09-21 19:40:33 +02:00
|
|
|
# generate pacman keyring
|
2021-09-25 14:02:02 +02:00
|
|
|
systemd-nspawn -D "${_DIR}" pacman-key --init
|
|
|
|
systemd-nspawn -D "${_DIR}" pacman-key --populate archlinux
|
2021-09-27 10:41:44 +02:00
|
|
|
# copy local mirrorlist to container
|
|
|
|
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
|
2021-09-27 11:59:21 +02:00
|
|
|
if [[ "$(grep "^\[testing" /etc/pacman.conf)" ]]; then
|
2021-09-27 11:33:47 +02: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
|
|
|
|
fi
|
2021-09-25 13:45:22 +02:00
|
|
|
# reinstall kernel to get files in /boot and firmware package
|
2021-09-25 14:02:02 +02:00
|
|
|
systemd-nspawn -D "${_DIR}" pacman -Sy linux --noconfirm
|
2021-09-25 14:19:47 +02:00
|
|
|
[[ ! -z ${_LINUX_FIRMWARE} ]] && systemd-nspawn -D "${_DIR}" pacman -Sy "${_LINUX_FIRMWARE}" --noconfirm
|
2021-09-24 13:42:02 +02:00
|
|
|
|
2021-09-25 17:29:40 +02:00
|
|
|
if [[ "${_SAVE_RAM}" == "1" ]]; then
|
2021-09-25 13:45:22 +02:00
|
|
|
# clean container from not needed files
|
2021-09-25 14:02:02 +02:00
|
|
|
rm -r "${_DIR}"/usr/include
|
|
|
|
rm -r "${_DIR}"/usr/share/{man,doc}
|
2021-09-25 13:45:22 +02:00
|
|
|
fi
|
2021-09-24 09:34:07 +02:00
|
|
|
|
2021-09-25 13:45:22 +02:00
|
|
|
if [[ "${_CLEANUP_CACHE}" == "1" ]]; then
|
|
|
|
# clean cache
|
2021-09-25 17:29:40 +02:00
|
|
|
rm -r "${_DIR}"/var/cache/pacman
|
2021-09-25 13:45:22 +02:00
|
|
|
fi
|