add xenial support with basic debian parity
[automated-distro-installer] / fai-revm
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
18
19
20 cleanup() { :; }
21 set -eE -o pipefail
22 trap 'cleanup; echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
23 script_dir=$(dirname $(readlink -f "$BASH_SOURCE"))
24
25 e() { echo "$*"; "$@"; }
26
27
28 usage() {
29 cat <<EOF
30 # Usage: ${0##*/} [OPTIONS]
31 Setup fai or arch pxe (depending on $0 name)
32 then start a virtual machine to test the config
33
34 Note, sometimes shutting down the existing demohost vm
35 fails. Just run again if that happens.
36
37 -r Do not reboot.
38 -n Create new qcow2(s) for vm
39 -h|--help Print help and exit.
40
41 Note: Uses GNU getopt options parsing style
42 EOF
43 exit $1
44 }
45
46
47 # not sure why I wanted to have this option before. oh well.
48 redeploy=true
49
50 reboot=true
51 temp=$(getopt -l opt o "$@") || usage 1
52 eval set -- "$temp"
53 while true; do
54 case $1 in
55 -n) new_disk=true; shift ;;
56 -r) reboot=false; shift ;;
57 -h|--help) usage ;;
58 --) shift; break ;;
59 *) echo "$0: Internal error!" ; exit 1 ;;
60 esac
61 done
62
63
64 if [[ $1 == -r ]]; then
65 redeploy=false
66 fi
67
68 # change this to test different disk counts. 1 and > 1 should be the only
69 # important things to test.
70 disk_count=1
71
72
73 if [[ $script_dir == /a/bin/* ]]; then
74 # Copy our script elsewhere so we can develop it
75 # and save it at the same time it's running
76 rm -rf /tmp/faifreeze
77 mkdir -p /a/tmp
78 cp -ar /a/bin/fai /tmp/faifreeze
79 exec /tmp/faifreeze/${BASH_SOURCE##*/} "$@"
80 fi
81
82 cd $script_dir
83
84 is_arch_revm() {
85 [[ ${0##*/} == arch-revm ]]
86 }
87
88 cleanup() { ./pxe-server :; }
89 if is_arch_revm; then
90 ./pxe-server arch
91 sleep 2
92 # via osinfo-query os. guessing arch is closest to latest fedora.
93 variant=fedora22
94 else
95 ./pxe-server fai
96 sleep 2
97 if $redeploy; then
98 ./fai-redep
99 fi
100 variant=ubuntu16.04
101 #variant=debian8
102 fi
103
104 name=demohost
105
106 e s virshrm $name ||:
107
108
109 disk_arg=()
110 for ((i=1; i <= disk_count; i++)); do
111 f=/var/lib/libvirt/images/${name}$i
112 disk_arg+=("--disk path=$f")
113 if $new_disk || [[ ! -e $f ]]; then
114 s rm -f $f
115 e s qemu-img create -o preallocation=metadata -f qcow2 $f 20G
116 fi
117 done
118
119 if [[ $SSH_CLIENT ]]; then
120 console_arg=--noautoconsole
121 fi
122
123 # --cpu host: this causes mkfs.btrfs to fail with a stack trace which began
124 # something like:
125 # init_module+0x108/0x1000 [raid6_pq]
126 #
127 # uniq is to stop gtk-warning spam
128 e s virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \
129 ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad \
130 --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq &
131
132 if [[ $SSH_CLIENT ]]; then
133 fg
134 fi
135
136 sleep 30
137 while ! timeout -s 9 10 ssh root@$name /bin/true; do
138 e sleep 5
139 done
140 cleanup() { :; }
141 e pxe-server :
142 if is_arch_revm; then
143 ./arch-init-remote $name
144 fi