archboot/usr/bin/archboot-update-installer.sh

88 lines
3.8 KiB
Bash
Raw Normal View History

#!/usr/bin/env bash
# created by Tobias Powalowski <tpowa@archlinux.org>
2021-09-22 09:02:56 +02:00
_BASENAME="$(basename "${0}")"
D_SCRIPTS=""
L_COMPLETE=""
2021-09-25 18:00:13 +02:00
L_INSTALL_COMPLETE=""
2021-09-22 09:02:56 +02:00
G_RELEASE=""
CONFIG="/etc/archboot/x86_64.conf"
2021-09-23 09:14:28 +02:00
W_DIR="archboot"
INSTALLER_SOURCE="https://gitlab.archlinux.org/tpowa/archboot/-/raw/master/usr/bin"
2021-09-22 09:02:56 +02:00
usage () {
2021-09-22 18:59:33 +02:00
echo "Update installer, launch latest environment or create latest image files:"
echo "---------------------------------------------------------------------------"
2021-09-22 09:02:56 +02:00
echo "PARAMETERS:"
echo " -u Update scripts: setup, quickinst, tz, km and helpers."
2021-09-22 18:59:33 +02:00
echo ""
echo "On fast internet connection (100Mbit) (approx. 5 minutes):"
echo " -latest Launch latest archboot environment (using kexec)."
echo " This operation needs at least 3500 MB RAM."
echo ""
echo " -latest-install Launch latest archboot environment with downloaded"
echo " package cache (using kexec)."
echo " This operation needs at least 4500 MB RAM."
2021-09-22 18:59:33 +02:00
echo ""
echo " -latest-image Generate latest image files in /archboot-release directory"
2021-09-24 17:21:01 +02:00
echo " This operation needs at least 4000 MB RAM."
2021-09-22 18:59:33 +02:00
echo ""
echo " -h This message."
2021-09-22 09:02:56 +02:00
exit 0
}
[[ -z "${1}" ]] && usage
while [ $# -gt 0 ]; do
case ${1} in
-u|--u) D_SCRIPTS="1" ;;
2021-09-22 18:59:33 +02:00
-latest|--latest) L_COMPLETE="1" ;;
2021-09-25 17:50:50 +02:00
-latest-install|--latest-install) L_INSTALL_COMPLETE="1";;
2021-09-22 18:59:33 +02:00
-latest-image|--latest-image) G_RELEASE="1" ;;
2021-09-22 09:02:56 +02:00
-h|--h|?) usage ;;
*) usage ;;
esac
shift
done
# Download latest setup and quickinst script from git repository
2021-09-22 09:02:56 +02:00
if [[ "${D_SCRIPTS}" == "1" ]]; then
2021-09-22 19:48:24 +02:00
echo 'Downloading latest km, tz, quickinst,setup and helpers...'
2021-09-22 09:02:56 +02:00
[[ -e /usr/bin/quickinst ]] && wget -q "$INSTALLER_SOURCE/archboot-quickinst.sh?inline=false" -O /usr/bin/quickinst
[[ -e /usr/bin/setup ]] && wget -q "$INSTALLER_SOURCE/archboot-setup.sh?inline=false" -O /usr/bin/setup
[[ -e /usr/bin/km ]] && wget -q "$INSTALLER_SOURCE/archboot-km.sh?inline=false" -O /usr/bin/km
[[ -e /usr/bin/tz ]] && wget -q "$INSTALLER_SOURCE/archboot-tz.sh?inline=false" -O /usr/bin/tz
2021-09-22 18:59:33 +02:00
[[ -e /usr/bin/archboot-create-container.sh ]] && wget -q "$INSTALLER_SOURCE/archboot-create-container.sh?inline=false" -O /usr/bin/archboot-create-container.sh
[[ -e /usr/bin/archboot-x86_64-release.sh ]] && wget -q "$INSTALLER_SOURCE/archboot-x86_64-release.sh?inline=false" -O /usr/bin/archboot-x86_64-release.sh
[[ -e /usr/bin/update-installer.sh ]] && wget -q "$INSTALLER_SOURCE/archboot-update-installer.sh?inline=false" -O /usr/bin/update-installer.sh
2021-09-22 09:02:56 +02:00
fi
# Generate new environment and launch it with kexec
2021-09-25 17:49:18 +02:00
if [[ "${L_COMPLETE}" == "1" || "${L_INSTALL_COMPLETE}" == "1" ]]; then
2021-09-22 09:02:56 +02:00
# create container
2021-09-25 18:03:43 +02:00
if [[ "${L_COMPLETE}" == "1" ]]; then
archboot-create-container.sh "${W_DIR}" -cc -cp -alf || exit 1
fi
if [[ "${L_INSTALL_COMPLETE}" == "1" ]]; then
archboot-create-container.sh "${W_DIR}" -cc -alf || exit 1
fi
2021-09-25 20:10:26 +02:00
# generate initrd in container, remove archboot packages from cache, not needed in normal install, umount tmp before generating initrd
systemd-nspawn -D "${W_DIR}" /bin/bash -c "rm /var/cache/pacman/pkg/archboot-*; umount /tmp;mkinitcpio -c ${CONFIG} -g /tmp/initrd.img; mv /tmp/initrd.img /" || exit 1
2021-09-23 09:14:28 +02:00
mv "${W_DIR}"/initrd.img /
mv "${W_DIR}"/boot/vmlinuz-linux /
mv "${W_DIR}"/boot/intel-ucode.img /
mv "${W_DIR}"/boot/amd-ucode.img /
# remove "${W_DIR}"
rm -r "${W_DIR}"
# load kernel and initrds into running kernel
kexec -l /vmlinuz-linux --initrd=/intel-ucode.img --initrd=/amd-ucode.img --initrd=/initrd.img --reuse-cmdline
# restart environment
2021-09-22 09:02:56 +02:00
systemctl kexec
fi
2021-09-22 09:02:56 +02:00
# Generate new images
if [[ "${G_RELEASE}" == "1" ]]; then
2021-09-23 09:14:28 +02:00
archboot-x86_64-release.sh "${W_DIR}"
2021-09-22 09:02:56 +02:00
fi