code cleanup, arch fixes
authorIan Kelling <ian@iankelling.org>
Sat, 11 Feb 2017 08:37:17 +0000 (00:37 -0800)
committerIan Kelling <ian@iankelling.org>
Sat, 11 Feb 2017 08:37:17 +0000 (00:37 -0800)
arch might still need more fixes

README
arch-init
arch-init-chroot
arch-init-remote
arch-pxe
fai-revm
pxe-server
wrt-setup

diff --git a/README b/README
index d579feb4c001a6deefaddc9b40b5f8f80edada92..fa28fa97944cc5e1d8bbff0b7848920e4eee865a 100644 (file)
--- a/README
+++ b/README
@@ -49,6 +49,7 @@ All scripts meant to be used directly are listed here:
 
 # Scripts to setup the environment for the install
 
 
 # Scripts to setup the environment for the install
 
+arch-pxe # Setup arch pxe boot server from an arch base image
 fai-redep # Deploy fai configuration to host "faiserver"
 faiserver-revm # using pxe & preseed, create a vm which is a fai server
 faiserver-uninstall # uninstall fai-server
 fai-redep # Deploy fai configuration to host "faiserver"
 faiserver-revm # using pxe & preseed, create a vm which is a fai server
 faiserver-uninstall # uninstall fai-server
index aa26ffdf68ac2a9051d562282c76207645a74613..982357f0a66f16161b83f728fccf8ce6e0c32cbb 100755 (executable)
--- a/arch-init
+++ b/arch-init
@@ -22,7 +22,6 @@ x="$(readlink -f "$BASH_SOURCE")"; cd ${x%/*}
 
 export HOSTNAME="$1"
 mirror=$2
 
 export HOSTNAME="$1"
 mirror=$2
-TPPASS="$(cat /root/shadow/traci-simple)"
 
 (( $# >= 1 )) || { echo "$0: error: need 1 or 2 arguments"; exit 1; }
 
 
 (( $# >= 1 )) || { echo "$0: error: need 1 or 2 arguments"; exit 1; }
 
@@ -73,8 +72,7 @@ sed -ri --follow-symlinks "/^crypt_dev_\S+$rootn /d" /tmp/fai/crypttab
 
 if ! $already_partitioned; then
     mount -o subvol=root_$DISTRO $ROOT_PARTITION /mnt
 
 if ! $already_partitioned; then
     mount -o subvol=root_$DISTRO $ROOT_PARTITION /mnt
-    mkdir -p /mnt/{a,home,boot}
-    mount -o subvol=a $ROOT_PARTITION /mnt/a
+    mkdir -p /mnt/boot
     mount -o subvol=boot_$DISTRO $BOOT_PARTITION /mnt/boot
 fi
 
     mount -o subvol=boot_$DISTRO $BOOT_PARTITION /mnt/boot
 fi
 
@@ -102,6 +100,7 @@ bindmount() {
     mount -o bind $source $mountpoint
 }
 bindmount /root/shadow /mnt/q/root/shadow
     mount -o bind $source $mountpoint
 }
 bindmount /root/shadow /mnt/q/root/shadow
+bindmount /a /mnt/a
 
 mkdir -p /mnt/etc/ssh
 cp /etc/ssh/ssh_host_* /mnt/etc/ssh
 
 mkdir -p /mnt/etc/ssh
 cp /etc/ssh/ssh_host_* /mnt/etc/ssh
index 7eac7ebe3e08c483b68bd3c4fd986c4747632128..7eaa5a20fd714155c3d2361baee6f0968c41c4aa 100755 (executable)
@@ -77,15 +77,11 @@ k_args=(
     root=/dev/mapper/crypt_dev_${first_root_dev##*/}
     resume=${first_root_dev%[0-9]}$swapn
 )
     root=/dev/mapper/crypt_dev_${first_root_dev##*/}
     resume=${first_root_dev%[0-9]}$swapn
 )
-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.
 
 
 
 # If we have more than 1 to decrypt, arch wiki lead me onto
 # a sort of hacky way run the encrypt hook multiple times.
 
-base=/usr/lib/initcpio
-
-
 # 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 btrfs; do
 # 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 btrfs; do
@@ -100,10 +96,9 @@ s#^\s*FILES=.*#FILES="/crypto_keyfile.bin"#
 EOF
 echo "$0: FILES:"
 grep FILES /etc/mkinitcpio.conf
 EOF
 echo "$0: FILES:"
 grep FILES /etc/mkinitcpio.conf
