From db347aeeb67bc92748af7a726485407729725498 Mon Sep 17 00:00:00 2001 From: MengMengCode <227010654+MengMengCode@users.noreply.github.com> Date: Fri, 5 Jun 2026 19:54:25 +0800 Subject: [PATCH] Add installer uninstall mode --- README.md | 12 +++++ install.sh | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 142 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 1ba7b9a..c0bd0d0 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,18 @@ Password: 随机 16 位密码 journalctl -u clicd --no-pager -n 80 | grep -E "Username:|Password:" ``` +卸载 CLICD: + +```bash +curl -fsSL https://raw.githubusercontent.com/MengMengCode/CLICD/main/install.sh | sudo sh -s -- uninstall +``` + +默认只删除 CLICD 服务和 `/usr/local/bin/clicd`,保留 `/root/.clicd` 配置数据和 `/var/lib/lxc` 容器。需要同时删除配置数据时: + +```bash +curl -fsSL https://raw.githubusercontent.com/MengMengCode/CLICD/main/install.sh | sudo sh -s -- uninstall --purge-data +``` + ![alt text](/img/image.png) ![alt text](/img/image-1.png) ![alt text](/img/image-2.png) diff --git a/install.sh b/install.sh index c4e658d..b599e99 100644 --- a/install.sh +++ b/install.sh @@ -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."