Spotter-VM/build/clean-all.sh

59 lines
1.4 KiB
Bash
Executable File

#!/bin/sh
set -ev
# Clean documentation
rm -rf /srv/build/doc/*
# Clean basic tar
rm -f /srv/build/vm.tar
# Clean native apps
rm -rf /srv/build/alpine/*
# Clean built LXC packages
rm -rf /srv/build/lxc/apps/*
rm -rf /srv/build/lxc/images/*
rm -f /srv/build/lxc/packages.sig
echo '{"apps":{},"images":{}}' >/srv/build/lxc/packages
# Stop running containers
for SERVICE in $(find /run/openrc/started -name 'lxc-*'); do
service $(basename ${SERVICE}) stop
done
# Remove services
rm -f /etc/init.d/lxc-*
rc-update -u
# Remove containers
rm -rf /var/lib/lxc/*
# Remove application data
for DIR in $(find /srv ! -path /srv/build -maxdepth 1 -mindepth 1); do
rm -rf ${DIR}
done
# Remove nginx configs
for CONF in $(find /etc/nginx/conf.d -name '*.conf' -a ! -name apkrepo.conf -a ! -name default.conf); do
rm -f ${CONF}
done
service nginx reload
# Reset /etc/hosts
cat <<EOF >/etc/hosts
127.0.0.1 localhost
::1 localhost
172.17.0.1 host
172.17.0.1 repo.spotter.cz
EOF
# Reset vmmgr config
export ADMINPWD=$(python3 -c "import json; f = open('/etc/vmmgr/config.json'); j = json.load(f); print(j['host']['adminpwd'])")
envsubst </etc/vmmgr/config.default.json >/etc/vmmgr/config.json
# Clean locally installed LXC packages
rm -rf /var/lib/lxcmgr/storage/*
rm -rf /var/lib/lxcmgr/cache/apps/*
rm -rf /var/lib/lxcmgr/cache/images/*
echo '{"apps":{},"images":{}}' >/var/lib/lxcmgr/packages