remove expect from launch.sh, only shell with named pipes and redirects
This commit is contained in:
parent
d453444d88
commit
521cd37779
|
@ -31,6 +31,7 @@
|
||||||
# 2021/05/18 changed: restrict the install.conf files in /var/www
|
# 2021/05/18 changed: restrict the install.conf files in /var/www
|
||||||
# 2021/08/29 added: next-server to dhcpd.conf, reliable pull of install.conf
|
# 2021/08/29 added: next-server to dhcpd.conf, reliable pull of install.conf
|
||||||
# 2021/10/28 changed: autoinstall from dhcp to autoconf
|
# 2021/10/28 changed: autoinstall from dhcp to autoconf
|
||||||
|
# 2022/12/01 added: boot device net, move away from expect()
|
||||||
#
|
#
|
||||||
use 5.024;
|
use 5.024;
|
||||||
use strict;
|
use strict;
|
||||||
|
@ -119,6 +120,7 @@ sub render_vm_conf {
|
||||||
printf $fh_vm "\tdisable\n";
|
printf $fh_vm "\tdisable\n";
|
||||||
printf $fh_vm "\towner %s\n", $_owner;
|
printf $fh_vm "\towner %s\n", $_owner;
|
||||||
printf $fh_vm "\tmemory %s\n", $_memory if $_memory;
|
printf $fh_vm "\tmemory %s\n", $_memory if $_memory;
|
||||||
|
printf $fh_vm "\tboot device net\n" if (! -e $_disk);
|
||||||
printf $fh_vm "\tboot \"%s\"\n", $_boot if (! -e $_disk);
|
printf $fh_vm "\tboot \"%s\"\n", $_boot if (! -e $_disk);
|
||||||
printf $fh_vm "\tdisk \"%s\" format %s\n", $_disk, $_disk_format;
|
printf $fh_vm "\tdisk \"%s\" format %s\n", $_disk, $_disk_format;
|
||||||
printf $fh_vm "\tdisk \"%s\" format %s\n", $_disk2, $_disk_format if $_disk2;
|
printf $fh_vm "\tdisk \"%s\" format %s\n", $_disk2, $_disk_format if $_disk2;
|
||||||
|
|
87
launch.sh
87
launch.sh
|
@ -26,41 +26,8 @@ if [[ -z ${1} ]]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
if [[ ! -f "${VMS}/${1}.txt" ]]; then
|
if [[ ! -f "${VMS}/${1}.txt" ]]; then
|
||||||
echo "unable to find ${VMS}/${1}.txt"
|
echo "unable to find ${VMS}/${1}"
|
||||||
if [[ -f "${VMS}/${1}.txt.free" ]]; then
|
|
||||||
echo "found ${VMS}/${1}.txt.free"
|
|
||||||
mv ${VMS}/${1}.txt.free ${VMS}/${1}.txt
|
|
||||||
else
|
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
|
||||||
else
|
|
||||||
chown mischa ${VMS}/${1}.txt
|
|
||||||
chmod 600 ${VMS}/${1}.txt
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${SERVER}" == server* ]]; then
|
|
||||||
HOST="s${SERVER#server}"
|
|
||||||
elif [[ "${SERVER}" == mega* ]]; then
|
|
||||||
HOST="m${SERVER#mega}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
openrsync -va --del /home/mischa/vms/ mischa@wm1.obsda.ms:vms/${HOST}/
|
|
||||||
ssh wm1.obsda.ms "doas ./create-user.pl ${HOST}${1}"
|
|
||||||
openrsync -va --del /home/mischa/vms/ mischa@rx.high5.nl:vms/${HOST}/
|
|
||||||
|
|
||||||
deploy.pl
|
|
||||||
rcctl restart dhcpd
|
|
||||||
vmctl reload
|
|
||||||
sleep 10
|
|
||||||
|
|
||||||
auto-deploy.exp ${1}
|
|
||||||
if [ $? != 0 ]; then
|
|
||||||
vmctl stop -f ${1}
|
|
||||||
rm -rf /var/vmm/${1}.qcow2
|
|
||||||
pushover.pl -m "$(SERVER) ${1} failed deploy" -p 1
|
|
||||||
exit 1
|
|
||||||
else
|
|
||||||
vmctl stop -f ${1}
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
deploy.pl
|
deploy.pl
|
||||||
|
@ -68,10 +35,48 @@ rcctl restart dhcpd
|
||||||
vmctl reload
|
vmctl reload
|
||||||
sleep 10
|
sleep 10
|
||||||
|
|
||||||
auto-start.exp ${1}
|
mkfifo -m 600 /tmp/pipe_${1}
|
||||||
if [ $? ]; then
|
install -g mischa -m 600 -o mischa /dev/null /home/mischa/${1}.log
|
||||||
echo
|
|
||||||
echo "SUCCES! - deployed ${1}"
|
echo -n "autoinstall ${1}, log output /home/mischa/${1}.log... "
|
||||||
notify.pl deployed ${1}
|
|
||||||
pushover.pl -m "${SERVER} ${1} deployed" -t "OpenBSD Amsterdam"
|
vmctl start -c ${1} < /tmp/pipe_${1} | while read line; do
|
||||||
fi
|
printf '%s\n' "$line" >&2
|
||||||
|
case $line in
|
||||||
|
*rebooting...*)
|
||||||
|
vmctl stop -f ${1}
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
#Response file location\?*)
|
||||||
|
#vmctl stop -f ${1}
|
||||||
|
#rm -rf /var/vmm/${1}.qcow2
|
||||||
|
#pushover.pl -m "${SERVER} ${1} failed deploy" -p 1
|
||||||
|
#exit 1
|
||||||
|
#;;
|
||||||
|
esac
|
||||||
|
done > /tmp/pipe_${1} 2> /home/mischa/${1}.log
|
||||||
|
|
||||||
|
echo "completed"
|
||||||
|
|
||||||
|
deploy.pl
|
||||||
|
rcctl restart dhcpd
|
||||||
|
vmctl reload
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
echo "booting ${1}"
|
||||||
|
|
||||||
|
vmctl start -c ${1} < /tmp/pipe_${1} | while read line; do
|
||||||
|
printf '%s\n' "$line" >&2
|
||||||
|
case $line in
|
||||||
|
*tty00*)
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done > /tmp/pipe_${1} 2>> /home/mischa/${1}.log
|
||||||
|
|
||||||
|
rm -rf /tmp/pipe_${1}
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "SUCCES! - deployed ${1}"
|
||||||
|
notify.pl deployed ${1}
|
||||||
|
pushover.pl -m "${SERVER} ${1} deployed"
|
||||||
|
|
|
@ -0,0 +1,77 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019-2022 Mischa Peters <mischa @ openbsd.amsterdam>
|
||||||
|
#
|
||||||
|
# Permission to use, copy, modify, and distribute this software for any
|
||||||
|
# purpose with or without fee is hereby granted, provided that the above
|
||||||
|
# copyright notice and this permission notice appear in all copies.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||||
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||||
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||||
|
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||||
|
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||||
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
#
|
||||||
|
CONF_FILE="${PWD}/_deploy.conf"
|
||||||
|
if [[ -f "${CONF_FILE}" ]]; then
|
||||||
|
. "${CONF_FILE}"
|
||||||
|
else
|
||||||
|
echo "unable to find _deploy.conf"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ -z ${1} ]]; then
|
||||||
|
echo "usage: ${0##*/} vmXX"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if [[ ! -f "${VMS}/${1}.txt" ]]; then
|
||||||
|
echo "unable to find ${VMS}/${1}.txt"
|
||||||
|
if [[ -f "${VMS}/${1}.txt.free" ]]; then
|
||||||
|
echo "found ${VMS}/${1}.txt.free"
|
||||||
|
mv ${VMS}/${1}.txt.free ${VMS}/${1}.txt
|
||||||
|
else
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
chown mischa ${VMS}/${1}.txt
|
||||||
|
chmod 600 ${VMS}/${1}.txt
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ "${SERVER}" == server* ]]; then
|
||||||
|
HOST="s${SERVER#server}"
|
||||||
|
elif [[ "${SERVER}" == mega* ]]; then
|
||||||
|
HOST="m${SERVER#mega}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
openrsync -va --del /home/mischa/vms/ mischa@wm1.obsda.ms:vms/${HOST}/
|
||||||
|
ssh wm1.obsda.ms "doas ./create-user.pl ${HOST}${1}"
|
||||||
|
openrsync -va --del /home/mischa/vms/ mischa@rx.high5.nl:vms/${HOST}/
|
||||||
|
|
||||||
|
deploy.pl
|
||||||
|
rcctl restart dhcpd
|
||||||
|
vmctl reload
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
auto-deploy.exp ${1}
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
vmctl stop -f ${1}
|
||||||
|
rm -rf /var/vmm/${1}.qcow2
|
||||||
|
pushover.pl -m "$(SERVER) ${1} failed deploy" -p 1
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
vmctl stop -f ${1}
|
||||||
|
fi
|
||||||
|
|
||||||
|
deploy.pl
|
||||||
|
rcctl restart dhcpd
|
||||||
|
vmctl reload
|
||||||
|
sleep 10
|
||||||
|
|
||||||
|
auto-start.exp ${1}
|
||||||
|
if [ $? ]; then
|
||||||
|
echo
|
||||||
|
echo "SUCCES! - deployed ${1}"
|
||||||
|
notify.pl deployed ${1}
|
||||||
|
pushover.pl -m "${SERVER} ${1} deployed" -t "OpenBSD Amsterdam"
|
||||||
|
fi
|
Loading…
Reference in New Issue