2016-08-13 01:08:44 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
# Détruit les conteneurs lxc de demo.
|
|
|
|
# Permet de repartir sur des bases saines avec le script demo_lxc_build.sh
|
|
|
|
|
|
|
|
# Récupère le dossier du script
|
2016-09-18 19:23:54 +02:00
|
|
|
if [ "${0:0:1}" == "/" ]; then script_dir="$(dirname "$0")"; else script_dir="$(echo $PWD/$(dirname "$0" | cut -d '.' -f2) | sed 's@/$@@')"; fi
|
2016-08-13 01:08:44 +02:00
|
|
|
|
2016-08-13 19:31:36 +02:00
|
|
|
LXC_NAME1=$(cat "$script_dir/demo_lxc_build.sh" | grep LXC_NAME1= | cut -d '=' -f2)
|
|
|
|
LXC_NAME2=$(cat "$script_dir/demo_lxc_build.sh" | grep LXC_NAME2= | cut -d '=' -f2)
|
|
|
|
IP_LXC1=$(cat "$script_dir/demo_lxc_build.sh" | grep IP_LXC1= | cut -d '=' -f2)
|
|
|
|
IP_LXC2=$(cat "$script_dir/demo_lxc_build.sh" | grep IP_LXC2= | cut -d '=' -f2)
|
2016-08-13 01:08:44 +02:00
|
|
|
|
2016-09-18 19:23:54 +02:00
|
|
|
# Check user
|
|
|
|
if [ "$USER" != "$(cat "$script_dir/setup_user")" ]; then
|
2022-08-30 19:53:21 +02:00
|
|
|
echo -e "\e[91mCe script doit être exécuté avec l'utilisateur $(cat "$script_dir/setup_user")"
|
2016-09-18 19:23:54 +02:00
|
|
|
echo -en "\e[0m"
|
|
|
|
exit 0
|
|
|
|
fi
|
2016-08-16 15:36:12 +02:00
|
|
|
|
2016-08-13 01:08:44 +02:00
|
|
|
"$script_dir/demo_stop.sh"
|
|
|
|
|
2016-12-17 19:31:44 +01:00
|
|
|
echo -e "\e[1m> Suppression des conteneurs et de leur snapshots\e[0m"
|
2016-08-13 01:08:44 +02:00
|
|
|
sudo lxc-snapshot -n $LXC_NAME1 -d snap0
|
|
|
|
sudo rm -f /var/lib/lxcsnaps/$LXC_NAME1/snap0.tar.gz
|
|
|
|
sudo lxc-destroy -n $LXC_NAME1 -f
|
|
|
|
sudo lxc-snapshot -n $LXC_NAME2 -d snap0
|
|
|
|
sudo rm -f /var/lib/lxcsnaps/$LXC_NAME2/snap0.tar.gz
|
|
|
|
sudo lxc-destroy -n $LXC_NAME2 -f
|
|
|
|
|
2016-12-17 19:31:44 +01:00
|
|
|
echo -e "\e[1m> Suppression des crons\e[0m"
|
2016-08-13 01:08:44 +02:00
|
|
|
sudo rm /etc/cron.d/demo_switch
|
|
|
|
sudo rm /etc/cron.d/demo_upgrade
|
2016-08-13 19:31:36 +02:00
|
|
|
|
2016-12-17 19:31:44 +01:00
|
|
|
echo -e "\e[1m> Suppression des clés ECDSA dans known_hosts\e[0m"
|
2016-08-13 19:31:36 +02:00
|
|
|
ssh-keygen -f "$HOME/.ssh/known_hosts" -R $IP_LXC1
|
|
|
|
ssh-keygen -f "$HOME/.ssh/known_hosts" -R $IP_LXC2
|
2016-09-18 19:23:54 +02:00
|
|
|
|
2016-12-17 19:31:44 +01:00
|
|
|
echo -e "\e[1m> Suppression du service\e[0m"
|
2017-06-05 16:30:42 +02:00
|
|
|
sudo systemctl disable lxc_demo.service
|
2016-09-18 19:23:54 +02:00
|
|
|
sudo rm -f /etc/systemd/system/lxc_demo.service
|