static usb ethnet addresses
[automated-distro-installer] / arch-init
index af649b2676640c481a7aed76836194f41842ae52..2f14ad60bc1485a6f325f722bab9c59863e1fe09 100755 (executable)
--- a/arch-init
+++ b/arch-init
@@ -1,26 +1,28 @@
 #!/bin/bash -x
+# Copyright (C) 2016 Ian Kelling
 
-# see t.org for how to call
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
 
-cd $(dirname $(readlink -f "$BASH_SOURCE"))
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
-ROOTPW="$(cat /root/shadow/standard)"
-export ROOTPW
-export hostname="$1"
+x="$(readlink -f "$BASH_SOURCE")"; source "${x%/*}/bash-trace"
+cd ${x%/*}
+
+export HOSTNAME="$1"
 mirror=$2
-TPPASS="$(cat /root/shadow/traci-simple)"
-export TPPASS
-if [[ $hostname == tp ]]; then
-    ROOTPW="$TPPASS"
-fi
 
 (( $# >= 1 )) || { echo "$0: error: need 1 or 2 arguments"; exit 1; }
 
-mv /root/devbyid /usr/bin
-
 rm -f /etc/pacman.d/mirrorlist
 # https://wiki.archlinux.org/index.php/Mirrors#Sorting_mirrors
 
@@ -30,26 +32,18 @@ fi
 curl -s 'https://www.archlinux.org/mirrorlist/?country=US&protocol=https&ip_version=4&ip_version=6&use_mirror_status=on' |
     sed -r 's/^[ #]*(Server *=)/\1/' >> /etc/pacman.d/mirrorlist
 
-# export class vars with CLASS_ in front to avoid name colissions.
-ifclass() {
-    local var=${1/#/CLASS_}
-    [[ $hostname == $1 || ${!var} ]]
-}
-export -f ifclass
-for x in $(bash 50-host-classes); do
-    export CLASS_$x=true
-done
+. /a/bin/fai/fai-wrapper
 export LUKS_DIR=/root/luks
-export HOSTNAME=$hostname
 export DISTRO=arch
-chmod +x partition.DEFAULT
+partition_script=/a/bin/fai/fai/config/hooks/partition.DEFAULT
+chmod +x $partition_script
 
 export PARTITION_PROMPT=true
 
 # to be idempotent if we fail after partitioning
 already_partitioned=true
 mount_out=$(mount)
-for dir in /mnt{,/home,/boot,/q}; do
+for dir in /mnt{,/home,/boot,/a}; do
     regex=" on $dir "
     if [[ ! $mount_out =~ $regex ]]; then
         already_partitioned=false
@@ -58,7 +52,7 @@ for dir in /mnt{,/home,/boot,/q}; do
 done
 
 if ! $already_partitioned; then
-    ./partition.DEFAULT
+    /a/bin/fai/fai/config/hooks/partition.DEFAULT
 fi
 
 . /tmp/fai/disk_var.sh
@@ -70,18 +64,16 @@ export bootn=3
 export swapn=2
 export BOOT_DEVICE
 export ROOT_PARTITIONS
-sed -ri "/^crypt_dev_\S+$rootn /d" /tmp/fai/crypttab
+sed -ri --follow-symlinks "/^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
+    mkdir -p /mnt/boot
     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
+cp /root/luks/host-$HOSTNAME /mnt/crypto_keyfile.bin
 chmod 600 /mnt/crypto_keyfile.bin
 
 
@@ -91,16 +83,23 @@ they will succeed using the secodary mirror"
 fi
 pacstrap /mnt base
 cp /tmp/fai/{fstab,crypttab} /mnt/etc
-cp /root/encrypt /mnt/usr/lib/initcpio/hooks
-# not needed anymore
-#cp /usr/bin/devbyid /mnt/root
+cp /a/bin/fai/encrypt /mnt/usr/lib/initcpio/hooks
+
+cp -r /root/.ssh /mnt/root
+
+bindmount() {
+    local mountpoint=$2
+    local source=$1
+    mkdir -p $mountpoint
+    mount -o bind $source $mountpoint
+}
+bindmount /root/shadow /mnt/q/root/shadow
+bindmount /a /mnt/a
 
-cp -r .ssh /mnt/root
-cp -r /root/distro-install-common /mnt/root
 mkdir -p /mnt/etc/ssh
-cp /etc/ssh/host_* /mnt/etc/ssh
+cp /etc/ssh/ssh_host_* /mnt/etc/ssh
 
-cp /root/arch-init-chroot /mnt/root
+cp /a/bin/fai/arch-init-chroot /mnt/root
 # for manual commands, arch-chroot /mnt bash
 arch-chroot /mnt /root/arch-init-chroot
 
@@ -109,7 +108,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; sleep 1
+umount -R /mnt; sleep 1
 
 # causes 255 exit code, so doing this from the caller script.
 # reboot now