-k_args="${k_args[*]}"
-echo "$0: grub cmdline additions: $k_args"
+echo "$0: grub cmdline additions: ${k_args[*]}"
 sed -ri --follow-symlinks -f - /etc/default/grub <<EOF
 sed -ri --follow-symlinks -f - /etc/default/grub <<EOF
-\%$k_args%!s%^ *GRUB_CMDLINE_LINUX_DEFAULT *= *"%\0$k_args %
+\%${k_args[*]}%!s%^ *GRUB_CMDLINE_LINUX_DEFAULT *= *"%\0${k_args[*]} %
 EOF
 
 mkinitcpio -p linux
 EOF
 
 mkinitcpio -p linux
index ceb3081c1adb36608b9db34454bb338bfeab55d9..6e460a5f0b15cc26f383b3c36bca8ebadd4d0ef3 100755 (executable)
@@ -41,7 +41,6 @@ if [[ -e  /var/cache/pacman/pkg ]]; then
     darkhttpd /var/cache/pacman/pkg &
     mirror=http://$HOSTNAME:8080
 fi
     darkhttpd /var/cache/pacman/pkg &
     mirror=http://$HOSTNAME:8080
 fi
-faid=/a/bin/fai
 
 rsync -rlpthvi --relative /a/bin/fai/ root@$host:/
 rsync /a/bin/fai/ root@$host:/a/bin/fai/
 
 rsync -rlpthvi --relative /a/bin/fai/ root@$host:/
 rsync /a/bin/fai/ root@$host:/a/bin/fai/
index 5a26fd70a7f97c9a66bc4035907f15a69ed8ce96..e480b5d7173ebb8d1c0dc639494c9180d18a19b9 100755 (executable)
--- a/arch-pxe
+++ b/arch-pxe
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 # Setup arch pxe boot server from the base image.
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
 # Setup arch pxe boot server from the base image.
-# Requires manually downloading image to /a/opt, and set it's name below.
+#
 
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
+usage() {
+    cat <<EOF
+Usage: ${0##*/}
+Setup arch pxe boot server from the base image
+
+Requires manually downloading image. Image path is hardcoded below to
+/a/opt/image_name. Run pxe-server HOST|default arch to enable it.
+
+-h|--help  Print help and exit.
+EOF
+    exit $1
+}
+
+case $1 in
+    -h|--help) usage ;;
+esac
+
+
 x="$(readlink -f "$BASH_SOURCE")"
 script_dir="${x%/*}"
 cd /a/opt
 x="$(readlink -f "$BASH_SOURCE")"
 script_dir="${x%/*}"
 cd /a/opt
-iso="archlinux-2016.05.01-dual"
+iso="archlinux-2017.02.01-dual"
 sfs=$iso/arch/x86_64/airootfs.sfs
 rm -rf $iso
 ex $iso.iso
 sfs=$iso/arch/x86_64/airootfs.sfs
 rm -rf $iso
 ex $iso.iso
@@ -47,7 +65,7 @@ s rm $sfs
 s mksquashfs squashfs-root $sfs -comp xz
 # file transfer to wrt is slow, so remove some useless files
 rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
 s mksquashfs squashfs-root $sfs -comp xz
 # file transfer to wrt is slow, so remove some useless files
 rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
-c $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; b
+pushd $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; popd
 
 # seems if you've done a pxe boot, mounted the nfs,
 # then shutdown, it's still busy.
 
 # seems if you've done a pxe boot, mounted the nfs,
 # then shutdown, it's still busy.
@@ -59,12 +77,10 @@ ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $iso tftpboot"
 
 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
 
 
 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
 
-pxe-server default arch
-
-# background:
-# great documentation at https://wiki.archlinux.org/index.php/PXE
-# background: arch can do netboot like ubuntu etc, but the docs look a little complicated, so fuck it,
-# we use nfs cuz it's easy
+# background: great documentation at
+# https://wiki.archlinux.org/index.php/PXE
+# arch can do netboot like ubuntu etc, but the docs look a little
+# complicated, so fuck it, we use nfs cuz it's easy
 
 rm -rf $iso
 s rm -rf squashfs-root
 
 rm -rf $iso
 s rm -rf squashfs-root
