various fixes
authorIan Kelling <ian@iankelling.org>
Tue, 12 Jul 2016 14:47:24 +0000 (07:47 -0700)
committerIan Kelling <ian@iankelling.org>
Mon, 6 Feb 2017 06:21:41 +0000 (22:21 -0800)
13 files changed:
README
arch-init
fai-wrapper
fai/config/class/50-host-classes
fai/config/distro-install-common/end
fai/config/files/etc/apt/preferences/LINODESTABLE [new symlink]
fai/config/files/etc/apt/sources.list.d/linodestable.list/LINODESTABLE [new file with mode: 0644]
fai/config/hooks/instsoft.DEFAULT
fai/config/scripts/GRUB_PC/11-ian
faiserver-revm
pxe-server
wrt-setup
wrt-setup-remote

diff --git a/README b/README
index f9137a04dd0617c07a9dd3f9777639b6fead7b3b..e1ceffd987b647fcf74a4e7121d958f84738194a 100644 (file)
--- a/README
+++ b/README
@@ -2,3 +2,15 @@ Scripts for initial setup of OSes on my home network.
 
 My network is a wndr3700v2 router with openwrt on it and a few pcs
 with various gnu/linux distros on them.
+
+
+Scripts meant to be called interactively:
+
+
+arch-init-remote # install arch (after it's been booted into it's setup env)
+fai-revm  # test fai on a fresh vm
+faiserver-revm # create a vm which is a fai server
+faiserver-uninstall
+fresize # resize swap or boot partitions in a host created with my fai setup
+pxe-server # temporarily enable (usually) fai or arch boot server
+wrt-setup-remote  # setup my router
index 007780771eeb2a08bdb0ea33f71379a35712980e..36b77c6b6851ca851b48949abf9db399ff3c39f4 100755 (executable)
--- a/arch-init
+++ b/arch-init
@@ -7,7 +7,7 @@ trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 cd $(dirname $(readlink -f "$BASH_SOURCE"))
 
-export hostname="$1"
+export HOSTNAME="$1"
 mirror=$2
 TPPASS="$(cat /root/shadow/traci-simple)"
 
index 8b44a6f4013657c2d08ebafbeac3320c887030cf..5a38b834cf3c1bd6fe3a15ae32dc353496160e09 100644 (file)
@@ -7,7 +7,7 @@ ifclass() {
 }
 export -f ifclass
 classes=  # used by fcopy
-for x in $(bash /a/bin/fai/config/class/50-host-classes); do
+for x in $(bash /a/bin/fai/fai/config/class/50-host-classes); do
     # export class vars with CLASS_ in front to avoid name colissions.
     classes+=" $x"
     export CLASS_$x=true
@@ -15,4 +15,4 @@ done
 classes="${classes# }"
 export classes
 export FAI_ROOT=/
-export FAI=/a/bin/fai/config
+export FAI=/a/bin/fai/fai/config
index 894261aab32d2bf309651d7d2b0de6a85ff90f8b..cc8e3defda6c789f42bcfd151939116a386f29e9 100755 (executable)
@@ -12,11 +12,15 @@ case $HOSTNAME in
     x2)
         echo "FAIBASE DEBIAN DESKTOP PARTITION_PROMPT" ;;
     tp)
-        echo "FAIBASE DEBIAN DESKTOP PARTITION_PROMPT" ;;
+        echo "FAIBASE DEBIAN DESKTOP PARTITION_PROMPT STABLE" ;;
     frodo)
         echo "FAIBASE DEBIAN DESKTOP PARTITION_PROMPT" ;;
     treetowl)
         echo "FAIBASE DEBIAN DESKTOP PARTITION_PROMPT" ;;
+    lj)
+        echo "FAIBASE DEBIAN LINODESTABLE PARTITION_PROMPT" ;;
+    li)
+        echo "FAIBASE DEBIAN LINODESTABLE PARTITION_PROMPT" ;;
     # faiserver)
     #     echo "FAIBASE DEBIAN DEMO FAISERVER" ;;
     # xfcehost)
