Files
QZMusic-Web/uninstall.sh

112 lines
2.5 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# QZMusic-Web 卸载脚本
# 完全删除所有QZMusic部署文件和配置
set -e
echo "=========================================="
echo " QZMusic-Web 卸载工具"
echo "=========================================="
echo ""
# 配置
INSTALL_DIR="/opt/QZMusic-Web"
PORT=10096
SERVICE_NAME="qzmusic-web"
# 颜色定义
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
log_info() {
echo -e "${GREEN}[INFO]${NC} $1"
}
log_warn() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
log_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# 确认卸载
echo "⚠️ 即将卸载 QZMusic-Web"
echo ""
read -p "确定要删除所有相关文件吗?(yes/no): " confirm
if [ "$confirm" != "yes" ]; then
log_info "取消卸载"
exit 0
fi
echo ""
# 停止服务
log_info "正在停止服务..."
# 停止开发服务器
PID=$(lsof -ti:$PORT 2>/dev/null || true)
if [ -n "$PID" ]; then
log_info "停止进程 (PID: $PID)..."
kill $PID 2>/dev/null || true
sleep 1
fi
# 停止Systemd服务如果存在
if systemctl is-active --quiet $SERVICE_NAME 2>/dev/null; then
log_info "停止 Systemd 服务..."
sudo systemctl stop $SERVICE_NAME
sudo systemctl disable $SERVICE_NAME
fi
# 删除Systemd服务文件
if [ -f "/etc/systemd/system/$SERVICE_NAME.service" ]; then
log_info "删除 Systemd 服务文件..."
sudo rm -f /etc/systemd/system/$SERVICE_NAME.service
sudo systemctl daemon-reload
fi
echo ""
# 删除安装目录
if [ -d "$INSTALL_DIR" ]; then
log_info "删除安装目录: $INSTALL_DIR"
sudo rm -rf "$INSTALL_DIR"
fi
# 删除npm全局链接如果有
if npm list -g --depth=0 2>/dev/null | grep -q "qzmusic-web"; then
log_info "删除 npm 全局包..."
sudo npm uninstall -g qzmusic-web 2>/dev/null || true
fi
# 删除相关缓存
log_info "清理缓存..."
# 删除npm缓存
if [ -d "$HOME/.npm/_cacache" ]; then
npm cache clean --force 2>/dev/null || true
fi
# 删除可能的临时文件
sudo rm -rf /tmp/QZMusic* 2>/dev/null || true
sudo rm -rf /var/tmp/QZMusic* 2>/dev/null || true
echo ""
echo "=========================================="
echo " ✅ 卸载完成!"
echo "=========================================="
echo ""
echo "已删除:"
echo " - 安装目录: $INSTALL_DIR"
echo " - 服务端口: $PORT"
echo " - 相关缓存"
echo ""
echo "如需重新安装,请运行:"
echo " bash <(curl -sL http://171.80.3.149:4321/miao-moe/QZMusic-Web/raw/branch/master/install.sh)"
echo ""