-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
merger.sh
executable file
·133 lines (106 loc) · 2.35 KB
/
merger.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
#!/bin/bash
set -e
banner()
{
clear
cat <<'EOF'
-,-,----------------------fossfrog's__
/_/_ _ _ _/. _/_ /|,/_ _ _ _ _
/ \/_|/ / //_//_\/\ / //_'/ /_//_'/
_/
git: shubhamvis98/ramdisk-merger
EOF
}
gethelp()
{
banner
echo "USAGE: $(basename $0) [OPTION] [FILE]"
echo -e " -h|--help\t#Help"
echo -e " -a|--android\t#Select Android boot image file"
echo -e " -t|--twrp\t#Select TWRP image file"
}
msg()
{
echo
echo "[+]$@"
}
chkarch()
{
arch=$(uname -m)
if [[ "$arch" == "arm" || "$arch" == "aarch64" ]]; then
MAGISKBOOT=`pwd`/bin/magiskboot_arm
elif [[ "$arch" == "x86_64" ]]; then
MAGISKBOOT=`pwd`/bin/magiskboot_x86
else
echo "[!]Unknown architecture"
exit
fi
}
banner
chkarch
OPTARG=$(getopt -o :ha:t: -l help,android:,twrp: -- "$@")
if [ "$?" != "0" ]; then
gethelp
exit
fi
eval set -- $OPTARG
while true
do
case "$1" in
-h|--help)
gethelp
exit;;
-a|--android)
ANDBOOT="$2"
shift 2;;
-t|--twrp)
TWRPBOOT="$2"
shift 2;;
*)
break;;
esac
done
if [ ! -e "$ANDBOOT" ] || [ ! -e "$TWRPBOOT" ]
then
echo "[!]Invalid Input"
exit 1
fi
WORKDIR=`pwd`
ANDTMP=$WORKDIR/andtmp
TWRPTMP=$WORKDIR/twrptmp
BB=$WORKDIR/_tmp
cleanup()
{
rm -rf $BB/sbin/*.cpio $ANDTMP $TWRPTMP
rm -rf $TWRPTMP $ANDTMP
}
msg "Removing old tmp files"
cleanup
echo -n "[?]Press return to edit device-specific details: "; read _null
nano $BB/sbin/device-params
mkdir $ANDTMP $TWRPTMP
cp $ANDBOOT $ANDTMP
cp $TWRPBOOT $TWRPTMP
msg "Unpacking $ANDBOOT"
cd $ANDTMP; $MAGISKBOOT unpack -h $ANDBOOT
mv ramdisk.cpio $BB/sbin/android.cpio
msg "Unpacking $TWRPBOOT"
cd $TWRPTMP; $MAGISKBOOT unpack -h $TWRPBOOT
ANDVER=`tail -n2 $ANDTMP/header | head -n1 | cut -d '=' -f2`
ANDLVL=`tail -n1 $ANDTMP/header | cut -d '=' -f2`
TWRPVER=`tail -n2 $TWRPTMP/header | head -n1 | cut -d '=' -f2`
TWRPLVL=`tail -n1 $TWRPTMP/header | cut -d '=' -f2`
rm header kernel* $TWRPBOOT
msg "Extracting ${TWRPBOOT}'s ramdisk"
cpio -i < ramdisk.cpio
rm ramdisk.cpio
msg "Patching ramdisk"
sed -i "s/$TWRPVER/$ANDVER/g;s/$TWRPLVL/$ANDLVL/g" prop.default
msg "Compressing ramdisk"
find . | cpio -H newc -o > $BB/sbin/twrp.cpio
cd $BB; find . | cpio -H newc -o > $ANDTMP/ramdisk.cpio
msg "Repacking merged boot image"
cd $ANDTMP; $MAGISKBOOT repack $ANDBOOT
mv new-boot.img $WORKDIR/
msg "Boot image placed here: $WORKDIR/new-boot.img"
cleanup