fix stretch, upgrade from jessie broke
[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 # Note, sometimes shutting down the existing demohost vm
19 # fails. Just run again if that happens.
20
21 # Deploy fai configuration to faiserver,
22 # then start a virtual machine to test the config.
23
24 cleanup() { :; }
25 set -eE -o pipefail
26 trap 'cleanup; echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
27 script_dir=$(dirname $(readlink -f "$BASH_SOURCE"))
28
29 e() { echo "$*"; "$@"; }
30
31 # I had this set false as default before, can't remember why. oh well.
32 redeploy=true
33 if [[ $1 == -r ]]; then
34 redeploy=false
35 fi
36
37 disk_count=2
38
39
40 if [[ $script_dir == /a/bin/* ]]; then
41 # Copy our script elsewhere so we can develop it
42 # and save it at the same time it's running
43 rm -rf /tmp/faifreeze
44 mkdir -p /a/tmp
45 cp -ar /a/bin/fai /tmp/faifreeze
46 exec /tmp/faifreeze/${BASH_SOURCE##*/} "$@"
47 fi
48
49 cd $script_dir
50
51 is_arch_revm() {
52 [[ ${0##*/} == arch-revm ]]
53 }
54
55 new_disk=false
56 [[ ! $1 ]] || new_disk=true
57
58 cleanup() { ./pxe-server :; }
59 if is_arch_revm; then
60 ./pxe-server arch
61 sleep 2
62 # via osinfo-query os. guessing arch is closest to latest fedora.
63 variant=fedora22
64 else
65 ./pxe-server fai
66 sleep 2
67 if $redeploy; then
68 ./fai-redep
69 fi
70 variant=debian8
71 fi
72
73 name=demohost
74
75 e s virshrm $name ||:
76
77
78 disk_arg=()
79 for ((i=1; i <= disk_count; i++)); do
80 f=/var/lib/libvirt/images/${name}$i
81 disk_arg+=("--disk path=$f")
82 if $new_disk || [[ ! -e $f ]]; then
83 s rm -f $f
84 e s qemu-img create -o preallocation=metadata -f qcow2 $f 20G
85 fi
86 done
87
88 if [[ $SSH_CLIENT ]]; then
89 console_arg=--noautoconsole
90 fi
91
92 # --cpu host: this causes mkfs.btrfs to fail with a stack trace which began
93 # something like:
94 # init_module+0x108/0x1000 [raid6_pq]
95 #
96 # uniq is to stop gtk-warning spam
97 e s virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \
98 ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad \
99 --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^ *$' | uniq &
100
101 if [[ $SSH_CLIENT ]]; then
102 fg
103 fi
104
105 sleep 30
106 while ! timeout -s 9 10 ssh root@$name /bin/true; do
107 e sleep 5
108 done
109 cleanup() { :; }
110 e pxe-server :
111 if is_arch_revm; then
112 ./arch-init-remote $name
113 fi