forked from wukongdaily/img-installer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.sh
More file actions
71 lines (62 loc) · 1.65 KB
/
custom.sh
File metadata and controls
71 lines (62 loc) · 1.65 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
#!/bin/bash
set -euo pipefail
# 校验参数是否存在
if [ -z "$1" ]; then
echo "❌ 错误:未提供下载地址!"
exit 1
fi
mkdir -p imm
DOWNLOAD_URL="$1"
filename=$(basename "$DOWNLOAD_URL") # 从 URL 提取文件名
OUTPUT_PATH="imm/$filename"
echo "下载地址: $DOWNLOAD_URL"
echo "保存路径: $OUTPUT_PATH"
# 下载文件
if ! curl -k -L -o "$OUTPUT_PATH" "$DOWNLOAD_URL"; then
echo "❌ 下载失败!"
exit 1
fi
echo "✅ 下载成功!"
file "$OUTPUT_PATH"
# 根据扩展名解压
extension="${filename##*.}" # 获取文件扩展名
case $extension in
gz)
echo "gz正在解压$OUTPUT_PATH"
gunzip -f "$OUTPUT_PATH" || true
final_name=$(find imm -name '*.img' -print -quit)
mv "$final_name" "imm/custom.img"
;;
zip)
echo "zip正在解压$OUTPUT_PATH"
unzip -j -o "$OUTPUT_PATH" -d imm/ # -j 忽略目录结构
final_name=$(find imm -name '*.img' -print -quit)
mv "$final_name" "imm/custom.img"
;;
xz)
echo "xz正在解压$OUTPUT_PATH"
xz -d --keep "$OUTPUT_PATH" # 保留原文件
final_name="${OUTPUT_PATH%.*}"
mv "$final_name" "imm/custom.img"
;;
*)
echo "❌ 不支持的压缩格式: $extension"
exit 1
;;
esac
# 检查最终文件
if [ -f "imm/custom.img" ]; then
echo "✅ 解压成功"
ls -lh imm/
echo "✅ 准备合成 自定义OpenWrt 安装器"
else
echo "❌ 错误:最终文件 imm/custom.img 不存在"
exit 1
fi
mkdir -p output
docker run --privileged --rm \
-v $(pwd)/output:/output \
-v $(pwd)/supportFiles:/supportFiles:ro \
-v $(pwd)/imm/custom.img:/mnt/custom.img \
debian:buster \
/supportFiles/custom/build.sh