From d2c05a5647eb3e1fb83c89720758551008f69112 Mon Sep 17 00:00:00 2001 From: Adrian Amaglio Date: Thu, 18 May 2023 10:03:11 +0200 Subject: [PATCH] tweaks for blatte --- installing/debootstrap_ordis_portables.sh | 73 +++++++++++++---------- 1 file changed, 42 insertions(+), 31 deletions(-) diff --git a/installing/debootstrap_ordis_portables.sh b/installing/debootstrap_ordis_portables.sh index f2b6c88..22badb7 100755 --- a/installing/debootstrap_ordis_portables.sh +++ b/installing/debootstrap_ordis_portables.sh @@ -30,6 +30,10 @@ varia[s]=repo repo="http://ftp.fr.debian.org/debian" #repo="http://localhost:3142/ftp.fr.debian.org/debian" +usage[S]="Additional sources to add in source.list. Newline separated." +varia[S]=repos +repos="deb http://ftp.fr.debian.org/debian stable main contrib non-free" + usage[n]="The hostname" varia[n]=hostname hostname="" @@ -50,6 +54,13 @@ usage[w]="Wireguard IP last number (4 for 1.2.3.4)" varia[w]=wireguard_number wireguard_number= +usage[J]="Just mount and chroot it. No installation" +varia[J]=just_mount +just_mount=false + +usage[i]="Packages to install. space separated" +varia[i]=install +install= . driglibash-args @@ -57,9 +68,9 @@ wireguard_number= secret_dir=secrets secret_dir="$(realpath -m "$secret_dir/$hostname")" -install="vim openssh-server git nginx" - +install="$install vim openssh-server git nginx smartmontool" +debootstrap_done_marker="$mnt/etc/debootstrap_done" ############################################################################### # Actual script @@ -69,7 +80,7 @@ install="vim openssh-server git nginx" chroot_run(){ chroot "$mnt" $@ - if [ "$?" -ne 0 ] ; then + if [ "$?" -ne 0 ] && [ "$?" != '0' ] ; then die "Error, chroot command [$@] exited with code '$?'" fi } @@ -86,6 +97,7 @@ mount_misc(){ #clean "umount '$(realpath "$mnt/proc")'" # To access physical devices run mount --rbind --make-rslave /dev "$mnt/dev" + # even explicitly mounting /dev/pts makes apt cry for its absence… #clean "umount -R '$(realpath "$mnt/dev")'" run mount --rbind --make-rslave /sys "$mnt/sys" #clean "umount -R '$(realpath "$mnt/sys")'" @@ -111,26 +123,40 @@ section "Mounting additionnal items" if [ -n "$(df | grep "$root_device")" ] ; then run umount "$root_device" fi +run mkdir -p "$mnt" run mount --make-private "$root_device" "$mnt" -clean "umount -R '$mnt'" +# bug in driglibash-base. If $mnt got spaces it break +clean "umount -R $mnt" -# Debootstrap may fail when the target is an existing system -if [ -n "$(ls -A $mnt)" ]; then - die "Root dir '$mnt' is not empty. Won’t debootstrap it." +if [ "$just_mount" != false ] ; then + echo 'Mounted. Exit shell to unmount.' + chroot_run + die 'You asked to just mount then exit.' fi - section "debootstraping" -run debootstrap --verbose --arch "$arch" "$release" "$mnt" "$repo" - +if [ ! -f "$debootstrap_done_marker" ] ; then + # Debootstrap may fail when the target is an existing system + if [ -n "$(ls -A $mnt)" ]; then + die "Root dir '$mnt' is not empty. Won’t debootstrap it. Is this installation broken?" + fi + run debootstrap --verbose --arch "$arch" "$release" "$mnt" "$repo" + touch "$debootstrap_done_marker" +else + yell "Already done" +fi mount_misc +section "Generating locales" +echo -e "$locale" > "$mnt/etc/locale.gen" +chroot_run locale-gen + section "Installing selected software" -#XXX use chroot_run +echo "$repos" >> "$mnt/etc/apt/sources.list" chroot "$mnt" < "$mnt/etc/hostname" run cat > "$mnt/root/.bashrc" <> "$mnt/etc/inputrc" @@ -188,23 +213,10 @@ section "Set up networking" # Disable the unpredictable naming (since we are not on the future host) run ln -s /dev/null "$mnt/etc/udev/rules.d/80-net-setup-link.rules" run cat >> "$mnt/etc/network/interfaces" <> "$mnt/root/.ssh/authorized_keys" +chroot_run systemctl enable ssh section "Creating wireguard conf" + if [ -n "$wireguard_number" ] ; then run cat >> "$mnt/etc/wireguard/jeancloud.conf" <> "$secret_dir/wg_conf_part_$hostname" < "/etc/locale.gen" -chroot_run locale-gen - section "Installing grub" # Disable predictable name (again)