Repository navigation
Expand file tree
/
Copy pathzip.sh
More file actions
83 lines (73 loc) · 2.42 KB
/
Copy pathzip.sh
File metadata and controls
83 lines (73 loc) · 2.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# =========================================================
# COS 解压环境检测脚本
# 作者: ChatGPT for hong lin
# 功能:
# ✅ 自动检测 7z / unzip / unrar 是否可用
# ✅ 自动生成测试压缩包并验证解压功能
# ✅ 彩色输出结果 ✅ / ❌
# =========================================================
RED="\e[31m"
GREEN="\e[32m"
YELLOW="\e[33m"
RESET="\e[0m"
WORKDIR="/root/scan/test_env"
mkdir -p "$WORKDIR"
cd "$WORKDIR" || exit 1
echo -e "${YELLOW}🚀 开始检测 COS 解压环境...${RESET}"
echo "工作目录: $WORKDIR"
echo "--------------------------------------------"
# Step 1: 创建测试文件
echo "hello world" > hello.txt
# Step 2: 检查 7z
echo -e "${YELLOW}🧩 检查 7z...${RESET}"
if command -v 7z >/dev/null 2>&1; then
7z a test.7z hello.txt >/dev/null 2>&1
rm -rf 7z_out && mkdir -p 7z_out
7z x test.7z -o7z_out -y >/dev/null 2>&1
if [ -f 7z_out/hello.txt ]; then
echo -e "✅ ${GREEN}7z 正常工作${RESET}"
else
echo -e "❌ ${RED}7z 解压失败${RESET}"
fi
else
echo -e "❌ ${RED}7z 未安装${RESET}"
fi
# Step 3: 检查 unzip
echo -e "${YELLOW}🧩 检查 unzip...${RESET}"
if command -v unzip >/dev/null 2>&1; then
zip -q test.zip hello.txt
rm -rf zip_out && mkdir -p zip_out
unzip -o test.zip -d zip_out >/dev/null 2>&1
if [ -f zip_out/hello.txt ]; then
echo -e "✅ ${GREEN}unzip 正常工作${RESET}"
else
echo -e "❌ ${RED}unzip 解压失败${RESET}"
fi
else
echo -e "❌ ${RED}unzip 未安装${RESET}"
fi
# Step 4: 检查 unrar
echo -e "${YELLOW}🧩 检查 unrar...${RESET}"
if command -v unrar >/dev/null 2>&1; then
rm -f test.rar
rar a -idq test.rar hello.txt >/dev/null 2>&1
rm -rf rar_out && mkdir -p rar_out
unrar x -y test.rar rar_out >/dev/null 2>&1
if [ -f rar_out/hello.txt ]; then
echo -e "✅ ${GREEN}unrar 正常工作${RESET}"
else
echo -e "❌ ${RED}unrar 解压失败${RESET}"
fi
else
echo -e "❌ ${RED}unrar 未安装${RESET}"
fi
echo "--------------------------------------------"
# Step 5: 总结结果
if [ -f 7z_out/hello.txt ] && [ -f zip_out/hello.txt ] && [ -f rar_out/hello.txt ]; then
echo -e "🎉 ${GREEN}所有解压引擎工作正常,COS 解压系统可以安全运行!${RESET}"
else
echo -e "⚠️ ${YELLOW}部分引擎工作异常,请检查上方输出。${RESET}"
fi
echo "--------------------------------------------"
echo -e "${YELLOW}检测完成!${RESET}"