forked from erfanoabdi/ErfanGSIs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url2GSI.sh
executable file
·160 lines (136 loc) · 3.4 KB
/
url2GSI.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/bin/bash
# Project OEM-GSI Porter by Erfan Abdi <[email protected]>
PROJECT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
AB=true
AONLY=true
MOUNTED=false
CLEAN=false
usage()
{
echo "Usage: [--help|-h|-?] [--ab|-b] [--aonly|-a] [--mounted|-m] [--cleanup|-c] $0 <Firmware link> <Firmware type> [Other args]"
echo -e "\tFirmware link: Firmware download link or local path"
echo -e "\tFirmware type: Firmware mode"
echo -e "\t--ab: Build only AB"
echo -e "\t--aonly: Build only A-Only"
echo -e "\t--cleanup: Cleanup downloaded firmware"
echo -e "\t--help: To show this info"
}
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
--ab|-b)
AONLY=false
AB=true
shift
;;
--aonly|-a)
AONLY=true
AB=false
shift
;;
--cleanup|-c)
CLEAN=true
shift
;;
--help|-h|-?)
usage
exit
;;
*)
POSITIONAL+=("$1")
shift
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [[ ! -n $2 ]]; then
echo "ERROR: Enter all needed parameters"
usage
exit
fi
URL=$1
shift
SRCTYPE=$1
shift
ORIGINAL_URL=$URL
if [[ $SRCTYPE == *":"* ]]; then
SRCTYPENAME=`echo "$SRCTYPE" | cut -d ":" -f 2`
else
SRCTYPENAME=$SRCTYPE
fi
DOWNLOAD()
{
URL="$1"
ZIP_NAME="$2"
echo "Downloading firmware to: $ZIP_NAME"
aria2c -x16 -j$(nproc) -U "Mozilla/5.0" -d "$PROJECT_DIR/input" -o "$ACTUAL_ZIP_NAME" ${URL} || wget -U "Mozilla/5.0" ${URL} -O "$ZIP_NAME"
}
MOUNT()
{
mkdir -p "$PROJECT_DIR/working/system"
if [ $(uname) == Linux ]; then
sudo mount -o ro "$1" "$PROJECT_DIR/working/system"
elif [ $(uname) == Darwin ]; then
fuse-ext2 "$1" "$PROJECT_DIR/working/system"
fi
}
UMOUNT()
{
sudo umount "$1"
}
LEAVE()
{
UMOUNT "$PROJECT_DIR/working/system"
rm -rf "$PROJECT_DIR/working"
exit 1
}
echo "Updating tools..."
"$PROJECT_DIR"/update.sh
# Create input & working directory if it does not exist
mkdir -p "$PROJECT_DIR/input" "$PROJECT_DIR/working" "$PROJECT_DIR/output"
if [[ -d "$URL" ]]; then
MOUNTED=true
fi
ZIP_NAME="$PROJECT_DIR/input/dummy"
if [ $MOUNTED == false ]; then
if [[ "$URL" == "http"* ]]; then
# URL detected
RANDOMM=$(echo $RANDOM)
ACTUAL_ZIP_NAME="$RANDOMM"_FIRMWARE.tgz
ZIP_NAME="$PROJECT_DIR"/input/"$RANDOMM"_FIRMWARE.tgz
DOWNLOAD "$URL" "$ZIP_NAME"
URL="$ZIP_NAME"
fi
"$PROJECT_DIR"/zip2img.sh "$URL" "$PROJECT_DIR/working" || exit 1
if [ $CLEAN == true ]; then
rm -rf "$ZIP_NAME"
fi
MOUNT "$PROJECT_DIR/working/system.img"
URL="$PROJECT_DIR/working/system"
fi
if [ $AB == true ]; then
"$PROJECT_DIR"/make.sh "${URL}" "${SRCTYPE}" AB "$PROJECT_DIR/output" ${@} || LEAVE
fi
if [ $AONLY == true ]; then
"$PROJECT_DIR"/make.sh "${URL}" "${SRCTYPE}" Aonly "$PROJECT_DIR/output" ${@} || LEAVE
fi
UMOUNT "$PROJECT_DIR/working/system"
rm -rf "$PROJECT_DIR/working"
echo "Porting ${SRCTYPENAME} GSI done on: $PROJECT_DIR/output"
if [[ -f "$PROJECT_DIR/private_utils.sh" ]]; then
. "$PROJECT_DIR/private_utils.sh"
UPLOAD "$PROJECT_DIR/output" ${SRCTYPENAME} ${AB} ${AONLY} "${ORIGINAL_URL}"
fi
DEBUG=false
if [ $DEBUG == true ]; then
echo "AONLY = ${AONLY}"
echo "AB = ${AB}"
echo "MOUNTED = ${MOUNTED}"
echo "URL = ${URL}"
echo "SRCTYPE = ${SRCTYPE}"
echo "SRCTYPENAME = ${SRCTYPENAME}"
echo "OTHER = ${@}"
echo "ZIP_NAME = ${ZIP_NAME}"
fi