mirror of
https://gitlab.archlinux.org/tpowa/archboot.git
synced 2024-09-20 03:50:37 +02:00
107 lines
3.9 KiB
Bash
Executable file
107 lines
3.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# created by Tobias Powalowski <tpowa@archlinux.org>
|
|
_PWD="$(pwd)"
|
|
_BASENAME="$(basename "${0}")"
|
|
_CACHEDIR=""$1"/var/cache/pacman/pkg"
|
|
_CLEANUP_CACHE=""
|
|
_SAVE_RAM=""
|
|
_LINUX_FIRMWARE=""
|
|
_DIR=""
|
|
|
|
usage () {
|
|
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"
|
|
echo " -lf add linux-firmware to container"
|
|
echo " -alf add archboot-linux-firmware to container"
|
|
exit 0
|
|
}
|
|
|
|
[[ -z "${1}" ]] && usage
|
|
|
|
_DIR="$1"
|
|
|
|
while [ $# -gt 0 ]; do
|
|
case ${1} in
|
|
-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
|
|
|
|
### check for root
|
|
if ! [[ ${UID} -eq 0 ]]; then
|
|
echo "ERROR: Please run as root user!"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
# prepare pacman dirs
|
|
mkdir -p "${_DIR}"/var/lib/pacman
|
|
mkdir -p "${_CACHEDIR}"
|
|
[[ -e "${_DIR}/proc" ]] || mkdir -m 555 "${_DIR}/proc"
|
|
[[ -e "${_DIR}/sys" ]] || mkdir -m 555 "${_DIR}/sys"
|
|
[[ -e "${_DIR}/dev" ]] || mkdir -m 755 "${_DIR}/dev"
|
|
# mount special filesystems to ${_DIR}
|
|
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
|
|
# install archboot
|
|
echo "Installing packages base and archboot ..."
|
|
pacman --root "${_DIR}" -Sy base archboot --ignore systemd-resolvconf --noconfirm --cachedir "${_PWD}"/"${_CACHEDIR}"
|
|
# umount special filesystems
|
|
umount -R ""${_DIR}"/proc"
|
|
umount -R ""${_DIR}"/sys"
|
|
umount -R ""${_DIR}"/dev"
|
|
# generate locales
|
|
echo "Create locales ..."
|
|
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
|
|
# generate pacman keyring
|
|
echo "Generate pacman keyring ..."
|
|
systemd-nspawn -D "${_DIR}" pacman-key --init >/dev/null 2>&1
|
|
systemd-nspawn -D "${_DIR}" pacman-key --populate archlinux >/dev/null 2>&1
|
|
# copy local mirrorlist to container
|
|
echo "Create pacman config and mirrorlist ..."
|
|
cp /etc/pacman.d/mirrorlist "${_DIR}"/etc/pacman.d/mirrorlist
|
|
# only copy from archboot pacman.conf, else use default file
|
|
[[ "$(cat /etc/hostname)" == "archboot" ]] && cp /etc/pacman.conf "${_DIR}"/etc/pacman.conf
|
|
# disable checkspace option in pacman.conf, to allow to install packages in environment
|
|
sed -i -e 's:^CheckSpace:#CheckSpace:g' "${_DIR}"/etc/pacman.conf
|
|
# enable parallel downloads
|
|
sed -i -e 's:^#ParallelDownloads:ParallelDownloads:g' "${_DIR}"/etc/pacman.conf
|
|
# enable [testing] if enabled in host
|
|
if [[ "$(grep "^\[testing" /etc/pacman.conf)" ]]; then
|
|
echo "Enable [testing] repository ..."
|
|
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
|
|
# install firmware package
|
|
if [[ ! -z ${_LINUX_FIRMWARE} ]]; then
|
|
echo "Installing ${_LINUX_FIRMWARE} ..."
|
|
systemd-nspawn -D "${_DIR}" pacman -Sy "${_LINUX_FIRMWARE}" --noconfirm >/dev/null 2>&1
|
|
fi
|
|
|
|
if [[ "${_SAVE_RAM}" == "1" ]]; then
|
|
# clean container from not needed files
|
|
echo "Clean container, delete not needed files ..."
|
|
rm -r "${_DIR}"/usr/include
|
|
rm -r "${_DIR}"/usr/share/{man,doc}
|
|
fi
|
|
|
|
if [[ "${_CLEANUP_CACHE}" == "1" ]]; then
|
|
# clean cache
|
|
echo "Clean pacman cache ..."
|
|
rm -r "${_DIR}"/var/cache/pacman
|
|
fi
|
|
echo "Finished container setup in ${_DIR}"
|