archboot/usr/bin/archboot-create-container.sh

51 lines
1.7 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# created by Tobias Powalowski <tpowa@archlinux.org>
2021-09-23 09:22:27 +02:00
_PWD="$(pwd)"
_BASENAME="$(basename "${0}")"
2021-09-23 09:14:28 +02:00
_CACHEDIR=""$1"/var/cache/pacman/pkg"
usage () {
echo "${_BASENAME}: usage"
echo "CREATE ARCHBOOT CONTAINER"
echo "-----------------------------"
echo "Usage: ${_BASENAME} <directory>"
echo "This will create an archboot container for an archboot image."
exit 0
}
[[ -z "${1}" ]] && usage
### 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
# prepare pacman dirs
mkdir -p "$1"/var/lib/pacman
mkdir -p "${_CACHEDIR}"
# install archboot
pacman --root "$1" -Sy base archboot archboot-linux-firmware --noconfirm --cachedir "${_PWD}"/"${_CACHEDIR}"
# generate locales
2021-09-23 09:14:28 +02:00
systemd-nspawn -D "$1" /bin/bash -c "echo 'en_US ISO-8859-1' >> /etc/locale.gen"
systemd-nspawn -D "$1" /bin/bash -c "echo 'en_US.UTF-8 UTF-8' >> /etc/locale.gen"
systemd-nspawn -D "$1" locale-gen
# generate pacman keyring
2021-09-23 09:14:28 +02:00
systemd-nspawn -D "$1" pacman-key --init
systemd-nspawn -D "$1" pacman-key --populate archlinux
# add genneral mirror
2021-09-23 09:14:28 +02:00
systemd-nspawn -D "$1" /bin/bash -c "echo 'Server = https://mirror.rackspace.com/archlinux/\$repo/os/\$arch' >> /etc/pacman.d/mirrorlist"
# disable checkspace option in pacman.conf, to allow to install packages in environment
2021-09-23 09:14:28 +02:00
systemd-nspawn -D "$1" /bin/bash -c "sed -i -e 's:^CheckSpace:#CheckSpace:g' /etc/pacman.conf"
2021-09-22 15:00:43 +02:00
# enable parallel downloads
2021-09-23 09:14:28 +02:00
systemd-nspawn -D "$1" /bin/bash -c "sed -i -e 's:^#ParallelDownloads:ParallelDownloads:g' /etc/pacman.conf"
# reinstall kernel to get files in /boot
2021-09-23 09:14:28 +02:00
systemd-nspawn -D "$1" pacman -Sy linux --noconfirm
# clean cache
systemd-nspawn -D "$1" pacman -Scc --noconfirm
# clean container from not needed files
rm -r "$1"/usr/include
rm -r "$1"/usr/share/{man,doc}
2021-09-24 09:34:07 +02:00