2
0

feat:添加生成证书脚本

This commit is contained in:
caiyuchao
2025-04-16 10:27:22 +00:00
parent 05caf96086
commit 14d05ad903

View File

@@ -0,0 +1,103 @@
#!/bin/bash
# 默认值(可选)
TIME=""
declare -a IPS=() # 声明为数组
declare -a MACS=() # 声明为数组
CPU=""
MB=""
IP=""
MAC=""
# 解析命令行参数
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
;;
-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%\",\"}
MAC=$(printf "%s\",\"" "${MACS[@]}")
MAC=${MAC%\",\"}
RAW='{
"expiryTime": "'$TIME'",
"ipAddress": ["'$IP'"],
"macAddress": ["'$MAC'"],
"cpuSerial": "'$CPU'",
"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/wfc/docker/license-server/license目录下"
fi