arch use by-id and various fixes
[automated-distro-installer] / arch-init
index c4f573fbd044b582d812a2b3edf37c8dfc8537e2..b34c42894033e196f8e90822d8e3f84fec7b956c 100755 (executable)
--- a/arch-init
+++ b/arch-init
@@ -7,35 +7,19 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' 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
-
-if [[ -e /root/devbyid ]]; then
-    mv /root/devbyid /usr/bin
-fi
+mv /root/devbyid /usr/bin
 
 rm -f /etc/pacman.d/mirrorlist
 # https://wiki.archlinux.org/index.php/Mirrors#Sorting_mirrors
@@ -60,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 -o subvol=boot_$DISTRO /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
@@ -80,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,
@@ -104,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,