zulip/tools/test-install/destroy-all
Anders Kaseorg 392175d6e8 Use #!/usr/bin/env for bash shebangs.
/bin/sh and /usr/bin/env are the only two binaries that NixOS provides
at a fixed path (outside a buildFHSUserEnv sandbox).

This discussion was split from #11004.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2018-12-17 17:21:08 -08:00

37 lines
637 B
Bash
Executable File

#!/usr/bin/env bash
set -e
usage() {
echo "usage: destroy-all -f" >&2
exit 1
}
args="$(getopt -o +f --long help,force -- "$@")"
eval "set -- $args"
while true; do
case "$1" in
--help) usage;;
-f|--force) FORCE=1; shift;;
--) shift; break;;
*) usage;;
esac
done
if [ -z "$FORCE" ] || [ "$#" -gt 0 ]; then
usage
fi
if [ "$EUID" -ne 0 ]; then
echo "error: this script must be run as root" >&2
exit 1
fi
lxc-ls -f \
| perl -lane '$_ = $F[0]; print if (/^zulip-install-/ && !/-base$/)' \
| while read -r c
do
echo "$c"
lxc-stop -n "$c"
lxc-destroy -n "$c"
done