112 lines
2.9 KiB
Bash
Executable File
112 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
stop_containers() {
|
|
local containers=$(sudo docker ps -q --filter='name=callabacloud-*')
|
|
|
|
if [[ -n "$containers" ]]; then
|
|
if sudo docker stop --time 60 $containers; then
|
|
echo "Containers stopped successfully"
|
|
else
|
|
echo "Error: Unable to stop containers" >&2
|
|
return 1
|
|
fi
|
|
else
|
|
echo "No containers to stop"
|
|
fi
|
|
}
|
|
|
|
remove_containers() {
|
|
local containers=$(sudo docker ps -a -q --filter='name=callabacloud-*')
|
|
|
|
if [[ -n "$containers" ]]; then
|
|
if sudo docker rm $containers; then
|
|
echo "Containers removed successfully"
|
|
else
|
|
echo "Error: Unable to remove containers" >&2
|
|
return 1
|
|
fi
|
|
else
|
|
echo "No containers to remove"
|
|
fi
|
|
}
|
|
|
|
remove_images() {
|
|
OLD_STACK_VERSION=$(cat STACK_VERSION.txt)
|
|
local images=$(sudo docker images -q --filter=reference="registry.callabacloud.com/*/*:$OLD_STACK_VERSION")
|
|
|
|
if [[ -n "$images" ]]; then
|
|
if sudo docker rmi -f $images; then
|
|
echo "Images removed successfully"
|
|
else
|
|
echo "Error: Unable to remove images" >&2
|
|
return 1
|
|
fi
|
|
else
|
|
echo "No images to remove"
|
|
fi
|
|
}
|
|
|
|
remove_volumes() {
|
|
local volumes=$(sudo docker volume list -q --filter='name=callabacloud-*')
|
|
|
|
if [[ -n "$volumes" ]]; then
|
|
if sudo docker volume rm $volumes; then
|
|
echo "Volumes removed successfully"
|
|
else
|
|
echo "Error: Unable to remove volumes" >&2
|
|
return 1
|
|
fi
|
|
else
|
|
echo "No volumes to remove"
|
|
fi
|
|
}
|
|
|
|
prune_network() {
|
|
if sudo docker network prune -f; then
|
|
echo "Network pruned successfully"
|
|
else
|
|
echo "Error: Unable to prune network" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
delete_rules() {
|
|
local ports=(3000 3021 3031 27017, 27019, 6379)
|
|
sudo chmod 600 /etc/iptables/rules.v4
|
|
for port in ${ports[@]}; do
|
|
if sudo iptables -D INPUT -p tcp --dport $port -j DROP; then
|
|
echo "Rule for port $port deleted successfully"
|
|
else
|
|
echo "Error: Unable to delete rule for port $port" >&2
|
|
fi
|
|
done
|
|
|
|
if sudo iptables-legacy-save >/etc/iptables/rules.v4 ; then
|
|
echo "Iptables rules saved successfully"
|
|
else
|
|
echo "Error: Unable to save iptables rules" >&2
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
echo "Uninstalling... It may take some time."
|
|
|
|
main() {
|
|
echo "Are you sure you want to remove Callaba $STACK_VERSION ? (y/yes to confirm)"
|
|
read -r confirmation
|
|
if [[ "$confirmation" == "y" || "$confirmation" == "yes" ]]; then
|
|
echo "Uninstalling... It may take some time."
|
|
rm -f STACK_VERSION.txt
|
|
stop_containers
|
|
remove_containers
|
|
remove_images
|
|
remove_volumes
|
|
prune_network
|
|
delete_rules
|
|
else
|
|
echo "Operation cancelled."
|
|
fi
|
|
}
|
|
|
|
main
|