small fixes and config changes
[automated-distro-installer] / arch-init
index a7420bedeeb09937041a3724ecfdc56ca3ccf166..d1c554268c3df48e39dafca3cbd0881443389436 100755 (executable)
--- a/arch-init
+++ b/arch-init
@@ -3,36 +3,23 @@
 # see t.org for how to call
 
 set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 cd $(dirname $(readlink -f "$BASH_SOURCE"))
 
-export ROOTPW="$1"
-export hostname="$2"
-mirror=$3
+ROOTPW="$(cat /root/shadow/standard)"
+export ROOTPW
+export hostname="$1"
+mirror=$2
+TPPASS="$(cat /root/shadow/traci-simple)"
+export TPPASS
+if [[ $hostname == tp ]]; then
+    ROOTPW="$TPPASS"
+fi
 
 (( $# >= 2 )) || { echo "error: need 2 arguments"; exit 1; }
 
-case $hostname in
-    x2)
-        export grubdisk=/dev/sda
-        ;;
-    demohost)
-        export grubdisk=/dev/vda
-        ;;
-    treetowl)
-        bootid=64d495ee-c9fe-4174-b20a-6c5e47abcfa1
-        export grubdisk=$(blkid|sed -nr "/$bootid/s/^([^0-9]+).*/\1/p")
-        ;;
-    frodo)
-        rootid=e9ce7b46-9a21-4e79-b7f7-0b18acb57587
-        export grubdisk=$(blkid|sed -nr "/$rootid/s/(^[^0-9]*).*/\1/p")
-        ;;
-    *)
-        echo "unrecognized hostname: $hostname"
-        exit 1
-esac
-
+mv /root/devbyid /usr/bin
 
 rm -f /etc/pacman.d/mirrorlist
 # https://wiki.archlinux.org/index.php/Mirrors#Sorting_mirrors
@@ -57,18 +44,40 @@ export LUKS_DIR=/root/luks
 export HOSTNAME=$hostname
 export DISTRO=arch
 chmod +x partition.DEFAULT
-./partition.DEFAULT
+
+export PARTITION_PROMPT=true
+
+already_partitioned=true
+mount_out=$(mount)
+for dir in /mnt{,/home,/boot,/q}; do
+    regex=" on $dir "
+    if [[ ! $mount_out =~ $regex ]]; then
+        already_partitioned=false
+        break
+    fi
+done
+
+if ! $already_partitioned; then
+    ./partition.DEFAULT
+fi
+
+. /tmp/fai/disk_var.sh
+
+
 # arch doesn't need crypttab entries for initramfs crypt partititions
 export rootn=1
 export bootn=3
 export swapn=2
-sed -ri '/^crypt_dev/d' /tmp/fai/crypttab
-mount -o subvol=root_$DISTRO /dev/mapper/crypt_dev_?da$rootn /mnt
-mkdir -p /mnt/{q,home}
-mount -o subvol=/q /dev/mapper/crypt_dev_?da$rootn /mnt/q
-mount -o subvol=/home_$DISTRO /dev/mapper/crypt_dev_?da$rootn /mnt/home
-mkdir -p /mnt/boot
-mount /dev/?da$bootn /mnt/boot
+export BOOT_DEVICE
+sed -ri "/^crypt_dev_\S+$rootn /d" /tmp/fai/crypttab
+
+if ! $already_partitioned; then
+    mount -o subvol=root_$DISTRO $ROOT_PARTITION /mnt
+    mkdir -p /mnt/{q,home,boot}
+    mount -o subvol=q $ROOT_PARTITION /mnt/q
+    mount -o subvol=home_$DISTRO $ROOT_PARTITION /mnt/home
+    mount -o subvol=boot_$DISTRO $BOOT_PARTITION /mnt/boot
+fi
 
 # https://wiki.archlinux.org/index.php/Dm-crypt/Device_encryption#Keyfiles
 cp /root/luks/host-$hostname /mnt/crypto_keyfile.bin
@@ -77,7 +86,7 @@ chmod 600 /mnt/crypto_keyfile.bin
 
 shopt -s extglob
 case $hostname in
-    # these hosts are broken, not updated to new fai hyrbrid scripts.
+    # todo: these hosts are broken, not updated to new fai hyrbrid scripts.
     frodo)
 
         # for this system, no separate /boot, to keep partitions simple,
@@ -101,6 +110,7 @@ they will succeed using the secodary mirror"
 fi
 pacstrap /mnt base
 cp /tmp/fai/{fstab,crypttab} /mnt/etc
+cp /usr/bin/devbyid /mnt/root
 case $hostname in
     frodo)
         # the root .ssh needs to be like this,
@@ -125,8 +135,6 @@ UUID=dd67766f-93c5-4ce3-9877-a1d9841dd4a4  none  swap  sw  0  0
 EOF
         ;;
     *)
-        echo "$0: 2nd fstab:"
-        cat /mnt/etc/fstab
         cp -r .ssh /mnt/root
         cp -r /root/distro-install-common /mnt/root
         ;;&
@@ -144,7 +152,7 @@ rm -f /mnt/etc/resolv.conf
 ln -s /run/systemd/resolve/resolv.conf /mnt/etc/resolv.conf
 
 # not necsesary, but makes reboot go fast.
-umount -R /mnt
+umount -R /mnt; sleep 1
 
 # causes 255 exit code, so doing this from the caller script.
 # reboot now