Blob


1 #!/bin/sh
2 #
3 # Copyright (c) 2019-2023 Mischa Peters <mischa @ openbsd.amsterdam>
4 #
5 # Permission to use, copy, modify, and distribute this software for any
6 # purpose with or without fee is hereby granted, provided that the above
7 # copyright notice and this permission notice appear in all copies.
8 #
9 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 #
17 CONF_FILE="${PWD}/_deploy.conf"
18 if [[ -f "${CONF_FILE}" ]]; then
19 . "${CONF_FILE}"
20 else
21 echo "unable to find _deploy.conf"
22 exit 1
23 fi
24 if [[ -z ${1} ]]; then
25 echo "usage: ${0##*/} vmXX"
26 exit 1
27 fi
28 if [[ ! -f "${VMS}/${1}.txt" ]]; then
29 echo "unable to find ${VMS}/${1}.txt"
30 if [[ -f "${VMS}/${1}.txt.free" ]]; then
31 echo "found ${VMS}/${1}.txt.free"
32 mv ${VMS}/${1}.txt.free ${VMS}/${1}.txt
33 else
34 exit 1
35 fi
36 else
37 chown mischa ${VMS}/${1}.txt
38 chmod 600 ${VMS}/${1}.txt
39 fi
41 INSTANCE=$(awk -F'=' '/instance/ {print $2}' ${VMS}/${1}.txt | tr -d '"')
42 if [[ -z ${INSTANCE} ]]; then
43 INSTANCE=${1}
44 fi
46 deploy.pl
47 sleep 5
48 if [[ -z ${DHCPD} ]]; then
49 rcctl restart dhcpd
50 fi
51 vmctl reload
52 sleep 5
54 mkfifo -m 600 /tmp/pipe_${1}
55 install -g mischa -m 600 -o mischa /dev/null ${LOGS}/${1}.log
57 echo -n "autoinstall(8) ${INSTANCE}, log output ${LOGS}/${1}.log... "
59 vmctl start -c ${INSTANCE} < /tmp/pipe_${1} | while read line; do
60 printf '%s\n' "$line" >&2
61 case $line in
62 *rebooting...*)
63 vmctl stop -f ${INSTANCE}
64 break
65 ;;
66 #Response file location\?*)
67 #vmctl stop -f ${1}
68 #rm -rf /tmp/pipe_${1}
69 #rm -rf /var/vmm/${1}.qcow2
70 #pushover.pl -m "${SERVER} ${1} failed deploy" -t "OpenBSD Amsterdam" -p 1
71 #exit 1
72 #;;
73 esac
74 done > /tmp/pipe_${1} 2> ${LOGS}/${1}.log
76 echo "completed"
78 deploy.pl
79 sleep 5
80 if [[ -z ${DHCPD} ]]; then
81 rcctl restart dhcpd
82 fi
83 vmctl reload
84 sleep 5
86 echo "booting ${INSTANCE}"
88 vmctl start -c ${INSTANCE} < /tmp/pipe_${1} | while read line; do
89 printf '%s\n' "$line" >&2
90 case $line in
91 *tty00*)
92 break
93 ;;
94 esac
95 done > /tmp/pipe_${1} 2>> ${LOGS}/${1}.log
97 rm -rf /tmp/pipe_${1}
99 echo
100 echo "SUCCES! - re-deployed ${INSTANCE}"
101 notify.pl redeployed ${1}
102 pushover.pl -m "${SERVER} ${INSTANCE} re-deployed" -t "OpenBSD Amsterdam"