Last active
October 25, 2025 23:40
-
-
Save tvidal-net/d5bacf5ee04909113bab2d0b5d9879e4 to your computer and use it in GitHub Desktop.
archiso-build
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env zsh | |
| if [ "$TERM" ] | |
| then | |
| autoload -Uz colors | |
| colors | |
| red=$fg_bold[red] | |
| cyn=$fg_bold[cyan] | |
| grn=$fg_bold[green] | |
| ylw=$fg_bold[yellow] | |
| mgt=$fg_bold[magenta] | |
| rst=$reset_color | |
| fi | |
| set -eo pipefail | |
| zparseopts -D -a ARGS -- d c n | |
| [ "${ARGS[(r)-d]}" ] && set -x | |
| WORK="/dev/shm" | |
| - "ARCHLIVE: $cyn${ARCHLIVE:=${1:-$WORK/archlive}}$rst" | |
| ROOTFS="$ARCHLIVE/airootfs" | |
| - "ROOTFS: $ylw$ROOTFS$rst" | |
| REPO="$ARCHLIVE/aur" | |
| - "REPO: $grn$REPO$rst" | |
| AUR=( paru-bin ) | |
| - "AUR: $mgt${(pj., .)AUR}$rst" | |
| PROFILE_DEF=( | |
| /root/.ssh "0:0:700" | |
| /root/.ssh/authorized_keys "0:0:600" | |
| ) | |
| if [ ! -d "$ARCHLIVE" ] | |
| then | |
| - | |
| mkdir -vp $ARCHLIVE | |
| fi | |
| if [ ! -d "$ROOTFS" -o "${ARGS[(r)-c]}" ] | |
| then | |
| - "\n- refresh $ylw${ARCHLIVE:t}$rst from ${grn}releng$rst" | |
| rsync -ahxP --delete /usr/share/archiso/configs/releng/ "$ARCHLIVE/" | |
| fi | |
| - "\n- ssh access" | |
| mkdir -vp "$ROOTFS/root/.ssh" | |
| ssh-keygen -y -f "$HOME/.ssh/id_ed25519" | tee "$ROOTFS/root/.ssh/authorized_keys" | |
| - "\n- shell and scripts" | |
| cp -v ~/.scripts/zsh/env.zsh "$ROOTFS/root/.zshenv" | |
| cp -v ~/.scripts/zsh/profile.zsh "$ROOTFS/root/.zprofile" | |
| cp -v ~/.scripts/bin/mount-* "$ROOTFS/usr/local/bin" | |
| sed -e '/plugin.zsh/d' \ | |
| -e '$a\\nfor plugin in /usr/share/zsh/plugins/*/*.plugin.zsh; source $plugin' \ | |
| -e '$a\unset plugin' "$ROOTFS/root/.zlogin" -i | |
| - | |
| mkdir -vp "$ROOTFS/usr/share/pacman/keyrings" | |
| function gpg-key-trust () { | |
| local key | |
| gpg --with-colons --import-options show-only --import ${1?file} | | |
| grep '^fpr' | cut -d: -f10 | | |
| while | |
| read key | |
| do | |
| - "$key:4:" | |
| done | |
| } | |
| function pacman-mirror () { | |
| local name=${1?name} server=${2?server} url=${3?url} file | |
| file="$ROOTFS/usr/share/pacman/keyrings/$name.gpg" | |
| if [ ! -r "$file" ] | |
| then | |
| - "\n- downloading $mgt$name.gpg$rst" | |
| tee --append "$ARCHLIVE/pacman.conf" <<-EOF | |
| [$name] | |
| Server = https://$server/ | |
| EOF | |
| - | |
| command curl -Skf -o $file "https://$url" | |
| gpg-key-trust $file | tee "${file:r}-trusted" | |
| fi | |
| } | |
| pacman-mirror g14 'arch.asus-linux.org' \ | |
| 'keyserver.ubuntu.com/pks/lookup?op=get&search=0x8b15a6b0e9a3fa35' | |
| pacman-mirror linux-surface 'pkg.surfacelinux.com/arch' \ | |
| 'raw.githubusercontent.com/linux-surface/linux-surface/master/pkg/keys/surface.asc' | |
| # add kernel to bootloader | |
| LINUX=( LTS G14 Surface ) | |
| for kernel in $LINUX | |
| do | |
| name=${(L)kernel} file="archiso_sys-linux-$name.cfg" | |
| tee "$ARCHLIVE/syslinux/$file" <<-EOF | |
| LABEL arch-$name | |
| MENU LABEL Arch Linux $kernel install medium (%ARCH%, BIOS) | |
| LINUX /%INSTALL_DIR%/boot/%ARCH%/vmlinuz-linux-$name | |
| INITRD /%INSTALL_DIR%/boot/%ARCH%/initramfs-linux-$name.img | |
| APPEND archisobasedir=%INSTALL_DIR% archisosearchuuid=%ARCHISO_UUID% | |
| EOF | |
| sed -e "/$file/d" \ | |
| -e "\$i\\INCLUDE $file" \ | |
| "$ARCHLIVE/syslinux/archiso_sys.cfg" -i | |
| done | |
| # extra packages | |
| print -l zsh-{completions,syntax-highlighting,autosuggestions} \ | |
| linux-${(L)^LINUX} $AUR | tee --append "$ARCHLIVE/packages.x86_64" | |
| # aur | |
| mkdir -vp $REPO | |
| AUR_URL="https://aur.archlinux.org" | |
| for aur in $AUR | |
| do | |
| - "- building $cyn$aur$rst" | |
| AUR_DIR="$WORK/aur/$aur" | |
| mkdir -vp $AUR_DIR | |
| ( | |
| set -e | |
| if [ ! -d "$AUR_DIR/.git" ] | |
| then | |
| git clone --progress --depth=1 "$AUR_URL/$aur.git" $AUR_DIR | |
| fi | |
| cd $AUR_DIR | |
| source PKGBUILD | |
| # build aur if not exists | |
| pkg="$pkgname-$epoch${epoch:+:}$pkgver-$pkgrel-${arch[1]}.pkg.tar.zst" | |
| if [ ! -e "$REPO/$pkg" ] | |
| then | |
| [ -e "$pkg" ] || makepkg -s --noconfirm | |
| cp -v $pkg $REPO | |
| fi | |
| ) | |
| done | |
| repo-add $REPO/aur.db.tar.zst $WORK/aur/*/*.pkg.tar.zst | |
| # aur @ pacman.conf | |
| if ! grep -qF '[aur]' "$ARCHLIVE/pacman.conf" | |
| then | |
| - "\n- adding ${ylw}aur$rst to ${grn}pacman.conf$rst" | |
| tee --append "$ARCHLIVE/pacman.conf" <<-EOF | |
| [aur] | |
| SigLevel = Optional TrustAll | |
| Server = file://$REPO | |
| EOF | |
| fi | |
| # mkinitcpio.conf | |
| sed -e '/^COMPRESSION/d' \ | |
| -e '$a\COMPRESSION="zstd"' \ | |
| -e '$a\COMPRESSION_OPTIONS=( --auto-threads --long )' \ | |
| "$ROOTFS/etc/mkinitcpio.conf.d/archiso.conf" -i | |
| # profile.def | |
| declare -a SED=() | |
| for dir arg in ${(kv)PROFILE_DEF} | |
| do | |
| SED+=( /${dir//\//\\\/}/d "\$i\\ [\"$dir\"]=\"$arg\"" ) | |
| done | |
| sed -e${^SED} "$ARCHLIVE/profiledef.sh" -i | |
| if [ "${ARGS[(r)-n]}" ] | |
| then | |
| - "\n- using ${ylw}profiledef.sh$rst" | |
| cat "$ARCHLIVE/profiledef.sh" | |
| else | |
| - | |
| exec sudo mkarchiso -vr -o ~/Work -w "${WORK?}/arch" ${ARCHLIVE?} | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment