add copyright, fix arch
[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 rm -rf /a/tmp/fai2
40 mkdir -p /a/tmp
41 cp -ar /a/bin/fai /a/tmp/fai2
42 exec /a/tmp/fai2/${BASH_SOURCE##*/} "$@"
43 fi
44
45 cd $script_dir
46
47 is_arch_revm() {
48 [[ ${0##*/} == arch-revm ]]
49 }
50
51 new_disk=false
52 [[ ! $1 ]] || new_disk=true
53
54 if is_arch_revm; then
55 ./pxe-server arch &
56 sleep 2
57 # via osinfo-query os. guessing arch is closest to latest fedora.
58 variant=fedora22
59 else
60 ./pxe-server fai &
61 sleep 2
62 if $redeploy; then
63 ./fai-redep
64 fi
65 variant=debian8
66 fi
67
68 name=demohost
69
70 s virshrm $name ||:
71
72
73 disk_arg=()
74 for ((i=1; i <= disk_count; i++)); do
75 f=/var/lib/libvirt/images/${name}$i
76 disk_arg+=("--disk path=$f")
77 if $new_disk || [[ ! -e $f ]]; then
78 s rm -f $f
79 s qemu-img create -o preallocation=metadata -f qcow2 $f 20G
80 fi
81 done
82
83 if [[ $SSH_CLIENT ]]; then
84 console_arg=--noautoconsole
85 fi
86
87 # --cpu host: this causes mkfs.btrfs to fail with a stack trace which began
88 # something like:
89 # init_module+0x108/0x1000 [raid6_pq]
90 #
91 # uniq is to stop gtk-warning spam
92 s virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \
93 ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad \
94 --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^$' | uniq &
95
96 if [[ $SSH_CLIENT ]]; then
97 fg
98 fi
99
100
101 if is_arch_revm; then
102 while ! timeout -s 9 10 ssh root@$name /bin/true; do sleep 1; done
103 ./arch-init-remote $name
104 fi