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

129 lines
6.1 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
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=""
2022-01-08 09:39:59 +01:00
CONFIG="/etc/archboot/$(uname -m).conf"
2021-10-07 15:15:20 +02:00
W_DIR="/archboot"
2021-09-23 09:14:28 +02:00
INSTALLER_SOURCE="https://gitlab.archlinux.org/tpowa/archboot/-/raw/master/usr/bin"
LOG="/dev/tty7"
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:"
2021-10-07 07:22:05 +02:00
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)."
2021-12-12 14:22:27 +01:00
echo " This operation needs at least 3 GB RAM."
echo ""
echo " -latest-install Launch latest archboot environment with downloaded"
echo " package cache (using kexec)."
2021-12-12 14:22:27 +01:00
echo " This operation needs at least 4 GB RAM."
2021-09-22 18:59:33 +02:00
echo ""
2021-10-08 16:38:42 +02:00
echo " -latest-image Generate latest image files in /archboot-release directory"
2021-12-12 14:22:27 +01:00
echo " This operation needs at least 4 GB RAM."
2021-09-22 18:59:33 +02:00
echo ""
2021-10-08 16:38:42 +02:00
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
if [[ ! "$(cat /etc/hostname)" == "archboot" ]]; then
echo "This script should only be run in booted archboot environment. Aborting..."
exit 1
fi
# Download latest setup and quickinst script from git repository
2021-10-06 17:35:33 +02:00
if [[ "${D_SCRIPTS}" == "1" ]]; then
2021-10-06 17:49:16 +02:00
echo "Downloading latest km, tz, quickinst, setup and helpers..."
2021-10-07 07:22:05 +02:00
[[ -e /usr/bin/quickinst ]] && wget -q "$INSTALLER_SOURCE/archboot-quickinst.sh?inline=false" -O /usr/bin/quickinst >/dev/null 2>&1
[[ -e /usr/bin/setup ]] && wget -q "$INSTALLER_SOURCE/archboot-setup.sh?inline=false" -O /usr/bin/setup >/dev/null 2>&1
[[ -e /usr/bin/km ]] && wget -q "$INSTALLER_SOURCE/archboot-km.sh?inline=false" -O /usr/bin/km >/dev/null 2>&1
[[ -e /usr/bin/tz ]] && wget -q "$INSTALLER_SOURCE/archboot-tz.sh?inline=false" -O /usr/bin/tz >/dev/null 2>&1
2022-01-08 09:51:29 +01:00
[[ -e /usr/bin/archboot-$(uname -m)-create-container.sh ]] && wget -q "$INSTALLER_SOURCE/archboot-$(uname -m)-create-container.sh?inline=false" -O /usr/bin/archboot-$(uname -m)-create-container.sh >/dev/null 2>&1
[[ -e /usr/bin/archboot-$(uname -m)-release.sh ]] && wget -q "$INSTALLER_SOURCE/archboot-$(uname -m)-release.sh?inline=false" -O /usr/bin/archboot-$(uname -m)-release.sh >/dev/null 2>&1
2021-10-07 07:22:05 +02:00
[[ -e /usr/bin/update-installer.sh ]] && wget -q "$INSTALLER_SOURCE/archboot-update-installer.sh?inline=false" -O /usr/bin/update-installer.sh >/dev/null 2>&1
2021-10-07 07:48:14 +02:00
echo "Finished: Downloading scripts done."
2021-10-08 10:04:39 +02:00
exit 0
2021-09-22 09:02:56 +02:00
fi
2021-10-08 10:04:39 +02:00
echo "Information: Logging is done on /dev/tty7 ..."
2021-09-22 09:02:56 +02:00
# 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
# remove everything not necessary
2021-10-07 07:22:05 +02:00
echo "Step 1/6: Removing not necessary files from /usr ..."
rm -r /lib/{firmware,modules} >/dev/tty7 2>&1
2022-01-09 18:45:37 +01:00
rm -r /usr/share/{efitools,file,grub,hwdata,kbd,licenses,nmap,openvpn,refind,tc,usb_modeswitch,vim,zoneinfo,zsh} >/dev/tty7 2>&1
2021-09-26 08:52:27 +02:00
# create container without package cache
2021-09-25 18:03:43 +02:00
if [[ "${L_COMPLETE}" == "1" ]]; then
2021-10-07 07:22:05 +02:00
echo "Step 2/6: Generating archboot container in "${W_DIR}" ..."
echo " This will need some time ..."
2022-01-08 09:39:59 +01:00
archboot-$(uname -m)-create-container.sh "${W_DIR}" -cc -cp -alf >/dev/tty7 2>&1 || exit 1
2021-09-25 18:03:43 +02:00
fi
2021-09-26 08:52:27 +02:00
# create container with package cache
2021-09-25 18:03:43 +02:00
if [[ "${L_INSTALL_COMPLETE}" == "1" ]]; then
2021-10-07 07:22:05 +02:00
echo "Step 2/6: Generating archboot container in "${W_DIR}" ..."
echo " This will need some time ..."
2022-01-08 09:39:59 +01:00
archboot-$(uname -m)-create-container.sh "${W_DIR}" -cc -alf >/dev/tty7 2>&1 || exit 1
2021-09-25 18:03:43 +02:00
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
2021-10-07 07:22:05 +02:00
echo "Step 3/6: Generating initramfs in "${W_DIR}" ..."
echo " This will need some time ..."
2021-11-30 18:37:03 +01:00
# add fix for mkinitcpio 31, remove when 32 is released
cp "${W_DIR}"/usr/lib/initcpio/functions "${W_DIR}"/usr/lib/initcpio/functions.old
2021-11-30 18:37:03 +01:00
cp "${W_DIR}"/usr/share/archboot/patches/31-initcpio.functions.fixed "${W_DIR}"/usr/lib/initcpio/functions
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 /" >/dev/tty7 2>&1 || exit 1
mv "${W_DIR}"/usr/lib/initcpio/functions.old "${W_DIR}"/usr/lib/initcpio/functions
2021-10-07 07:22:05 +02:00
echo "Step 4/6: Moving initramfs files from "${W_DIR}" to / ..."
mv "${W_DIR}"/initrd.img / || exit 1
2022-01-08 09:39:59 +01:00
if [[ "$(uname -m)" == "x86_64" ]]; then
mv "${W_DIR}"/boot/vmlinuz-linux / || exit 1
mv "${W_DIR}"/boot/intel-ucode.img / || exit 1
fi
if [[ "$(uname -m)" == "aarch64" ]]; then
mv "${W_DIR}"/boot/Image / || exit 1
fi
mv "${W_DIR}"/boot/amd-ucode.img / || exit 1
2021-09-23 09:14:28 +02:00
# remove "${W_DIR}"
2021-10-07 07:22:05 +02:00
echo "Step 5/6: Remove ${W_DIR} ..."
rm -r "${W_DIR}" || exit 1
2021-10-07 07:22:05 +02:00
echo "Step 6/6: Loading files to kexec now, reboot in a few seconds ..."
# load kernel and initrds into running kernel
2022-01-08 09:39:59 +01:00
if [[ "$(uname -m)" == "x86_64" ]]; then
kexec -l /vmlinuz-linux --initrd=/intel-ucode.img --initrd=/amd-ucode.img --initrd=/initrd.img --reuse-cmdline
fi
if [[ "$(uname -m)" == "aarch64" ]]; then
kexec -l /Image --initrd=/amd-ucode.img --initrd=/initrd.img --reuse-cmdline
fi
2021-10-07 07:22:05 +02:00
echo "Finished: Rebooting ..."
# 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-10-07 07:22:05 +02:00
echo "Step 1/1: Generating new iso files now in "${W_DIR}" ..."
echo " This will need some time ..."
2022-01-08 09:39:59 +01:00
archboot-$(uname -m)-release.sh "${W_DIR}" >/dev/tty7 2>&1 || exit 1
2021-10-07 07:22:05 +02:00
echo "Finished: New isofiles are located in "${W_DIR}""
2021-09-22 09:02:56 +02:00
fi