-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathextract.sh
executable file
·47 lines (36 loc) · 1004 Bytes
/
extract.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
#!/bin/sh
set -e
if [ -z "$1" ]
then
echo "Usage : $0 image(s)"
exit 1
fi
while :
do
[ -z "$1" ] && exit 0
IMAGE="$1"
echo "Extracting $IMAGE ..."
KERNEL_SIZE=$((0x$(od -j12 -N4 -tx1 -An "$IMAGE" | tr -d ' ')))
DIR="${IMAGE%.*}"
mkdir -p "$DIR"
head -c $((64 + KERNEL_SIZE)) "$IMAGE" > "$DIR/uImage"
echo "Extracted $DIR/uImage"
tail -c +65 "$DIR/uImage" > "$DIR/kernel.lzma"
echo "Extracted $DIR/kernel.lzma"
tail -c +$((65 + KERNEL_SIZE)) "$IMAGE" > "$DIR/rootfs.squashfs"
echo "Extracted $DIR/rootfs.squashfs"
rm -rf "$DIR/squashfs-root"
if unsquashfs -n -d "$DIR/squashfs-root" "$DIR/rootfs.squashfs" > /dev/null
then
echo "Extracted rootfs in $DIR/squashfs-root"
else
if [ "$(id -u)" -ne 0 ]
then
echo "Errors during rootfs extraction, ignored since not running as root"
else
echo "Failed to extract rootfs"
exit 1
fi
fi
shift
done