mirror of
https://github.com/MengMengCode/CLICD.git
synced 2026-08-06 05:52:19 +08:00
Add installer uninstall mode
This commit is contained in:
+130
-4
@@ -2,11 +2,12 @@
|
||||
set -eu
|
||||
|
||||
REPO="${CLICD_REPO:-MengMengCode/CLICD}"
|
||||
VERSION="${CLICD_VERSION:-latest}"
|
||||
CLICD_INSTALL_VERSION="${CLICD_VERSION:-latest}"
|
||||
ASSET="clicd-linux-amd64.tar.gz"
|
||||
ACTION="${1:-install}"
|
||||
|
||||
echo "====================================="
|
||||
echo " CLICD Installation"
|
||||
echo " CLICD Installer"
|
||||
echo "====================================="
|
||||
|
||||
log() {
|
||||
@@ -33,6 +34,7 @@ is_openrc() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "Please run as root: sudo ./install.sh"
|
||||
echo "Or: curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | sudo sh"
|
||||
echo "Uninstall: curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | sudo sh -s -- uninstall"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -44,6 +46,130 @@ if [ -r /etc/os-release ]; then
|
||||
OS_LIKE="${ID_LIKE:-}"
|
||||
fi
|
||||
|
||||
usage() {
|
||||
cat << EOF
|
||||
Usage:
|
||||
./install.sh
|
||||
./install.sh uninstall [--purge-data] [--delete-containers]
|
||||
|
||||
Environment:
|
||||
CLICD_REPO=owner/repo
|
||||
CLICD_VERSION=latest|v1.0.0
|
||||
|
||||
Examples:
|
||||
curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | sudo sh
|
||||
curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | sudo sh -s -- uninstall
|
||||
EOF
|
||||
}
|
||||
|
||||
remove_path() {
|
||||
path="$1"
|
||||
if [ ! -e "$path" ] && [ ! -L "$path" ]; then
|
||||
return
|
||||
fi
|
||||
rm -rf "$path"
|
||||
log "Removed $path"
|
||||
}
|
||||
|
||||
uninstall_clicd() {
|
||||
purge_data=0
|
||||
delete_containers=0
|
||||
|
||||
shift || true
|
||||
while [ "$#" -gt 0 ]; do
|
||||
case "$1" in
|
||||
--purge-data)
|
||||
purge_data=1
|
||||
;;
|
||||
--delete-containers)
|
||||
delete_containers=1
|
||||
;;
|
||||
-h|--help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
die "Unknown uninstall option: $1"
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
log "Uninstalling CLICD..."
|
||||
|
||||
if has_cmd systemctl; then
|
||||
systemctl stop clicd >/dev/null 2>&1 || true
|
||||
systemctl disable clicd >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
if has_cmd rc-service; then
|
||||
rc-service clicd stop >/dev/null 2>&1 || true
|
||||
fi
|
||||
if has_cmd rc-update; then
|
||||
rc-update del clicd default >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
if [ "$delete_containers" -eq 1 ]; then
|
||||
log "Destroying CLICD-style LXC containers named ct-*..."
|
||||
for container_dir in /var/lib/lxc/ct-*; do
|
||||
[ -d "$container_dir" ] || continue
|
||||
container_name="$(basename "$container_dir")"
|
||||
lxc-stop -n "$container_name" -k >/dev/null 2>&1 || true
|
||||
lxc-destroy -n "$container_name" -f >/dev/null 2>&1 || true
|
||||
remove_path "$container_dir"
|
||||
done
|
||||
fi
|
||||
|
||||
remove_path /etc/systemd/system/clicd.service
|
||||
remove_path /etc/init.d/clicd
|
||||
remove_path /usr/local/bin/clicd
|
||||
remove_path /etc/sysctl.d/99-clicd.conf
|
||||
remove_path /var/log/clicd.log
|
||||
remove_path /var/log/clicd.err
|
||||
|
||||
if [ "$purge_data" -eq 1 ]; then
|
||||
remove_path /root/.clicd
|
||||
fi
|
||||
|
||||
if has_cmd systemctl; then
|
||||
systemctl daemon-reload >/dev/null 2>&1 || true
|
||||
systemctl reset-failed clicd >/dev/null 2>&1 || true
|
||||
fi
|
||||
if has_cmd sysctl; then
|
||||
sysctl --system >/dev/null 2>&1 || true
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "====================================="
|
||||
echo " CLICD Uninstalled"
|
||||
echo "====================================="
|
||||
if [ "$purge_data" -eq 0 ]; then
|
||||
echo " Kept data: /root/.clicd"
|
||||
fi
|
||||
if [ "$delete_containers" -eq 0 ]; then
|
||||
echo " Kept LXC containers: /var/lib/lxc"
|
||||
echo " To delete CLICD-style ct-* containers too:"
|
||||
echo " ./install.sh uninstall --delete-containers"
|
||||
fi
|
||||
echo "====================================="
|
||||
}
|
||||
|
||||
case "$ACTION" in
|
||||
install|"")
|
||||
;;
|
||||
uninstall|remove)
|
||||
uninstall_clicd "$@"
|
||||
exit 0
|
||||
;;
|
||||
-h|--help|help)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
die "Unknown action: $ACTION"
|
||||
;;
|
||||
esac
|
||||
|
||||
install_apk() {
|
||||
log "Installing dependencies with apk..."
|
||||
apk update
|
||||
@@ -264,10 +390,10 @@ download_release_if_needed() {
|
||||
return
|
||||
fi
|
||||
|
||||
if [ "$VERSION" = "latest" ]; then
|
||||
if [ "$CLICD_INSTALL_VERSION" = "latest" ]; then
|
||||
download_url="https://github.com/${REPO}/releases/latest/download/${ASSET}"
|
||||
else
|
||||
download_url="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}"
|
||||
download_url="https://github.com/${REPO}/releases/download/${CLICD_INSTALL_VERSION}/${ASSET}"
|
||||
fi
|
||||
|
||||
log "clicd binary not found in current directory."
|
||||
|
||||
Reference in New Issue
Block a user