Skip to content

Instantly share code, notes, and snippets.

@Strykar
Last active July 4, 2025 07:51
Show Gist options
  • Save Strykar/ffafe1fca0ce777a048ec44984d7aaef to your computer and use it in GitHub Desktop.
Save Strykar/ffafe1fca0ce777a048ec44984d7aaef to your computer and use it in GitHub Desktop.
Minimal aurutils (setup + post-boot install) inside an Arch linux rescue EFI created by systemd-mkosi
#!/bin/bash
# mkosi.conf.d/01-minimal-aurutils-setup.sh
# Call this from mkosi.postinst.chroot
#
# Prepare an mkosi image for (optionally) installing aurutils (post-boot) in an Arch linux rescue EFI.
# A rescue EFI has no need for persistent storage, instead we drop a 0.2 MB compiled / packaged
# "aurutils-*.pkg.tar.zst" into the image's "/home/packages" or "$AURUTILS_PKG_PATH" directory before mkosi's image build completion.
#
# This keeps the EFI size down as pre-installing any aur helper will pull in 100+ MBs of dependencies.
# The script sticks with pacman.conf's example username "packages" and repository name "custom".
# It expects a sane Arch config - https://codeberg.org/swsnr/rescue-image
: "${AUR_BUILD_USER:=custompkgs}"
: "${CUSTOM_REPO_NAME:=custom}"
# Uncomment these three lines from the default pacman.conf
#[custom]
#SigLevel = Optional TrustAll
#Server = file:///home/packages
#sed -i "/^#\[${CUSTOM_REPO_NAME}\]/,/^#Server = file:\/\/\/home\/${AUR_BUILD_USER}\// { s/^#// }" /etc/pacman.conf
sed -i '/^#\[custom\]/,/^#Server = file:\/\/\/home\/packages/ { s/^#// }' /etc/pacman.conf
# Create the $AUR_BUILD_USER and add it to the wheel group
useradd --shell /bin/bash --create-home \
--user-group --groups wheel "${AUR_BUILD_USER}" \
--password "$(openssl passwd -stdin -6 < mkosi.conf.d/mkosi.userpw)"
# Allow wheel to sudo without password
echo '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' | EDITOR='tee -a' visudo
# Add $AUR_REPO to this user's .bash_profile
echo "export AUR_REPO=\"${CUSTOM_REPO_NAME}\"" | tee -a /home/"${AUR_BUILD_USER}"/.bash_profile
# Create the repository root and database:
repo-add /home/"${AUR_BUILD_USER}"/"${CUSTOM_REPO_NAME}".db.tar.gz
### aurutils setup complete, do not run pacman -Sy, boot into the image instead. See 02-install-aurutils.sh ###
#!/bin/bash
# extra/arch/root/02-install-aurutils.sh
# Upload this to your user home dir before creating the image
# Boot into the rescue EFI and run this as the unprivileged user inside it
#
# Sensible aur-helpers will not work as root, use an unprivileged user with sudo privs instead.
# Login (as root), fix file ownership and init the aurutils db as $AUR_BUILD_USER.
# If you are not using the pacman default names for repo / user, change them below.
: "${AUR_BUILD_USER:=${USER:-custompkgs}}"
: "${CUSTOM_REPO_NAME:=custom}"
# Fix file ownership as mkosi creates things as root
sudo chown -R "${AUR_BUILD_USER}":"${AUR_BUILD_USER}" /home/"${AUR_BUILD_USER}"
# If built packages are available, add them to the database:
repo-add -n /home/"${AUR_BUILD_USER}"/"${CUSTOM_REPO_NAME}".db.tar.gz /home/"${AUR_BUILD_USER}"/*.pkg.tar*
# Then init the pacman db and install aurutils (and its dependencies)
sudo pacman -Sy
echo ""
# Install aurutils
sudo pacman -U /home/${AUR_BUILD_USER}/aurutils-*.pkg.tar*
# You may now (man 1 aur sync) install packages from the aur
echo ""
echo "Try: aur sync visual-studio-code-bin"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment