post_install() {
    :
#!/bin/bash

if type update-alternatives 2>/dev/null >&1; then
    # Remove previous link if it doesn't use update-alternatives
    if [ -L '/usr/bin/irisclient' -a -e '/usr/bin/irisclient' -a "`readlink '/usr/bin/irisclient'`" != '/etc/alternatives/irisclient' ]; then
        rm -f '/usr/bin/irisclient'
    fi
    update-alternatives --install '/usr/bin/irisclient' 'irisclient' '/opt/IrisClient/irisclient' 100 || ln -sf '/opt/IrisClient/irisclient' '/usr/bin/irisclient'
else
    ln -sf '/opt/IrisClient/irisclient' '/usr/bin/irisclient'
fi

# SUID chrome-sandbox for Electron 5+
chmod 4755 '/opt/IrisClient/chrome-sandbox' || true

if hash update-mime-database 2>/dev/null; then
    update-mime-database /usr/share/mime || true
fi

if hash update-desktop-database 2>/dev/null; then
    update-desktop-database /usr/share/applications || true
fi

}
post_remove() {
    :
#!/bin/bash

# CloudVPN 卸载后清理脚本
# 停止、禁用并移除 cloudvpn.helper.service 服务

set -e

SERVICE_NAME="cloudvpn.helper"
SERVICE_FILE="/etc/systemd/system/cloudvpn.helper.service"

echo "开始清理 CloudVPN Helper 服务..."

# 检查是否以 root 权限运行
if [ "$EUID" -ne 0 ]; then
    echo "错误: 此脚本需要 root 权限运行"
    exit 1
fi

# 停止服务
echo "正在停止 $SERVICE_NAME 服务..."
if systemctl is-active --quiet "$SERVICE_NAME"; then
    systemctl stop "$SERVICE_NAME"
    echo "服务已停止"
else
    echo "服务未运行，跳过停止操作"
fi

# 禁用服务
echo "正在禁用 $SERVICE_NAME 服务..."
if systemctl is-enabled --quiet "$SERVICE_NAME" 2>/dev/null; then
    systemctl disable "$SERVICE_NAME"
    echo "服务已禁用"
else
    echo "服务未启用，跳过禁用操作"
fi

# 移除服务文件
echo "正在移除服务文件..."
if [ -f "$SERVICE_FILE" ]; then
    rm -f "$SERVICE_FILE"
    echo "服务文件已移除: $SERVICE_FILE"
else
    echo "服务文件不存在，跳过移除操作"
fi

# 重新加载 systemd 配置
echo "正在重新加载 systemd 配置..."
systemctl daemon-reload

echo "CloudVPN Helper 服务清理完成"
}