index b55295232e614959ff7daf2ba16c302fe9c086ab..6be266ebacfedd9b4e8a61d0b9bd14ece91a0267 100755 (executable)
@@ -9,9 +9,9 @@ if [[ $EUID != 0 ]]; then
 fi
 
 ### begin set hostname
-echo $hostname > /etc/hostname
+echo $HOSTNAME > /etc/hostname
 sed -i '/^127\.0\.1\.1/d' /etc/hosts
-echo "127.0.1.1 $hostname" >> /etc/hosts
+echo "127.0.1.1 $HOSTNAME" >> /etc/hosts
 hostname -F /etc/hostname
 ### end set hostname
 
@@ -33,19 +33,16 @@ chpw() {
     pwfile=$2
     if [[ $pwfile && -e $pwfile ]]; then
         printf "$user:" | cat - "$pwfile" | $ROOTCMD chpasswd -e
-        else
-            echo "$0: warning: no pw set for $user"
+    else
+        echo "$0: warning: no pw set for $user"
     fi
 }
 au() {
     if ! $ROOTCMD getent passwd $1; then
-        $ROOTCMD useradd -m $1 -s /bin/bash || [[ $? == 9 ]]
+        $ROOTCMD useradd -m -s /bin/bash $1 || [[ $? == 9 ]]
     fi
 }
 
-echo "IANNNNNNN 222222222, $ROOTPW"
-ls -la $ROOTPW
-
 chpw root "$ROOTPW"
 # 9 = user already exists. so we are idempotent.
 au ian
@@ -80,10 +77,7 @@ fi
 dir=/q/p/c/machine_specific/$HOSTNAME/.unison
 $ROOTCMD mkdir -p $dir
 
-$ROOTCMD rm -rf /root/.unison
-$ROOTCMD ln -sf $dir /root
 $ROOTCMD ln -sf /q/p /
-
 $ROOTCMD chown -R 1000:1000 $dir
 while true; do
     $ROOTCMD chown 1000:1000 $dir
diff --git a/fai/config/files/etc/apt/preferences/LINODESTABLE b/fai/config/files/etc/apt/preferences/LINODESTABLE
new file mode 120000 (symlink)
index 0000000..31109f8
--- /dev/null
@@ -0,0 +1 @@
+STABLE
\ No newline at end of file
diff --git a/fai/config/files/etc/apt/sources.list.d/linodestable.list/LINODESTABLE b/fai/config/files/etc/apt/sources.list.d/linodestable.list/LINODESTABLE
new file mode 100644 (file)
index 0000000..056de00
--- /dev/null
@@ -0,0 +1,9 @@
+deb http://mirrors.linode.com/debian/ jessie main
+deb-src http://mirrors.linode.com/debian/ jessie main
+
+deb http://security.debian.org/ jessie/updates main
+deb-src http://security.debian.org/ jessie/updates main
+
+# jessie-updates, previously known as 'volatile'
+deb http://mirrors.linode.com/debian/ jessie-updates main
+deb-src http://mirrors.linode.com/debian/ jessie-updates main
index 3eda00ee9d6a57873c2cce167729eaefc28cc4c2..b4b3c1028b00ff3890cab3471d81f3107313cf3c 100755 (executable)
@@ -29,14 +29,14 @@ EOF
 chmod +x $f
 
 
-if ifclass tp; then
-    d=$target/q/root/shadow
-    mkdir -p $d
-    # ls -la /var/lib/fai/config/distro-install-common
-    cp /var/lib/fai/config/distro-install-common/traci{,-simple} $d
-    chmod -R o-rwx $d
+if ifclass demohost; then
+    files=(/var/lib/fai/config/distro-install-common/luks/host-demohost)
+elif ifclass tp; then
+    files=(/var/lib/fai/config/distro-install-common/luks/host-{tp,demohost})
+fi
+if [[ ${files[0]}  ]]; then
     d=$target/q/root/luks
     mkdir -p $d
-    cp /var/lib/fai/config/distro-install-common/luks/host-{tp,demohost} $d
+    cp ${files[@]} $d
     chmod -R o-rwx $d
 fi
