added shell script tooling
This commit is contained in:
parent
25066b3efc
commit
510c65cd1f
|
@ -0,0 +1,18 @@
|
||||||
|
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 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.
|
||||||
|
#
|
||||||
|
grep "email=" vms/vm*.txt | awk -F'=' '{print $2}' | sed 's/"//g' | tr '\n' ',' ; echo
|
|
@ -0,0 +1,104 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 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.
|
||||||
|
#
|
||||||
|
main () {
|
||||||
|
CONF_FILE="$PWD/_deploy.conf"
|
||||||
|
[ -f "$CONF_FILE" ] && . "$CONF_FILE"
|
||||||
|
|
||||||
|
file=${VMS}/$1
|
||||||
|
|
||||||
|
if [ -f "$file" ]; then
|
||||||
|
echo "reading $file"
|
||||||
|
. "$file"
|
||||||
|
backup_image "$file"
|
||||||
|
remove_user "$file"
|
||||||
|
move_file "$file"
|
||||||
|
else
|
||||||
|
echo "ERROR file doesn't exist: ${file}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_instance() {
|
||||||
|
# Check if the instance name exists, otherwise return filename as VM.
|
||||||
|
# Takes vm*.txt and instance
|
||||||
|
# prints either filename or instance variable
|
||||||
|
if test -z "$2"
|
||||||
|
then echo "$1" | sed "s@^$VMS@@;s@^/@@;s/\\.txt$//"
|
||||||
|
else echo "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_owner() {
|
||||||
|
# Check if the owner name exists, otherwise returns username.
|
||||||
|
# Takes username and owner
|
||||||
|
# prints either owner or username
|
||||||
|
if test -z "$2"
|
||||||
|
then echo "$1"
|
||||||
|
else echo "$2"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
check_format() {
|
||||||
|
# Check if the image format exists, otherwise returns img.
|
||||||
|
# Takes format
|
||||||
|
# prints either format or img
|
||||||
|
if test -z "$1"
|
||||||
|
then echo "${FORMAT}"
|
||||||
|
else echo "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
backup_image() {
|
||||||
|
filename=$1
|
||||||
|
_instance=$(check_instance "$filename" "$instance")
|
||||||
|
_format=$(check_format "$format")
|
||||||
|
if [ -f "${IMAGES}/${_instance}.${_format}" ]; then
|
||||||
|
mv ${IMAGES}/${_instance}.${_format} ${IMAGES}/${_instance}.${_format}-backup
|
||||||
|
echo "vmm(4)/vmd(8) files moved: ${IMAGES}/${_instance}.${_format} ${IMAGES}/${_instance}.${_format}-backup"
|
||||||
|
else
|
||||||
|
echo "ERROR vmm(4)/vmd(8) files moved: ${IMAGES}/${_instance}.${_format} doesn't exist"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_user() {
|
||||||
|
_owner=$(check_owner "$username" "$owner")
|
||||||
|
if [ -n "$_owner" ]; then
|
||||||
|
if grep -e "^${_owner}:" /etc/passwd > /dev/null; then
|
||||||
|
userdel -r "$_owner"
|
||||||
|
echo "userdel(8) removal: $_owner"
|
||||||
|
else
|
||||||
|
echo "ERROR userdel(8) removal: $_owner doesn't exist"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if grep -e "^${_owner}:" /etc/group > /dev/null; then
|
||||||
|
groupdel "$_owner"
|
||||||
|
echo "groupdel(8) removal: $_owner"
|
||||||
|
else
|
||||||
|
echo "ERROR groupdel(8) removal: $_owner doesn't exist"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
move_file() {
|
||||||
|
filename=$1
|
||||||
|
cp ${filename} ${filename}-backup
|
||||||
|
echo "cp(1): ${filename} ${filename}-backup"
|
||||||
|
mv ${filename} ${filename}.free
|
||||||
|
echo "mv(1): ${filename} ${filename}.free"
|
||||||
|
chown -R mischa:mischa ${filename}-backup ${filename}.free
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
|
@ -0,0 +1,37 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 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.
|
||||||
|
#
|
||||||
|
DEV="${HOME}/openbsd.amsterdam/deploy.pl"
|
||||||
|
PROD="${HOME}"
|
||||||
|
RELAY="mx"
|
||||||
|
|
||||||
|
if [ -d ${DEV} ]; then
|
||||||
|
. ${DEV}/_deploy.conf
|
||||||
|
elif [ -d ${PROD} ]; then
|
||||||
|
. ${PROD}/_deploy.conf
|
||||||
|
else
|
||||||
|
echo "Unable to find config file."
|
||||||
|
exit 1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
FILE="${TMPL}/email-renewal.txt"
|
||||||
|
[ ! -f ${FILE} ] && exit 1
|
||||||
|
|
||||||
|
LINES=$(wc -l ${FILE} | awk '{printf $1}')
|
||||||
|
[ ${LINES} == 2 ] && rm ${FILE} && exit 1
|
||||||
|
|
||||||
|
cat ${FILE} | while read; do sleep 0.2; echo ${REPLY}; done | nc ${RELAY} 25
|
||||||
|
mv ${FILE} ${FILE}-$(date +%Y%m%d)
|
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 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.
|
||||||
|
#
|
||||||
|
vmctl show | for i in $(awk '/ - / {print $9}'); do echo ${i}; doas vmctl start $i; sleep 90; done
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#
|
||||||
|
# Copyright (c) 2019 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.
|
||||||
|
#
|
||||||
|
TOTAL=$(vmctl show | grep -vc ID)
|
||||||
|
RUNNING=$(vmctl show | egrep -vc 'ID|- ')
|
||||||
|
uname -a
|
||||||
|
date
|
||||||
|
w
|
||||||
|
printf "VMs Running: %s of %s\n" "${RUNNING}" "${TOTAL}"
|
||||||
|
|
Loading…
Reference in New Issue