#!/bin/bash

echo -e ''
echo -e "\033[32m============ ddns-go for OPNsense一键安装脚本 ==============\033[0m"
echo -e ''

# 定义颜色变量
GREEN="\033[32m"
YELLOW="\033[33m"
RED="\033[31m"
CYAN="\033[36m"
RESET="\033[0m"

# 定义目录变量
ROOT="/usr/local"
BIN="$ROOT/bin"
WWW="$ROOT/www"
MENU="$ROOT/opnsense/mvc/app/models/OPNsense"
START="$ROOT/etc/rc.syshook.d/start"

# 定义日志函数
log() {
    local color="$1"
    local message="$2"
    echo -e "${color}${message}${RESET}"
}

# 复制文件
log "$YELLOW" "复制文件..."
log "$YELLOW" "生成菜单..."
log "$YELLOW" "添加开机脚本..."
cp -f bin/* "$BIN/" || log "$RED" "bin 文件复制失败！"
cp -f www/* "$WWW/" || log "$RED" "www 文件复制失败！"
cp -R menu/* "$MENU/" || log "$RED" "menu 文件复制失败！"
cp -R start/* "$START/" || log "$RED" "start 文件复制失败！"

# 设置执行权限
log "$YELLOW" "添加文件执行权限..."
    chmod +x $BIN/ddns-go
    chmod +x $START/94-ddnsgo
echo ""

# 完成提示
log "$YELLOW" "安装完成..."
log "$GREEN" "请重启OPNsense防火墙，然后进入Web界面，导航到服务 > DDNG-GO菜单进行操作。"
echo ""