-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathmake.sh
executable file
·120 lines (104 loc) · 2.8 KB
/
make.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
# Copyright (C) 2021 Xiaoxindada <[email protected]>
# 2021 Jiuyu <[email protected]>
LOCALDIR=`cd "$( dirname ${BASH_SOURCE[0]} )" && pwd`
cd $LOCALDIR
source $LOCALDIR/bin.sh
source $TOOLDIR/language_helper.sh
Usage() {
cat <<EOT
Usage:
$0 <Build Type> <Firmware Path>
Build Type: [AB|ab] or [A|a]
Firmware Path: Rom Firmware Path
EOT
}
case $1 in
"AB"|"ab")
build_type="AB"
;;
"A"|"a")
build_type="A"
echo $NOTSUPPAONLY
exit 1
;;
"-h"|"--help")
Usage
exit 1
;;
*)
Usage
exit 1
;;
esac
if [ $# -lt 2 ];then
Usage
exit 1
fi
firmware=$2
systemdir=$TARGETDIR/system/system
configdir="$TARGETDIR/config"
if [ ! -e $firmware ];then
if [ ! -e $TMPDIR/$firmware ];then
echo $NOTFOUNDFW
exit 1
fi
fi
rm -rf $TOOLDIR/other/*.log
function firmware_extract() {
rm -rf $WORKSPACE
mkdir -p $TARGETDIR
cd $LOCALDIR
if [ -e $firmware ];then
./Firmware_extractor/extractor.sh $firmware $TMPDIR > $TARGETDIR/extract.log 2> $TOOLDIR/other/extract.log || { echo "> Failed to extract firmware" && exit 1; }
fi
if [ -e $TMPDIR/$firmware ];then
./Firmware_extractor/extractor.sh "$TMPDIR/$firmware" "$TMPDIR/" > $TARGETDIR/extract.log 2> $TOOLDIR/other/extract.log || { echo "> Failed to extract firmware" && exit 1; }
fi
}
chmod -R 777 ./
./workspace_cleanup.sh > /dev/null 2>&1
if [[ $firmware == system.img ]]; then
rm -rf $TARGETDIR
mkdir -p $IMAGESDIR
mv $firmware $IMAGESDIR/ || mv $TMPDIR/$firmware $IMAGESDIR/
else
echo "┠ Extracting Firmware..."
firmware_extract
fi
mkdir -p $IMAGESDIR
mkdir -p $TARGETDIR
mkdir -p $OUTDIR
# Detect image
if [[ -d $TMPDIR ]];then
cd $TMPDIR
mv *.img $IMAGESDIR/
fi
if ! [ -e $IMAGESDIR/system.img ];then
echo "> $NOTFOUNDSYSTEMIMG"
exit 1
fi
cd $LOCALDIR
echo "├─ Extracting images..."
# Sparse Image To Raw Image
$SCRIPTDIR/simg2img.sh "$IMAGESDIR" > $TARGETDIR/simg.log 2> $TOOLDIR/other/simg.log || { echo "> Failed to convert sparse image!" ; exit 1; }
# Mount Partitions
#./scripts/mount_partition.sh > /dev/null 2>&1 || { echo "> Failed to mount!" ; exit 1; }
cd $LOCALDIR
# Extract Image
$SCRIPTDIR/image_extract.sh > $TARGETDIR/eimg.log 2> $TOOLDIR/other/eimg.log || { echo "> Failed to extract image!" ; exit 1; }
echo "├─ Extracted."
if [[ -d $systemdir/../system_ext && -L $systemdir/system_ext ]] \
|| [[ -d $systemdir/../product && -L $systemdir/product ]];then
echo "┠ Merging dynamic partitions..."
$SCRIPTDIR/partition_merge.sh > $TARGETDIR/dynamic.log 2> $TOOLDIR/other/dynamic.log || { echo "> Failed to merge dynamic partitions!" ; exit 1; }
echo "├─ Merged."
fi
if [[ ! -d $systemdir/product ]];then
echo "> product $DIR_NOT_FOUND_STR!"
exit 1
elif [[ ! -d $systemdir/system_ext ]];then
echo "> system_ext $DIR_NOT_FOUND_STR!"
exit 1
fi
exit 0