-
Notifications
You must be signed in to change notification settings - Fork 1
/
fsextract.sh
executable file
·90 lines (74 loc) · 1.34 KB
/
fsextract.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
#!/bin/bash
COLORINFO=4
TOOL=unsquashfs # squashfs-tools
ROOTFS=squashfs-root
if [ -z "$1" ]
then
echo "extract squashfs to $ROOTFS"
echo "usage: $0 src.fs"
exit 1
fi
FNAME=$1
echo "processing $FNAME ..."
# extract root
if [ -e "$ROOTFS" ]
then
echo "WARNING: $ROOTFS exists, skipping."
else
echo 'extracting...'
echo '------>>>'
tput setaf $COLORINFO
$TOOL -d $ROOTFS $FNAME '/!(dev)'
RET=$?
tput sgr0
echo '<<<------'
if [ $RET != 0 ] || [ ! -d "$ROOTFS" ]
then
echo 'ERROR: extract squashfs root failed'
exit 1
fi
echo 'creating .gitkeep ...'
find $ROOTFS -empty -type d -exec touch {}/.gitkeep \;
./permssave.sh
RET=$?
if [ $RET != 0 ]
then
exit 1
fi
echo '/ done.'
fi
# extract dev
if [ -e "$ROOTFS-dev" ]
then
echo "ERROR: $ROOTFS-dev exists, remove it."
elif [ -e "$ROOTFS/dev" ]
then
echo "WARNING: $ROOTFS/dev exists, skipping."
else
SUDO=
if [ 'root' != "`whoami`" ]
then
SUDO='sudo'
fi
echo 'extracting /dev ...'
echo '------>>>'
tput setaf $COLORINFO
$SUDO $TOOL -d $ROOTFS-dev $FNAME '/dev'
RET=$?
tput sgr0
echo '<<<------'
if [ $RET != 0 ] || [ ! -d $ROOTFS-dev/dev ]
then
echo 'ERROR: extract squashfs dev failed'
exit 1
fi
$SUDO mv $ROOTFS-dev/dev $ROOTFS/dev
$SUDO rmdir $ROOTFS-dev
if [ ! -d "$ROOTFS/dev" ]
then
echo 'ERROR: move /dev failed'
exit 1
fi
echo '/dev done.'
fi
exit 0