#!/bin/bash    
local env=$1
local zip_file="quectel-CM-binary-RK3568.zip"
local bin_file="quectel-CM"
local service_file="quectel-autodial.service"
local extract_dir="${zip_file%.zip}"

echo "4G驱动程序初始化.... "
if [ ! -d "$env" ]; then
    echo "错误: 指定的环境目录 '$env' 不存在。"
    return 1
fi

local zip_path="${env}/${zip_file}"
if [ ! -f "$zip_path" ]; then
    echo "错误: ZIP文件 '$zip_path' 不存在。"
    return 1
fi

local extract_path="${env}/${extract_dir}"
if [ ! -d "$extract_path" ]; then
    echo "解压缩4G配置文件..."
    unzip "$zip_path" -d "$env"
fi

local bin_path="${extract_path}/${bin_file}"
if [ ! -f "$bin_path" ]; then
    echo "错误:二进制文件 '$bin_path' 不存在。"
    return 1
fi

local service_path="${extract_path}/${service_file}"
if [ ! -f "$service_path" ]; then
    echo "错误:service 文件 '$service_path' 不存在。"
    return 1
fi

chmod +x "$bin_path"
sudo cp "$bin_path" /usr/sbin/
sudo cp "$service_path" /lib/systemd/system/
# sudo systemctl enable "$service_file"
# sudo systemctl start "$service_file"
rm -rf "$extract_path"
echo "设置完成."