static usb ethnet addresses
[automated-distro-installer] / arch-init-chroot
index 5e2f8aa6a5ef58c68b3fcd85345b33b546ce4381..e1738632e39c27612c3386160be064bacff1cd0a 100755 (executable)
@@ -1,15 +1,27 @@
 #!/bin/bash -x
+# Copyright (C) 2016 Ian Kelling
+
+# 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.
+
+# 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.
+
+# 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.
 set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?"' ERR
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
-for x in /etc/*.pacorig; do
-    # This started breaking immediately when I stoped doing genfstab.
-    # It's probably not needed anymore
-    [[ -e $x ]] || break
-    mv $x ${x%.pacorig}
-done
+# note, when I did genfstab, i
+# neeeded to to do for x in mv /etc/*.pacorig; do mv $x ${x%.pacorig}; done
+
+pacman -Syu
 
-echo $hostname > /etc/hostname
 [[ -L /etc/localtime ]] || ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
 l=en_US.UTF-8
 echo "$l UTF-8" > /etc/locale.gen
@@ -27,9 +39,9 @@ echo "LANG=$l" > /etc/locale.conf
 # # https://bugs.archlinux.org/task/42884
 # # disabled, as with just the module, startup spammed something about
 # # command takes a device name and something else.
-# sed -ri '/^ *MODULES *=.*btrfs/!s/^( *MODULES *=.*)"/\1 btrfs"/' /etc/mkinitcpio.conf
+# sed -ri --follow-symlinks '/^ *MODULES *=.*btrfs/!s/^( *MODULES *=.*)"/\1 btrfs"/' /etc/mkinitcpio.conf
 # # remove extra space
-# sed -ri 's/^( *MODULES *=[^"]*)" */\1"/' /etc/mkinitcpio.conf
+# sed -ri --follow-symlinks 's/^( *MODULES *=[^"]*)" */\1"/' /etc/mkinitcpio.conf
 
 
 
@@ -55,65 +67,38 @@ cat /etc/fstab
 # which will be the crypt device name under /dev/mapper/
 # https://wiki.archlinux.org/index.php/GRUB#Additional_arguments
 
