2021-09-15 07:35:02 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
# created by Tobias Powalowski <tpowa@archlinux.org>
|
2022-03-21 22:25:15 +01:00
|
|
|
. /usr/lib/archboot/common.sh
|
2022-01-13 17:21:39 +01:00
|
|
|
_D_SCRIPTS=""
|
|
|
|
_L_COMPLETE=""
|
|
|
|
_L_INSTALL_COMPLETE=""
|
|
|
|
_G_RELEASE=""
|
2022-02-05 10:07:00 +01:00
|
|
|
_CONFIG="/etc/archboot/${_RUNNING_ARCH}-update_installer.conf"
|
2022-01-13 17:21:39 +01:00
|
|
|
_W_DIR="/archboot"
|
2022-03-07 22:47:42 +01:00
|
|
|
_INSTALLER_SOURCE="https://gitlab.archlinux.org/tpowa/archboot/-/raw/master"
|
2022-03-24 16:24:43 +01:00
|
|
|
_BIN_PATH="/usr/bin"
|
|
|
|
_LIB_PATH="/usr/lib/archboot"
|
|
|
|
_INST_PATH="/${_LIB_PATH}/installer"
|
2021-09-22 09:02:56 +02:00
|
|
|
|
2022-02-03 07:14:49 +01:00
|
|
|
kver() {
|
|
|
|
# get kernel version from installed kernel
|
2022-03-24 16:20:05 +01:00
|
|
|
[[ "${_RUNNING_ARCH}" == "x86_64" ]] && VMLINUZ="vmlinuz-linux"
|
|
|
|
[[ "${_RUNNING_ARCH}" == "aarch64" ]] && VMLINUZ="Image"
|
2022-02-03 07:14:49 +01:00
|
|
|
if [[ -f "${VMLINUZ}" ]]; then
|
|
|
|
offset=$(hexdump -s 526 -n 2 -e '"%0d"' "${VMLINUZ}")
|
2022-03-24 16:20:05 +01:00
|
|
|
read -r _HWKVER _ < <(dd if="/${VMLINUZ}" bs=1 count=127 skip=$(( offset + 0x200 )) 2>/dev/null)
|
2022-02-03 07:14:49 +01:00
|
|
|
fi
|
|
|
|
# fallback if no detectable kernel is installed
|
|
|
|
[[ "${_HWKVER}" == "" ]] && _HWKVER="$(uname -r)"
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:14:25 +01:00
|
|
|
zram_mount() {
|
|
|
|
modprobe zram
|
|
|
|
echo zstd >/sys/block/zram0/comp_algorithm
|
2022-03-25 19:26:03 +01:00
|
|
|
echo "${_DISKSIZE}" >/sys/block/zram0/disksize
|
2022-03-25 09:14:25 +01:00
|
|
|
echo 4 >/sys/block/zram0/max_comp_streams
|
2022-03-25 12:16:04 +01:00
|
|
|
echo "Creating btrfs filesystem with ${_DISKSIZE} on /dev/zram0 ..." > /dev/tty7
|
|
|
|
mkfs.btrfs --mixed /dev/zram0 > /dev/null 2>&1 || exit 1
|
2022-03-25 09:14:25 +01:00
|
|
|
mkdir "${_W_DIR}"
|
|
|
|
# use -o discard for RAM cleaning on delete
|
|
|
|
# (online fstrimming the block device!)
|
|
|
|
# fstrim <mountpoint> for manual action
|
|
|
|
# it needs some seconds to get RAM free on delete!
|
|
|
|
mount -o discard /dev/zram0 "${_W_DIR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
clean_archboot() {
|
|
|
|
# remove everything not necessary
|
|
|
|
rm -rf "/usr/lib/firmware"
|
|
|
|
rm -rf "/usr/lib/modules"
|
|
|
|
rm -rf /usr/lib/{libicu*,libstdc++*}
|
2022-03-25 12:16:04 +01:00
|
|
|
_SHARE_DIRS="archboot efitools file grub hwdata kbd licenses lshw nmap nano openvpn pacman refind systemd tc usb_modeswitch vim zoneinfo"
|
2022-03-25 09:14:25 +01:00
|
|
|
for i in ${_SHARE_DIRS}; do
|
|
|
|
#shellcheck disable=SC2115
|
|
|
|
rm -rf "/usr/share/${i}"
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
2021-09-22 09:02:56 +02:00
|
|
|
usage () {
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mUpdate installer, launch latest environment or create latest image files:\033[0m"
|
|
|
|
echo -e "\033[1m-------------------------------------------------------------------------\033[0m"
|
|
|
|
echo -e "\033[1mPARAMETERS:\033[0m"
|
|
|
|
echo -e " \033[1m-u\033[0m Update scripts: setup, quickinst, tz, km and helpers."
|
|
|
|
echo -e ""
|
|
|
|
echo -e " \033[1m-latest\033[0m Launch latest archboot environment (using kexec)."
|
|
|
|
echo -e " This operation needs at least \033[1m1.8 GB RAM\033[0m."
|
2022-03-18 14:25:36 +01:00
|
|
|
echo ""
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e " \033[1m-latest-install\033[0m Launch latest archboot environment with downloaded"
|
|
|
|
echo -e " package cache (using kexec)."
|
|
|
|
echo -e " This operation needs at least \033[1m2.5 GB RAM\033[0m."
|
2022-03-18 14:25:36 +01:00
|
|
|
echo ""
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e " \033[1m-latest-image\033[0m Generate latest image files in /archboot directory"
|
|
|
|
echo -e " This operation needs at least \033[1m3.4 GB RAM\033[0m."
|
2022-03-18 14:25:36 +01:00
|
|
|
echo ""
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e " \033[1m-h\033[0m This message."
|
2022-03-18 14:25:36 +01:00
|
|
|
exit 0
|
2021-09-22 09:02:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
[[ -z "${1}" ]] && usage
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case ${1} in
|
2022-01-13 17:21:39 +01:00
|
|
|
-u|--u) _D_SCRIPTS="1" ;;
|
|
|
|
-latest|--latest) _L_COMPLETE="1" ;;
|
|
|
|
-latest-install|--latest-install) _L_INSTALL_COMPLETE="1";;
|
|
|
|
-latest-image|--latest-image) _G_RELEASE="1" ;;
|
2021-09-22 09:02:56 +02:00
|
|
|
-h|--h|?) usage ;;
|
|
|
|
*) usage ;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
2021-10-08 15:02:21 +02:00
|
|
|
if [[ ! "$(cat /etc/hostname)" == "archboot" ]]; then
|
|
|
|
echo "This script should only be run in booted archboot environment. Aborting..."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-09-15 07:35:02 +02:00
|
|
|
# Download latest setup and quickinst script from git repository
|
2022-01-13 17:21:39 +01:00
|
|
|
if [[ "${_D_SCRIPTS}" == "1" ]]; then
|
2021-10-06 17:49:16 +02:00
|
|
|
echo "Downloading latest km, tz, quickinst, setup and helpers..."
|
2022-03-24 16:24:43 +01:00
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-quickinst.sh?inline=false" -O /usr/bin/quickinst >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-setup.sh?inline=false" -O /usr/bin/setup >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-km.sh?inline=false" -O /usr/bin/km >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-tz.sh?inline=false" -O /usr/bin/tz >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-${_RUNNING_ARCH}-create-container.sh?inline=false" -O "/usr/bin/archboot-${_RUNNING_ARCH}-create-container.sh" >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-${_RUNNING_ARCH}-release.sh?inline=false" -O "/usr/bin/archboot-${_RUNNING_ARCH}-release.sh" >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-binary-check.sh?inline=false" -O /usr/bin/archboot-binary-check.sh >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_BIN_PATH}/archboot-update-installer.sh?inline=false" -O /usr/bin/update-installer.sh >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_LIB_PATH}/common.sh?inline=false" -O "${_LIB_PATH}/common.sh" >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_LIB_PATH}/container.sh?inline=false" -O "${_LIB_PATH}/container.sh" >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_LIB_PATH}/release.sh?inline=false" -O "${_LIB_PATH}/release.sh" >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_LIB_PATH}/iso.sh?inline=false" -O "${_LIB_PATH}/iso.sh" >/dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/autoconfiguration.sh?inline=false" -O "${_INST_PATH}/autoconfiguration.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/autoprepare.sh?inline=false" -O "${_INST_PATH}/autoprepare.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/base.sh?inline=false" -O "${_INST_PATH}/base.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/blockdevices.sh?inline=false" -O "${_INST_PATH}/blockdevices.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/bootloader.sh?inline=false" -O "${_INST_PATH}/bootloader.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/btrfs.sh?inline=false" -O "${_INST_PATH}/btrfs.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/common.sh?inline=false" -O "${_INST_PATH}/common.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/configuration.sh?inline=false" -O "${_INST_PATH}/configuration.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/mountpoints.sh?inline=false" -O "${_INST_PATH}/mountpoints.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/network.sh?inline=false" -O "${_INST_PATH}/network.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/pacman.sh?inline=false" -O "${_INST_PATH}/pacman.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/partition.sh?inline=false" -O "${_INST_PATH}/partition.sh" > /dev/null 2>&1
|
|
|
|
wget -q "${_INSTALLER_SOURCE}${_INST_PATH}/storage.sh?inline=false" -O "${_INST_PATH}/storage.sh" > /dev/null 2>&1
|
2022-03-27 13:20:35 +02:00
|
|
|
echo -e "\033[1mFinished:\033[0m Downloading scripts done."
|
2021-10-08 10:04:39 +02:00
|
|
|
exit 0
|
2021-09-22 09:02:56 +02:00
|
|
|
fi
|
|
|
|
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mInformation:\033[0m Logging is done on \033[1m/dev/tty7\033[0m ..."
|
2021-10-08 10:04:39 +02:00
|
|
|
|
2021-09-22 09:02:56 +02:00
|
|
|
# Generate new environment and launch it with kexec
|
2022-01-13 17:21:39 +01:00
|
|
|
if [[ "${_L_COMPLETE}" == "1" || "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
2022-03-21 09:32:55 +01:00
|
|
|
if [[ -f /.update-installer ]]; then
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[91mAborting:033[0m"
|
|
|
|
echo "update-installer.sh is already running on other tty ..."
|
2022-03-21 09:32:55 +01:00
|
|
|
echo "If you are absolutly sure it's not running, you need to remove /.update-installer"
|
2022-03-21 09:10:18 +01:00
|
|
|
exit 1
|
2022-03-07 22:23:28 +01:00
|
|
|
fi
|
2022-03-21 09:32:55 +01:00
|
|
|
touch /.update-installer
|
2022-03-25 11:58:26 +01:00
|
|
|
_DISKSIZE="3G"
|
2022-03-25 09:14:25 +01:00
|
|
|
zram_mount
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 1/9:\033[0m Removing not necessary files from / ..."
|
2022-03-25 09:14:25 +01:00
|
|
|
clean_archboot
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 2/9:\033[0m Waiting for gpg pacman keyring import to finish ..."
|
2022-03-21 11:19:03 +01:00
|
|
|
while pgrep -x gpg > /dev/null 2>&1; do
|
2022-03-18 14:02:45 +01:00
|
|
|
sleep 1
|
|
|
|
done
|
2022-03-24 16:20:05 +01:00
|
|
|
systemctl stop pacman-init.service
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 3/9:\033[0m Generating archboot container in ${_W_DIR} ..."
|
2022-03-21 09:10:18 +01:00
|
|
|
echo " This will need some time ..."
|
2021-09-26 08:52:27 +02:00
|
|
|
# create container without package cache
|
2022-03-24 16:20:05 +01:00
|
|
|
if [[ "${_L_COMPLETE}" == "1" ]]; then
|
|
|
|
"archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc -cp >/dev/tty7 2>&1 || exit 1
|
|
|
|
fi
|
2021-09-26 08:52:27 +02:00
|
|
|
# create container with package cache
|
2022-03-18 12:32:00 +01:00
|
|
|
if [[ -e /var/cache/pacman/pkg/archboot.db ]]; then
|
2022-03-25 18:01:24 +01:00
|
|
|
# offline mode, for local image
|
2022-03-18 14:14:10 +01:00
|
|
|
# add the db too on reboot
|
2022-03-18 14:25:36 +01:00
|
|
|
install -D -m644 /var/cache/pacman/pkg/archboot.db /archboot/var/cache/pacman/pkg/archboot.db
|
2022-03-24 16:20:05 +01:00
|
|
|
if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
|
|
|
"archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc --install-source=file:///var/cache/pacman/pkg >/dev/tty7 2>&1 || exit 1
|
|
|
|
fi
|
2022-03-18 12:32:00 +01:00
|
|
|
else
|
2022-03-21 09:10:18 +01:00
|
|
|
#online mode
|
2022-03-24 16:20:05 +01:00
|
|
|
if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
|
|
|
"archboot-${_RUNNING_ARCH}-create-container.sh" "${_W_DIR}" -cc >/dev/tty7 2>&1 || exit 1
|
|
|
|
mv "${_W_DIR}"/var/cache/pacman/pkg /var/cache/pacman/
|
|
|
|
fi
|
2022-01-08 09:39:59 +01:00
|
|
|
fi
|
2022-03-24 16:20:05 +01:00
|
|
|
kver
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 4/9:\033[0m Moving kernel ${VMLINUZ} to /${VMLINUZ} ..."
|
2022-03-25 09:14:25 +01:00
|
|
|
mv "${_W_DIR}"/boot/${VMLINUZ} / || exit 1
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 5/9:\033[0m Collect initramfs files in ${_W_DIR} ..."
|
2022-02-03 09:09:19 +01:00
|
|
|
echo " This will need some time ..."
|
|
|
|
# add fix for mkinitcpio 31, remove when 32 is released
|
2022-03-21 09:10:18 +01:00
|
|
|
cp "${_W_DIR}"/usr/share/archboot/patches/31-mkinitcpio.fixed "${_W_DIR}"/usr/bin/mkinitcpio
|
2022-03-21 22:28:08 +01:00
|
|
|
cp "${_W_DIR}"/usr/share/archboot/patches/31-initcpio.functions.fixed "${_W_DIR}"/usr/lib/initcpio/functions
|
2022-03-24 16:20:05 +01:00
|
|
|
# write initramfs to "${_W_DIR}"/tmp
|
|
|
|
systemd-nspawn -D "${_W_DIR}" /bin/bash -c "umount tmp;mkinitcpio -k ${_HWKVER} -c ${_CONFIG} -d /tmp" >/dev/tty7 2>&1 || exit 1
|
|
|
|
#mv "${_W_DIR}/tmp" /initrd || exit 1
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 6/9:\033[0m Cleanup ${_W_DIR} ..."
|
2022-03-24 16:20:05 +01:00
|
|
|
find "${_W_DIR}"/. -mindepth 1 -maxdepth 1 ! -name 'tmp' ! -name "${VMLINUZ}" -exec rm -rf {} \;
|
2022-03-25 09:14:25 +01:00
|
|
|
# 10 seconds for getting free RAM
|
|
|
|
sleep 10
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 7/9:\033[0m Create initramfs /initrd.img ..."
|
2022-02-03 09:25:48 +01:00
|
|
|
echo " This will need some time ..."
|
2022-03-24 16:20:05 +01:00
|
|
|
# move cache back to initramfs directory in online mode
|
|
|
|
if ! [[ -e /var/cache/pacman/pkg/archboot.db ]]; then
|
2022-03-25 18:01:24 +01:00
|
|
|
if [[ "${_L_INSTALL_COMPLETE}" == "1" ]]; then
|
|
|
|
if [[ -d /var/cache/pacman/pkg ]]; then
|
|
|
|
mv /var/cache/pacman/pkg ${_W_DIR}/tmp/var/cache/pacman/
|
|
|
|
fi
|
|
|
|
fi
|
2022-03-24 16:20:05 +01:00
|
|
|
fi
|
2022-02-03 10:36:40 +01:00
|
|
|
#from /usr/bin/mkinitpcio.conf
|
|
|
|
# compress image with zstd
|
2022-03-24 16:20:05 +01:00
|
|
|
cd "${_W_DIR}"/tmp || exit 1
|
2022-03-16 13:04:17 +01:00
|
|
|
find . -mindepth 1 -printf '%P\0' | sort -z |
|
2022-03-24 16:53:38 +01:00
|
|
|
bsdtar --uid 0 --gid 0 --null -cnf - -T - |
|
2022-03-25 09:14:25 +01:00
|
|
|
bsdtar --null -cf - --format=newc @- | zstd -T0 -10> /initrd.img
|
2022-03-24 16:20:05 +01:00
|
|
|
for i in $(find . -mindepth 1 -type f | sort); do
|
|
|
|
rm "${i}" >/dev/null 2>&1
|
|
|
|
done
|
|
|
|
while pgreg -x bsdtar >/dev/null 2>&1; do
|
|
|
|
sleep 1
|
|
|
|
done
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 8/9:\033[0m Cleanup ${_W_DIR} ..."
|
2022-03-25 09:14:25 +01:00
|
|
|
cd /
|
|
|
|
umount ${_W_DIR}
|
|
|
|
echo 1 > /sys/block/zram0/reset
|
|
|
|
sleep 5
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 9/9:\033[0m Loading files through kexec into kernel now ..."
|
2022-03-24 16:20:05 +01:00
|
|
|
# load kernel and initrds into running kernel in background mode!
|
2022-03-25 09:14:25 +01:00
|
|
|
kexec -f /"${VMLINUZ}" --initrd="/initrd.img" --reuse-cmdline&
|
|
|
|
# wait 1 seconds for getting a complete initramfs
|
2022-03-24 16:20:05 +01:00
|
|
|
# remove kernel and initrd to save RAM for kexec in background
|
2022-03-25 09:14:25 +01:00
|
|
|
sleep 2
|
|
|
|
rm /{initrd.img,${VMLINUZ}}
|
2022-03-24 16:20:05 +01:00
|
|
|
while pgreg -x kexec >/dev/null 2>&1; do
|
|
|
|
sleep 1
|
|
|
|
done
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mFinished:\033[0m Rebooting in a few seconds ..."
|
2022-03-25 09:14:25 +01:00
|
|
|
# don't show active prompt wait for kexec to be launched
|
2022-03-24 16:20:05 +01:00
|
|
|
sleep 30
|
2021-09-22 09:02:56 +02:00
|
|
|
fi
|
2021-09-15 07:35:02 +02:00
|
|
|
|
2021-09-22 09:02:56 +02:00
|
|
|
# Generate new images
|
2022-01-13 17:21:39 +01:00
|
|
|
if [[ "${_G_RELEASE}" == "1" ]]; then
|
2022-03-25 11:58:26 +01:00
|
|
|
_DISKSIZE="5G"
|
2022-03-25 09:14:25 +01:00
|
|
|
zram_mount
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 1/2:\033[0m Removing not necessary files from / ..."
|
2022-03-25 09:14:25 +01:00
|
|
|
clean_archboot
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mStep 2/2:\033[0m Generating new iso files now in ${_W_DIR} ..."
|
2021-10-07 07:22:05 +02:00
|
|
|
echo " This will need some time ..."
|
2022-01-21 11:54:13 +01:00
|
|
|
"archboot-${_RUNNING_ARCH}-release.sh" "${_W_DIR}" >/dev/tty7 2>&1 || exit 1
|
2022-03-27 13:16:20 +02:00
|
|
|
echo -e "\033[1mFinished:\033[0m New isofiles are located in ${_W_DIR}"
|
2021-09-22 09:02:56 +02:00
|
|
|
fi
|