Files
license.build.wfc/opt/lic/bin/generatelic.sh
2025-04-18 03:57:20 +00:00

116 lines
3.1 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
# 默认值(可选)
TIME=""
declare -a IPS=() # 声明为数组
declare -a MACS=() # 声明为数组
CPU=""
MB=""
IP=""
MAC=""
CODE=""
# 解析命令行参数
while [[ $# -gt 0 ]]; do
case "$1" in
-t|--t)
TIME="$2"
shift 2 # 移除选项和参数值
;;
-ip|--ip)
shift # 先移除 "-ip" 自身
# 收集所有后续非选项参数(直到遇到下一个以 "-" 开头的参数)
while [[ $# -gt 0 ]] && [[ ! "$1" =~ ^- ]]; do
IPS+=("$1")
shift
done
# 检查是否至少有一个名字
if [[ ${#IPS[@]} -eq 0 ]]; then
echo "错误:-ip 参数需要至少一个名字"
exit 1
fi
;;
-mac|--mac)
shift # 先移除 "-mac" 自身
# 收集所有后续非选项参数(直到遇到下一个以 "-" 开头的参数)
while [[ $# -gt 0 ]] && [[ ! "$1" =~ ^- ]]; do
MACS+=("$1")
shift
done
# 检查是否至少有一个名字
if [[ ${#MACS[@]} -eq 0 ]]; then
echo "错误:-mac 参数需要至少一个名字"
exit 1
fi
;;
-cpu|--cpu)
CPU="$2"
shift 2
;;
-code|--code)
CODE="$2"
shift 2
;;
-mb|--mb)
MB="$2"
shift 2
;;
*) # 未知选项
echo "错误:未知选项 $1"
exit 1
;;
esac
done
# 检查必需参数
if [[ -z "$TIME" ]]; then
echo "错误:缺少 -t 参数"
exit 1
fi
# 输出结果(或执行其他操作)
echo "失效时间: $TIME"
echo "ip地址: ${IPS[*]}"
echo "mac地址: ${MACS[*]}"
echo "cpu序列号: $CPU"
echo "ip序列号: $MB"
IP=$(printf "%s\",\"" "${IPS[@]}")
IP=${IP%\",\"}
if [ ! -z "$IP" ]; then
IP=\"$IP\"
fi
MAC=$(printf "%s\",\"" "${MACS[@]}")
MAC=${MAC%\",\"}
if [ ! -z "$MAC" ]; then
MAC=\"$MAC\"
fi
RAW='{
"expiryTime": "'$TIME'",
"ipAddress": ['$IP'],
"macAddress": ['$MAC'],
"cpuSerial": "'$CPU'",
"activationCode": "'$CODE'",
"mainBoardSerial": "'$MB'"
}'
res=$(curl --location --request GET 'http://localhost:8070/license/generateLicense' \
--header 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VyX2tleSI6IjE3NTE3MTBkLWI5YzItNGRjYy1iZGUwLTNlMTEyYjY2OGYzZCIsInBsYXRmb3JtIjoic3lzdGVtIiwidXNlcm5hbWUiOiJhZG1pbiJ9.NG7WLME_mH6nPhfAwwqHD3kzdlZi6Zn1B4t5BG_IMWRh9ClsoM0dqRH9agq7FKL4fn68cahbJS7EpFwCXNgOWA' \
--header 'User-Agent: Apifox/1.0.0 (https://apifox.com)' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Host: 192.168.2.249:8070' \
--header 'Connection: keep-alive' \
--data-raw "$RAW")
echo $res
isok=$(echo $res | grep "result\":\"ok")
#echo "$RAW"
echo "------------------------"
if [ -z "$isok" ]; then
echo "生成license证书失败"
else
echo "生成license证书成功license.lic文件在/opt/lic/docker/license目录下"
fi