index 629d1bc6a0deaf9a34b91c49b10dd44dda4bad1c..5d064be41bfa8593539c54ac1e1d9d65ee494c8d 100755 (executable)
@@ -8,40 +8,44 @@ if [[ $EUID != 0 ]]; then
     exit 1
 fi
 
+if ! type -t fcopy &>/dev/null; then
+    sudo apt-get -y install fai-client
+fi
 
 dir=/q/root/shadow
-if [[ ! -e $dir ]]; then
+fai_shadow=$FAI/distro-install-common/shadow
+if [[ ! -e $dir && -e $fai_shadow ]]; then
     mkdir -p $dir
-    echo "IANNNNNN 111"
-    ls -la $FAI/distro-install-common/shadow
-    mount -o bind $FAI/distro-install-common/shadow $dir
+    mount -o bind $fai_shadow $dir
 fi
 $FAI/distro-install-common/end
 
-if ifclass STABLE; then
+if ifclass STABLE || ifclass LINODESTABLE; then
     fcopy -M /etc/apt/preferences
 fi
 
 if ifclass DEBIAN; then
     fcopy -M /etc/apt/preferences.d/unstable
     fcopy -riM /etc/apt/sources.list.d
+    $ROOTCMD apt-get update
 fi
 
 
 # note:
 # fcopy -i = ignore nonmatching class error, always return 0.
 
-f=$FAI_ROOT/home/ian/.ssh/authorized_keys
-if [[ ! -L $f || -e $f ]]; then
-    fcopy -r -M /home/ian/.ssh
-else
-    echo "$0: info: $f exists"
-fi
+# for lj, this will be empty and fail
+fcopy -riM /home/ian/.ssh
 
 rm -f $FAI_ROOT/etc/apt/sources.list
 
 chroot $FAI_ROOT bash <<'EOF'
 set -eE -o pipefail
+mkdir -p /home/ian/.ssh
+f=/root/.ssh/authorized_keys
+if [[ -e $f ]]; then
+   cp $f /home/ian/.ssh
+fi
 chown -R 1000:1000 /home/ian/.ssh
 chmod -R u=Xrw,og= /home/ian/.ssh
 rm -rf /root/.ssh
@@ -49,8 +53,8 @@ cp -rL /home/ian/.ssh /root
 chown -R root:root /root/.ssh
 chmod 700 /root/.ssh
 
-# default jessie groups + kvm & systemd-journal
-usermod -aG cdrom,floppy,sudo,audio,dip,video,plugdev,netdev,systemd-journal ian
+# default jessie groups + kvm, systemd-journal, adm
+usermod -aG adm,cdrom,floppy,sudo,audio,dip,video,plugdev,netdev,systemd-journal ian
 EOF
 
 
index f546accd3238df6166c94e5ee83d2150660ef490..1f84b0dd5ab928dc2ef5d785752aba8ededdef3b 100755 (executable)
@@ -1,4 +1,5 @@
 #!/bin/bash -l
+# create a vm which is a fai server
 set -x
 
 set -eE -o pipefail
index 574a896f05ea3e19bb73590655f5b8e816772252..6099ddba82f9b98a2bfa1d2e065784843f9e2d45 100755 (executable)
@@ -22,6 +22,7 @@ HOST makes the pxe server only for that specific host
 -h|--help  Print help and exit
 --         Subsequent arguments are never treated as options
 -p         Persist. Otherwise, wait for 2 dhcp acks then remove.
+-r         Don't redeploy fai config.
 EOF
     exit $1
 }
@@ -30,12 +31,12 @@ EOF
 
 persist=false
 args=()
-redep=false
+redep=true
 while [[ $1 ]]; do
     case $1 in
         --) shift; break ;;
         -h|--help) usage ;;
-        -r) redep=true; shift ;;
+        -r) redep=false; shift ;;
         -p) persist=true; shift ;;
         *) args+=("$1"); shift ;;
     esac
