-
Notifications
You must be signed in to change notification settings - Fork 2
/
unpackimg_x64.sh
85 lines (72 loc) · 1.67 KB
/
unpackimg_x64.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
#!/bin/sh
# AIK-Linux/unpackimg: split image and unpack ramdisk
# osm0sis @ xda-developers
cleanup() { rm -rf ramdisk split_img *new.*; }
abort() { cd "$PWD"; echo "Error!"; }
if [ ! "$1" -o ! -f "$1" ]; then
echo "No image file supplied.";
abort;
return 1;
fi;
case $1 in
*\ *)
echo "Filename contains spaces.";
abort;
return 1;;
esac;
bin="$PWD/bin";
chmod -R 755 "$bin" "$PWD"/*.sh;
chmod 644 "$bin/magic";
cd "$PWD";
clear;
echo "\nAndroid Image Kitchen - UnpackImg Script - x64";
echo "by osm0sis @ xda-developers\n";
file=`basename "$1"`;
echo "Supplied image: $file\n";
if [ -d split_img -o -d ramdisk ]; then
echo "Removing old work folders and files...\n";
cleanup;
fi;
echo "Setting up work folders...\n";
mkdir split_img ramdisk;
echo 'Splitting image to "split_img/"...\n'
$bin/unpackbootimg_x64 -i "$1" -o split_img;
if [ $? -eq "1" ]; then
cleanup;
abort;
return 1;
fi;
cd split_img;
file -m $bin/magic *-ramdisk.gz | cut -d: -f2 | cut -d" " -f2 > "$file-ramdiskcomp";
ramdiskcomp=`cat *-ramdiskcomp`;
unpackcmd="$ramdiskcomp -dc";
compext=$ramdiskcomp;
case $ramdiskcomp in
gzip) compext=gz;;
lzop) compext=lzo;;
xz) ;;
lzma) ;;
bzip2) compext=bz2;;
lz4) unpackcmd="$bin/lz4_x64 -dq"; extra="stdout";;
*) compext="";;
esac;
if [ "$compext" ]; then
compext=.$compext;
fi;
mv "$file-ramdisk.gz" "$file-ramdisk.cpio$compext";
cd ..;
echo '\nUnpacking ramdisk to "ramdisk/"...\n';
cd ramdisk;
echo "Compression used: $ramdiskcomp";
if [ ! "$compext" ]; then
abort;
return 1;
fi;
$unpackcmd "../split_img/$file-ramdisk.cpio$compext" $extra | cpio -i;
if [ $? -eq "1" ]; then
abort;
return 1;
fi;
cd ..;
echo "\nDone!";
return 0;