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