forked from xiaoxindada/SGSI-build-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
img2sdat.sh
executable file
·101 lines (86 loc) · 2.06 KB
/
img2sdat.sh
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
# Copyright (C) 2020 Xiaoxindada <[email protected]>
LOCALDIR=`cd "$( dirname ${BASH_SOURCE[0]} )" && pwd`
cd $LOCALDIR
source ./bin.sh
function Usage() {
cat <<EOT
Usage:
$0 <Image Path> [Other args]
Image Path: Image Path
Other args:
[--make_br]: Make new.dat.br
EOT
}
case $1 in
"-h"|"--help")
Usage
exit
;;
esac
if [ "$1" = "" ];then
Usage
exit
fi
image="$1"
image_name=$(echo ${image##*/} | sed 's/\.img//')
make_br="false"
[ ! -e $image ] && echo "$image 不存在!" && exit
function img2simg() {
rimg_file="$image"
simg_file=$(echo "${image%%.*}" | sed 's/$/&s\.img/')
echo "正在转换simg..."
$bin/img2simg "$rimg_file" "$simg_file"
if [ $? != "0" ];then
echo "转换失败"
else
echo "转换成功"
mv -f $simg_file $bin/img2sdat/${image_name}.img
fi
}
function simg2sdat() {
if [ ! -f $bin/img2sdat/${image_name}.img ];then
cp -frp $image $bin/img2sdat/${image_name}.img
fi
cd $bin/img2sdat
rm -rf ./output
mkdir ./output
file ${image_name}.img
echo "正在生成 ${image_name}.new.dat..."
python3 ./img2sdat.py "${image_name}.img" -o "output" -v "4" -p "$image_name"
if [ $? != "0" ];then
echo "转换失败!"
rm -rf ${image_name}.img
exit
else
echo "${image_name}.new.dat 已生成..."
rm -rf ${image_name}.img
echo "正在移动至输出目录..."
cd $LOCALDIR
rm -rf ./new_dat
mkdir ./new_dat
mv $bin/img2sdat/output/* ./new_dat/
echo "输出至 $LOCALDIR/new_dat 文件夹"
fi
}
function sdat2sdat_br() {
echo "正在生成 ${image_name}.new.dat.br..."
$bin/brotli -q 0 $LOCALDIR/new_dat/${image_name}.new.dat -o $LOCALDIR/new_dat/${image_name}.new.dat.br
if [ $? != "0" ] ;then
echo "${image_name}.new.dat.br 生成失败!"
exit
else
echo "${image_name}.new.dat.br 已生成"
echo "输出至$LOCALDIR/new_dat/${image_name}.new.dat.br"
fi
}
if ! (file $image | grep -qo "sparse") ;then
img2simg
fi
simg2sdat
if [ "$2" = "--make_br" ];then
make_br="true"
fi
if [ $make_br = "true" ];then
sdat2sdat_br
fi