-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathurl2Debloat.sh
executable file
·74 lines (60 loc) · 1.59 KB
/
url2Debloat.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
#!/bin/bash
# Inspired from url2GSI from ErfanGSIs tool at https://github.com/erfanoabdi/ErfanGSIs
# Copyright to Rahul at https://github.com/rahulkhatri137
LOCALDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
cd $LOCALDIR
source ./bin.sh
usage() {
cat <<EOT
Usage:
$0 <GSI/SGSI link> <Debloated Name>
EOT
}
case $1 in
--help|-h|-?)
usage
exit 1
;;
esac
URL=$1
NAME=$2
LEAVE() {
echo "-> Something got messed up! Exiting..."
rm -rf workspace output tmp
exit 1
}
echo "-> Initing Environment..."
rm -rf $OUTDIR
mkdir -p $TMPDIR
mkdir -p $TARGETDIR
mkdir -p $IMAGESDIR
mkdir -p $OUTDIR
chmod -R 777 ./
if echo "${URL}" | grep -q "http\|https"; then
echo "-> Downloading image..."
cd $TMPDIR
aria2c -x16 ${URL} > /dev/null 2>&1
mv *.img $IMAGESDIR
else
mv $URL $IMAGESDIR
fi
cd $LOCALDIR
chmod -R 777 ./
#Extract Image
echo "-> Extracting image..."
./image_extract.sh > /dev/null 2>&1 || LEAVE
#Debloat
echo "-> Debloating..."
./debloat.sh $systemdir/system > /dev/null 2>&1 || LEAVE
./debloat2.sh $systemdir/system > /dev/null 2>&1 || LEAVE
#vars
date=`date +%Y%m%d`
outputname="$NAME-Debloated-$date-SGSI137".img
output="$OUTDIR/$outputname"
size=`du -sk $systemdir | awk '{$1*=1024;$1=int($1*1.05);printf $1}'`
tree $systemdir > $OUTDIR/$NAME-Debloated-System-Tree.txt
#Pack Image
echo "-> Repacking image..."
$bin/mkuserimg_mke2fs.sh "$systemdir" "$output" "ext4" "/system" $size -j "0" -T "1230768000" -C "$configdir/system_fs_config" -L "system" -I "256" -M "/system" -m "0" "$configdir/system_file_contexts"
rm -rf tmp workspace
echo "-> Debloating GSI done!"