index cc494cccb2c424293cf95ca05383b4c9dd44a3a7..6f8beeb6c326f521872634fce90e3ecaa072745a 100755 (executable)
--- a/fai-revm
+++ b/fai-revm
@@ -34,7 +34,7 @@ then start a virtual machine to test the config
 Note, sometimes shutting down the existing demohost vm
 fails. Just run again if that happens.
 
 Note, sometimes shutting down the existing demohost vm
 fails. Just run again if that happens.
 
--r         Do not reboot.
+-r         Do not boot after install is complete
 -n         Create new qcow2(s) for vm
 -h|--help  Print help and exit.
 
 -n         Create new qcow2(s) for vm
 -h|--help  Print help and exit.
 
@@ -45,13 +45,12 @@ EOF
 
 
 new_disk=false
 
 
 new_disk=false
-reboot=true
 temp=$(getopt -l help hnr "$@") || usage 1
 eval set -- "$temp"
 while true; do
     case $1 in
         -n) new_disk=true; shift ;;
 temp=$(getopt -l help hnr "$@") || usage 1
 eval set -- "$temp"
 while true; do
     case $1 in
         -n) new_disk=true; shift ;;
-        -r) reboot=false; shift ;;
+        -r) reboot_arg=--noreboot; shift ;;
         -h|--help) usage ;;
         --) shift; break ;;
         *) echo "$0: Internal error!" ; exit 1 ;;
         -h|--help) usage ;;
         --) shift; break ;;
         *) echo "$0: Internal error!" ; exit 1 ;;
@@ -120,7 +119,7 @@ fi
 #
 # uniq is to stop gtk-warning spam
 e s virt-install --os-variant $variant  -n $name --pxe -r 2048 --vcpus 1 \
 #
 # uniq is to stop gtk-warning spam
 e s virt-install --os-variant $variant  -n $name --pxe -r 2048 --vcpus 1 \
-  ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad \
+  ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad $reboot_arg \
   --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq &
 
 if [[ $SSH_CLIENT ]]; then
   --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq &
 
 if [[ $SSH_CLIENT ]]; then
index fb92d66c82b736692ce2d9849491c4798d83101e..a3df1a5953846368397e9b335be844970b132771 100755 (executable)
@@ -63,7 +63,6 @@ EOF
 
 ##### begin command line parsing ########
 
 
 ##### begin command line parsing ########
 
-args=()
 redep=true
 acks=2
 wait=false
 redep=true
 acks=2
 wait=false
@@ -80,7 +79,7 @@ while true; do
     esac
 done
 
     esac
 done
 
-read host type <<<"$@"
+read -r host type <<<"$@"
 
 case $# in
     0|2);;
 
 case $# in
     0|2);;
@@ -120,7 +119,6 @@ EOF
 
 fai() {
     cat <<EOF
 
 fai() {
     cat <<EOF
-$set_host_tag
 dhcp-boot=${host_tag}pxelinux.0,faiserver.lan,faiserver.lan
 EOF
 }
 dhcp-boot=${host_tag}pxelinux.0,faiserver.lan,faiserver.lan
 EOF
 }
@@ -132,8 +130,7 @@ ack-wait() {
     fi
     regex=".*DHCPACK.*$host_regex$"
     i=0
     fi
     regex=".*DHCPACK.*$host_regex$"
     i=0
-    tmp=$(mktemp)
-    while (( i != wait_count )) && read line; do
+    while (( i != wait_count )) && read -r line; do
         if [[ $line =~ $regex ]]; then
             i=$((i+1))
             echo $line
         if [[ $line =~ $regex ]]; then
             i=$((i+1))
             echo $line
index aa34f67f4321872434d6ba55b23f75045db23871..15f28cb7f553d3885eb1d0a86d5d070d1572afca 100755 (executable)
--- a/wrt-setup
+++ b/wrt-setup
@@ -25,7 +25,6 @@ pmirror() {
     # doesn't go into the firmware. build new firmware if you want
     # lots of upgrades.
     f=(/tmp/opkg-lists/*)
     # doesn't go into the firmware. build new firmware if you want
     # lots of upgrades.
     f=(/tmp/opkg-lists/*)
-    f=${f[0]}
     if ! (( $(date -r $f +%s) + 60*60*24 > $(date +%s) )); then
         opkg update
     fi
     if ! (( $(date -r $f +%s) + 60*60*24 > $(date +%s) )); then
         opkg update
     fi