forked from erfanoabdi/Capire-Le-Treble
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CLT-ify_ab.sh
executable file
·116 lines (99 loc) · 3.51 KB
/
CLT-ify_ab.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
#!/bin/bash
# Project Capire le treble (CLT) by Erfan Abdi <[email protected]>
# Modified for AB type devices by Pranav Bedre <[email protected]>
usage()
{
echo "Usage: $0 <Path to Orginal system> <Path to GSI system> <System Partition Size> <Output File> [proprietary-files.txt]"
echo -e "\tPath to Orginal system : Mount treblized lineage system image and set mount point"
echo -e "\tPath to GSI system : Mount GSI and set mount point"
echo -e "\tSystem Partition Size : set system Partition Size"
echo -e "\tOutput File : set Output file path (system.img)"
echo -e "\tproprietary-files.txt : enter proprietary-files.txt if you want to copy any file from orginal system to target"
}
if [ "$4" == "" ]; then
echo "ERROR: Enter all needed parameters"
usage
exit 1
fi
lineage=$1
gsi=$2
syssize=$3
output=$4
LOCALDIR=`pwd`
tempdirname="tmp"
tempdir="$LOCALDIR/$tempdirname"
systemdir="$tempdir/system"
toolsdir="$LOCALDIR/tools"
echo "Create Temp dir"
mkdir -p "$systemdir"
echo "Copy Lineage RootDir Files to Temp"
( cd "$lineage" ; sudo tar cf - --exclude="./system" . ) | ( cd "$systemdir" ; sudo tar xf - )
cd "$LOCALDIR"
echo "Copy GSI System to Temp"
( cd "$gsi" ; sudo tar cf - "system" ) | ( cd "$systemdir" ; sudo tar xf - )
cd "$LOCALDIR"
echo "Remove Vendor Symlink"
sudo rm -rf "$systemdir/system/vendor"
echo "Copy Vendor Dir to Temp"
( cd "$lineage/system" ; sudo tar cf - "vendor" ) | ( cd "$systemdir/system" ; sudo tar xf - )
cd "$LOCALDIR"
if [ "$5" != "" ]; then
echo "Copy System Prop Files"
proptxt=$5
while read -r line
do
line=`echo "$line" | grep -v vendor/`
[[ $line = \#* ]] && continue
[ -z "$line" ] && continue
if [[ $line = '-'* ]]
then
line=`echo "$line" | cut -c2-`
fi
if [[ $line = '?'* ]]
then
line=`echo "$line" | cut -c2-`
file=`echo "$line" | cut -d ":" -f 2 | cut -d "|" -f 1`
filedir=`echo $file | rev | cut -d "/" -f 2- | rev`
sudo mkdir -p "$systemdir/system/$filedir"
sudo cp -npr "$lineage/system/$file" "$systemdir/system/$filedir/"
continue
fi
file=`echo "$line" | cut -d ":" -f 2 | cut -d "|" -f 1`
filedir=`echo $file | rev | cut -d "/" -f 2- | rev`
sudo mkdir -p "$systemdir/system/$filedir"
sudo cp -fpr "$lineage/system/$file" "$systemdir/system/$filedir/"
done < "$proptxt"
fi
echo "Prepare File Contexts"
p="/plat_file_contexts"
n="/nonplat_file_contexts"
for f in "$systemdir/system/etc/selinux" "$systemdir/system/vendor/etc/selinux" "$systemdir"; do
if [[ -f "$f$p" ]]; then
sudo cat "$f$p" >> "$tempdir/file_contexts_tmp"
fi
if [[ -f "$f$n" ]]; then
sudo cat "$f$n" >> "$tempdir/file_contexts_tmp"
fi
done
sudo sort "$tempdir/file_contexts_tmp" | uniq >> "$tempdir/file_contexts"
if [[ -f "$tempdir/file_contexts" ]]; then
fcontexts="-S $tempdir/file_contexts"
fi
if [[ "$OSTYPE" == "linux-gnu" ]]; then
if [[ $(getconf LONG_BIT) = "64" ]]; then
make_ext4fs="$toolsdir/linux/bin/make_ext4fs_64"
else
make_ext4fs="$toolsdir/linux/bin/make_ext4fs_32"
fi
elif [[ "$OSTYPE" == "darwin"* ]]; then
make_ext4fs="$toolsdir/mac/bin/make_ext4fs"
else
echo "Not Supported OS for make_ext4fs"
echo "Removing Temp dir"
sudo rm -rf "$tempdir"
exit 1
fi
echo "Create Image"
sudo $make_ext4fs -T 0 $fcontexts -l $syssize -L / -a / -s "$output" "$systemdir/"
echo "Remove Temp dir"
sudo rm -rf "$tempdir"