Files
tms-bbt-config-pkg/tms-bbt-config/unzipKDMs.sh
2026-01-12 21:21:01 +08:00

86 lines
2.7 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
# 定义保存cookie的文件路径
COOKIE_FILE="/home/smart/cookie.txt"
# 1. 登录 SmartTMS_S3 系统
echo "正在登录 SmartTMS_S3 系统以获取会话..."
curl -s -X POST -d 'userName=admin&userPassword=admin' -c "$COOKIE_FILE" http://127.0.0.1:8080/SmartTMS_S3/LoginController/login.do >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "错误: 登录 SmartTMS_S3 失败。请检查服务是否运行或网络连接。"
rm -f "$COOKIE_FILE" # 清理可能不完整的cookie文件
sleep 60
exit 1
fi
echo "登录成功。"
# 2. 从 SettingManagementController 接口提取密钥编码 (code)
echo "正在获取编码..."
JSON_RESPONSE=$(curl -s -X POST -b "$COOKIE_FILE" 'http://127.0.0.1:8080/SmartTMS_S3/SettingManagementController/queryCinemaModel.do')
if [ $? -ne 0 ] || [ -z "$JSON_RESPONSE" ]; then
echo "错误: 无法获取系统配置信息或返回为空。检查tms是否启动"
rm -f "$COOKIE_FILE"
sleep 60
exit 1
fi
KEY_ENCODING=$(echo "$JSON_RESPONSE" | sed -n 's/.*"result":{[^}]*"code":"\([^"]*\)".*/\1/p')
if [ -z "$KEY_ENCODING" ]; then
echo "错误: 无法从接口响应中提取到有效的密钥编码。检查配置中是否填写影院编码"
rm -f "$COOKIE_FILE"
sleep 60
exit 1
fi
echo "已成功获取影院编码: $KEY_ENCODING"
# 开始解压操作
echo "开始解压密钥文件..."
# 定义需要扫描的目录
declare -a DIRS=("/home/smart/下载/" "/home/smart/Downloads/" "/media/kdm/" "/tmp/")
TARGET_DIR="/media/kdm/"
for dir in "${DIRS[@]}"; do
echo "正在处理目录: $dir 中的ZIP文件..."
find "$dir" -maxdepth 1 -name "${KEY_ENCODING}*.zip" -print0 | xargs -0 -r -n1 unzip -o -d "$TARGET_DIR"
if [ $? -ne 0 ]; then
echo "警告: 在 $dir 中解压文件时可能出现问题,或没有找到匹配的文件。"
fi
done
echo "解压操作完成。"
echo "删除密钥压缩包..."
# 使用之前获取的 KEY_ENCODING 变量来查找并删除压缩包
for dir in "${DIRS[@]}"; do
echo "正在删除 $dir 中的 ${KEY_ENCODING}*.zip 文件..."
find "$dir" -maxdepth 1 -name "${KEY_ENCODING}*.zip" -delete
done
# 确保 /media/kdm/ 下的也删除
echo "正在删除 /media/kdm/ 中的 ${KEY_ENCODING}*.zip 文件..."
find "$TARGET_DIR" -maxdepth 1 -name "${KEY_ENCODING}*.zip" -delete
echo "密钥压缩包删除完成。"
sleep 3
echo "刷新密钥..."
# 刷新KDM使用之前登录获取的cookie
curl -s http://127.0.0.1:8080/SmartTMS_S3/kdmController/updateKdm.do -X POST -b "$COOKIE_FILE" >/dev/null 2>&1
if [ $? -ne 0 ]; then
echo "错误: 刷新密钥失败。"
else
echo "刷新成功。"
fi
sleep 5
# 清理cookie文件
rm -f "$COOKIE_FILE"
echo "已清理临时cookie文件。"
echo "脚本执行完毕。"