@@ -88,28 +89,46 @@ dhcp-boot=${host_tag}fai/pxelinux.0,faiserver.lan,faiserver.lan
 EOF
 }
 
-echo "setting config type: $type"
-$type | ssh wrt "cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart #
-if [[ $type == arch ]]; then arch-pxe-mount; fi"
-
-
-if $redep && [[ $type == fai ]]; then
-    fai-redep
-fi
-if ! $persist; then
-    echo "waiting for 2 dhcp acks then disabling pxe"
+ack-wait() {
+    wait_count=$1
     if [[ $host ]]; then
         host_regex=" $host"
     fi
     regex=".*DHCPACK.*$host_regex$"
     i=0
     tmp=$(mktemp)
-    while (( i != 2 )) && read line; do
+    while (( i != wait_count )) && read line; do
         if [[ $line =~ $regex ]]; then
             i=$((i+1))
             echo $line
         fi
     done < <(ssh wrt logread -f)
     sv sleep 5
-    sv "$BASH_SOURCE" :
+}
+
+set-pxe() {
+    ${1:-$type} | ssh wrt "cedit pxe-server /etc/dnsmasq.conf || /etc/init.d/dnsmasq restart
+if [[ $type == arch ]]; then arch-pxe-mount; fi"
+}
+
+set-pxe
+
+if [[ $type == fai ]]; then
+    if $redep; then
+        fai-redep
+    fi
+    faiserver-enable
+fi
+
+if ! $persist; then
+    echo "waiting for 2 dhcp acks then disabling pxe"
+    ack-wait 2
+    set-pxe :
+    if [[ $type == fai ]]; then
+        # fai server can contain sensitive info, so turn it off
+        # when it's not in use.
+        echo "waiting for 1 dhcp ack then disabling fai server"
+        ack-wait 1
+        faiserver-disable
+    fi
 fi
index 7a68c49ad02dd4205dee7942e8d19286482ad792..beea6b1b1639fd8a6b0dcc0866533e3409bb07f3 100755 (executable)
--- a/wrt-setup
+++ b/wrt-setup
@@ -232,7 +232,8 @@ cedit /etc/hosts <<EOF || dnsmasq_restart=true
 192.168.1.6 testvm
 192.168.1.8 tp
 72.14.176.105 li
-173.255.198.166 lj
+173.255.202.210 lj
+23.239.31.172 lk
 EOF
 
 
@@ -258,23 +259,25 @@ cedit /etc/dnsmasq.conf <<'EOF' || dnsmasq_restart=true
 # in a browsing session, I probably won't ever do 5000 lookups
 # before the ttl expiration or whatever does expiration.
 cache-size=10000
+# ask all servers, use the one which responds first.
 # http://ma.ttwagner.com/make-dns-fly-with-dnsmasq-all-servers/
 all-servers
-# namebench showed 4 servers fairly close ranking:
+# namebench showed 4 servers fairly close ranking.
 # qwest
-server=205.171.3.65
-server=205.171.2.25
+#server=205.171.3.65
+#server=205.171.2.25
 # clearwire anchorage
-server=64.13.115.12
+#server=64.13.115.12
 # comcast spokane
-server=68.87.69.146
+#server=68.87.69.146
 # google
 server=8.8.4.4
+server=8.8.8.8
 # NTT
-server=129.250.35.250
+#server=129.250.35.250
 # isp servers
-server=75.75.76.76
-server=75.75.75.75
+#server=75.75.76.76
+#server=75.75.75.75
 
 
 
index 12f65673433294436ce3dc8b59c40bc123fc0d34..7bbdea6e41cf4f90336e13ed47f0f3e22bff52db 100755 (executable)
@@ -4,7 +4,7 @@ set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
 h=root@192.168.1.1
-scp /a/bin/fai/wrt-setup /a/bin/bash-programs-by-ian/repos/cedit/cedit $h:/usr/bin
+scp /a/bin/fai/wrt-setup /a/bin/cedit/cedit $h:/usr/bin
 ssh $h <<'EOF'
 if ! opkg list-installed|grep bash; then
     opkg update