-first_boot_dev=${BOOT_DEVICE%% *}
-crypt_dev=${first_boot_dev}$rootn
-crypt_name=$(/root/devbyid $crypt_dev)
-crypt_name=crypt_dev_${crypt_name##*/}
+
+root_devs=( ${ROOT_PARTITIONS} )
+first_root_dev=${root_devs[0]}
 
 
 k_args=(
-    cryptdevice=$crypt_dev:$crypt_name:allow-discards
-    root=/dev/mapper/$crypt_name
-    resume=${crypt_dev%[0-9]}$swapn
+    cryptdevices=${ROOT_PARTITIONS// /,}
+    root=/dev/mapper/crypt_dev_${first_root_dev##*/}
+    resume=${first_root_dev%[0-9]}$swapn
 )
-crypt_mapper_devs=(/dev/mapper/crypt_dev_*$rootn)
-crypt_count=${#crypt_mapper_devs[@]}
-if [[ crypt_count == 0 ]]; then
-    echo "$0: error: expected crypt_mapper_devs length to be > 0"
-    ls -la /dev/mapper
-    exit 1
-fi
-keyfile_vars=()
-dup_keys=()
-extra_encrypt_hooks=()
 
 
 # If we have more than 1 to decrypt, arch wiki lead me onto
 # a sort of hacky way run the encrypt hook multiple times.
-for ((i=1; i < $crypt_count; i++)); do
-    extra_encrypt_hooks+=(encrypt$i)
-    if (( i = 1 )); then dup_keys=(" "); fi # prefix with an empty space
-    cp /crypto_keyfile.bin /crypto_keyfile$i.bin
-    dup_keys+=(/crypto_keyfile$i.bin)
-    base=/usr/lib/initcpio
-    cp $base/hooks/encrypt{,$i}
-    cp $base/install/encrypt{,$i}
-    sed -i "s/cryptdevice/cryptdevice$i/" $base/hooks/encrypt$i
-    sed -i "s/cryptkey/cryptkey$i/" $base/hooks/encrypt$i
-    crypt_name=${crypt_mapper_devs[i]#/dev/mapper/}
-    crypt_dev=/dev/${crypt_name#crypt_dev_}
-    k_args+=(cryptdevice$i=$crypt_dev:$crypt_name:allow-discards
-             cryptkey$i=rootfs:/crypto_keyfile$i.bin)
-done
 
 # https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system#Configuring_mkinitcpio_2
 # used to have lvm2 after encrypt for lvm, but not using lvm anymore
-for x in encrypt ${extra_encrypt_hooks[@]} btrfs; do
-    sed -ri -f - /etc/mkinitcpio.conf <<EOF
+for x in encrypt btrfs; do
+    sed -ri --follow-symlinks -f - /etc/mkinitcpio.conf <<EOF
 /^ *HOOKS.*\b$x\b/!s/^( *HOOKS=.*)filesystems/\1$x filesystems/
 EOF
 done
 
 # this is the default file, otherwise you use cryptkey=device:fstype:path
-sed -ri -f - /etc/mkinitcpio.conf <<EOF
-s#^\s*FILES=.*#FILES="/crypto_keyfile.bin${dup_keys[*]}"#
+sed -ri --follow-symlinks -f - /etc/mkinitcpio.conf <<EOF
+s#^\s*FILES=.*#FILES="/crypto_keyfile.bin"#
 EOF
 echo "$0: FILES:"
 grep FILES /etc/mkinitcpio.conf
-k_args="${k_args[*]}"
-echo "$0: grub cmdline additions: $k_args"
-sed -ri -f - /etc/default/grub <<EOF
-\%$k_args%!s%^ *GRUB_CMDLINE_LINUX_DEFAULT *= *"%\0$k_args %
+echo "$0: grub cmdline additions: ${k_args[*]}"
+sed -ri --follow-symlinks -f - /etc/default/grub <<EOF
+\%${k_args[*]}%!s%^ *GRUB_CMDLINE_LINUX_DEFAULT *= *"%\0${k_args[*]} %
 EOF
 
 mkinitcpio -p linux
@@ -121,40 +106,30 @@ mkinitcpio -p linux
 
 # remove the default quiet arg.
 # this doesn't seem to affect anything, so leave it alone.
-#sed -ri 's/^( *GRUB_CMDLINE_LINUX_DEFAULT *= *.*) ?\bquiet\b(.*)/\1\2/' /etc/default/grub
+#sed -ri --follow-symlinks 's/^( *GRUB_CMDLINE_LINUX_DEFAULT *= *.*) ?\bquiet\b(.*)/\1\2/' /etc/default/grub
 
 # https://wiki.archlinux.org/index.php/GRUB#Install_to_disk
 for dev in $BOOT_DEVICE; do
     grub-install --recheck $dev
 done
 grub-mkconfig -o /boot/grub/grub.cfg
-pacman -S --noconfirm openssh unison
+# gtk2 is an optional dependency of unison.
+# I know Im gonna want the gui, so just doing it now.
+pacman -S --noconfirm openssh rsync
 
-echo "root:$ROOTPW" | chpasswd -e
 
 pacman -S --noconfirm sudo
 
-# 9 = user already exists. so we are idempotent.
-useradd -m -p "$ROOTPW" ian || [[ $? == 9 ]]
-
-if [[ $hostname == frodo ]]; then
-    useradd -m -p "$TPPASS" traci || [[ $? == 9 ]]
-else
-    useradd -m traci || [[ $? == 9 ]]
-fi
-# comparing ian's groups to traci, I see none she should join on arch
-usermod -a -G traci ian
-
-
-/root/distro-install-common/end
+. /a/bin/fai/fai-wrapper
+/a/bin/fai/fai/config/distro-install-common/end
 systemctl enable sshd
 
-rm -rf /home/ian/.ssh
-cp -r /root/.ssh /home/ian
-chown ian:ian /home/ian/.ssh
+rm -rf /home/iank/.ssh
+cp -r /root/.ssh /home/iank
+chown -R iank:iank /home/iank/.ssh
 # the groups recommended by
 # https://wiki.archlinux.org/index.php/Users_and_groups#Group_list
-usermod -aG games,rfkill,users,uucp,wheel ian
+usermod -aG games,rfkill,users,uucp,wheel iank
 
 
 pacman -S --noconfirm net-tools # for route