main fai scripts can run outside of fai, fixup stuff
[automated-distro-installer] / fai-revm
1 #!/bin/bash -l
2 set -x
3
4 # Assumes pxe config for dhcp has been setup.
5 # Deploy fai configuration to faiserver,
6 # then start a virtual machine to test the config.
7
8 set -eE -o pipefail
9 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
10
11 # I had this set false as default before, can't remember why. oh well.
12 redeploy=true
13 if [[ $1 == -r ]]; then
14 redeploy=false
15 fi
16
17 disk_count=2
18
19 script_dir=$(dirname $(readlink -f "$BASH_SOURCE"))
20
21 if [[ $script_dir == /a/bin/* ]]; then
22 rm -rf /a/tmp/fai2
23 mkdir -p /a/tmp
24 cp -ar /a/bin/fai /a/tmp/fai2
25 exec /a/tmp/fai2/${BASH_SOURCE##*/} "$@"
26 fi
27
28 cd $script_dir
29
30 is_arch_revm() {
31 [[ ${0##*/} == arch-revm ]]
32 }
33
34 new_disk=false
35 [[ ! $1 ]] || new_disk=true
36
37 if is_arch_revm; then
38 ./pxe-server arch &
39 sleep 2
40 # via osinfo-query os. guessing arch is closest to latest fedora.
41 variant=fedora22
42 else
43 ./pxe-server fai &
44 sleep 2
45 if $redeploy; then
46 ./fai-redep
47 fi
48 variant=debian8
49 fi
50
51 name=demohost
52
53 s virshrm $name ||:
54
55
56 disk_arg=()
57 for ((i=1; i <= disk_count; i++)); do
58 f=/var/lib/libvirt/images/${name}$i
59 disk_arg+=("--disk path=$f")
60 if $new_disk || [[ ! -e $f ]]; then
61 s rm -f $f
62 s qemu-img create -o preallocation=metadata -f qcow2 $f 20G
63 fi
64 done
65
66 if [[ $SSH_CLIENT ]]; then
67 console_arg=--noautoconsole
68 fi
69
70 # --cpu host: this causes mkfs.btrfs to fail with a stack trace which began
71 # something like:
72 # init_module+0x108/0x1000 [raid6_pq]
73 #
74 # uniq is to stop gtk-warning spam
75 s virt-install --os-variant $variant -n $name --pxe -r 2048 --vcpus 1 \
76 ${disk_arg[*]} -w bridge=br0,mac=52:54:00:9c:ef:ad \
77 --graphics spice,listen=0.0.0.0 $console_arg |& grep -v '^$' | uniq &
78
79 if [[ $SSH_CLIENT ]]; then
80 fg
81 fi
82
83
84 if is_arch_revm; then
85 while ! timeout 10 ssh $name /bin/true; do sleep 1; done
86 ./arch-init-remote $name
87 fi