chamesle-bootstrap (3445B)
1 #!/bin/sh 2 # chamesle-bootstrap TARGET [PACKAGE]...: puts the Chamesle base into TARGET with mag, like debootstrap does for Debian. 3 # the repos and the keys are this system's, from /etc/mag. the base is chamesle-base, a kernel and what they need. 4 # -l glibc makes the glibc Chamesle instead, on Artix and Arch packages and the AUR, from /usr/share/chamesle/glibc. 5 # chamesle-bootstrap /mnt 6 # chamesle-bootstrap -a x86 -n box /mnt vim 7 # chamesle-bootstrap -l glibc -f "linux-firmware-intel linux-firmware-realtek" /mnt 8 set -e 9 usage() { 10 echo "usage: chamesle-bootstrap [-l musl|glibc] [-a ARCH] [-n HOSTNAME] [-k KERNEL] [-f FIRMWARE] TARGET [PACKAGE]..." >&2 11 echo " -l musl (default) or glibc" >&2 12 echo " -a x86_64, x86 and so on (default: this machine's)" >&2 13 echo " -n host name of the new system (default chamesle)" >&2 14 echo " -k the kernel package (default linux-lts), -f its firmware (default linux-firmware-none, none on glibc)" >&2 15 exit 2 16 } 17 arch= name=chamesle kernel= firmware= libc=musl 18 while getopts l:a:n:k:f: o; do 19 case $o in 20 l) libc=$OPTARG;; 21 a) arch=$OPTARG;; 22 n) name=$OPTARG;; 23 k) kernel=$OPTARG;; 24 f) firmware=$OPTARG;; 25 *) usage;; 26 esac 27 done 28 shift $((OPTIND - 1)) 29 [ $# -ge 1 ] || usage 30 target=$1 31 shift 32 [ "$(id -u)" = 0 ] || { echo "chamesle-bootstrap: run it as root" >&2; exit 1; } 33 command -v mag >/dev/null || { echo "chamesle-bootstrap: mag is not in PATH" >&2; exit 1; } 34 case $libc in 35 musl) conf=/etc/mag;; 36 glibc) conf=/usr/share/chamesle/glibc; [ -n "$arch" ] || arch=x86_64;; 37 *) usage;; 38 esac 39 [ -f $conf/repos ] && [ -d $conf/keys ] || { echo "chamesle-bootstrap: $conf/repos and $conf/keys are needed" >&2; exit 1; } 40 41 mkdir -p "$target/etc/mag" "$target/dev" "$target/proc" "$target/sys" "$target/run" "$target/tmp" "$target/boot" 42 chmod 1777 "$target/tmp" 43 # the base never comes from the AUR: its index (15 MB) waits for the first mag update on the system 44 grep -v '^aur ' $conf/repos > "$target/etc/mag/repos" 45 cp -R $conf/keys "$target/etc/mag/" 46 [ -n "$arch" ] && echo "$arch" > "$target/etc/mag/arch" 47 export MAG_ROOT=$target MAG_YES=1 48 mag update 49 if [ $libc = glibc ]; then 50 # pacman's hooks (the initramfs, the users, tmpfiles) want /proc, /sys and /dev in there, as pacstrap gives them 51 for m in proc sys dev run; do mount --rbind /$m "$target/$m" && mount --make-rslave "$target/$m"; done 52 trap 'for m in run dev sys proc; do umount -R "$target/$m" 2>/dev/null; done' EXIT 53 mag install chamesle-base ${kernel:-linux-lts} $firmware "$@" 54 rm -f "$target"/etc/mag/keys/*.gpg 55 cp $conf/repos "$target/etc/mag/repos" 56 # Artix's localmount would mount a second /sys over the cgroups: proc and sys are its services' to mount 57 [ -f "$target/etc/fstab" ] && sed -i '/^proc[[:space:]]/d; /^sysfs[[:space:]]/d' "$target/etc/fstab" 58 else 59 # the kernel wants some firmware; the vendor packages do not count as that, so -none goes with them 60 case ${firmware:=linux-firmware-none} in linux-firmware|linux-firmware-none) ;; *) firmware="linux-firmware-none $firmware";; esac 61 mag install chamesle-base $firmware ${kernel:-linux-lts} "$@" 62 fi 63 echo "$name" > "$target/etc/hostname" 64 # startx's xauth wants the host name to resolve 65 printf '127.0.0.1\tlocalhost %s\n::1\t\tlocalhost %s\n' "$name" "$name" > "$target/etc/hosts" 66 [ -e "$target/etc/resolv.conf" ] || cp /etc/resolv.conf "$target/etc/" 2>/dev/null || : 67 echo 68 echo "the base is in $target. go on with the fstab, a password and the boot entry (handbook, 3.4)."