mirror of
https://github.com/MengMengCode/CLICD.git
synced 2026-08-08 14:34:49 +08:00
Add installer uninstall mode
This commit is contained in:
@@ -72,6 +72,18 @@ Password: 随机 16 位密码
|
|||||||
journalctl -u clicd --no-pager -n 80 | grep -E "Username:|Password:"
|
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
|
||||||
|
```
|
||||||
|
|
||||||

|

|
||||||

|

|
||||||

|

|
||||||
|
|||||||
+130
-4
@@ -2,11 +2,12 @@
|
|||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
REPO="${CLICD_REPO:-MengMengCode/CLICD}"
|
REPO="${CLICD_REPO:-MengMengCode/CLICD}"
|
||||||
VERSION="${CLICD_VERSION:-latest}"
|
CLICD_INSTALL_VERSION="${CLICD_VERSION:-latest}"
|
||||||
ASSET="clicd-linux-amd64.tar.gz"
|
ASSET="clicd-linux-amd64.tar.gz"
|
||||||
|
ACTION="${1:-install}"
|
||||||
|
|
||||||
echo "====================================="
|
echo "====================================="
|
||||||
echo " CLICD Installation"
|
echo " CLICD Installer"
|
||||||
echo "====================================="
|
echo "====================================="
|
||||||
|
|
||||||
log() {
|
log() {
|
||||||
@@ -33,6 +34,7 @@ is_openrc() {
|
|||||||
if [ "$(id -u)" -ne 0 ]; then
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
echo "Please run as root: sudo ./install.sh"
|
echo "Please run as root: sudo ./install.sh"
|
||||||
echo "Or: curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | sudo 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
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -44,6 +46,130 @@ if [ -r /etc/os-release ]; then
|
|||||||
OS_LIKE="${ID_LIKE:-}"
|
OS_LIKE="${ID_LIKE:-}"
|
||||||
fi
|
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() {
|
install_apk() {
|
||||||
log "Installing dependencies with apk..."
|
log "Installing dependencies with apk..."
|
||||||
apk update
|
apk update
|
||||||
@@ -264,10 +390,10 @@ download_release_if_needed() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$VERSION" = "latest" ]; then
|
if [ "$CLICD_INSTALL_VERSION" = "latest" ]; then
|
||||||
download_url="https://github.com/${REPO}/releases/latest/download/${ASSET}"
|
download_url="https://github.com/${REPO}/releases/latest/download/${ASSET}"
|
||||||
else
|
else
|
||||||
download_url="https://github.com/${REPO}/releases/download/${VERSION}/${ASSET}"
|
download_url="https://github.com/${REPO}/releases/download/${CLICD_INSTALL_VERSION}/${ASSET}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log "clicd binary not found in current directory."
|
log "clicd binary not found in current directory."
|
||||||
|
|||||||
Reference in New Issue
Block a user