-
Notifications
You must be signed in to change notification settings - Fork 0
/
xs-unpack-xobuild
executable file
·62 lines (56 loc) · 1.54 KB
/
xs-unpack-xobuild
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
#!/bin/bash
#
##
## unpack the jffs2 tree file in a fakeroot
## to preserve all its glory
##
## Author: Martin Langhoff <[email protected]>
##
#
set -e
# Parameters
DESTDIR=$1 # complete dest dir path
BUILDFILE=$2 # tree file
# Very recommended: Set TMPDIR to a tempdir
# on the same partition as DESTDIR
TEMPDIR=$(mktemp -d)
if [ -z "$FAKEROOTKEY" ]; then
echo $0 MUST run in a fakeroot.
echo You do NOT want to be creating
echo random devices on your machine.
exit 1
fi
if [ -z "$DESTDIR" -o -z "$BUILDFILE" ]; then
echo Missing a parameter. Usage:
echo $0 destdir buildfile
exit 1
fi
# Stop complaining and do the job
if [ ${BUILDFILE:(-8)} = ".tar.bz2" ]; then
tar -C "$TEMPDIR" --numeric-owner -xpjf "$BUILDFILE"
elif [ ${BUILDFILE:(-9)} = ".tar.lzma" ]; then
lzma -cd "$BUILDFILE" | tar -C "$TEMPDIR" --numeric-owner -xp
elif [ ${BUILDFILE:(-7)} = ".tar.xz" ]; then
xz -cd "$BUILDFILE" | tar -C "$TEMPDIR" --numeric-owner -xp
else
echo Unknown file format!
exit 1
fi
#
# Some of the images have odd leftovers around
# so if the image contains a pristine copy, use that.
# Otherwise, clear out the '/versions' directory.
#
if [ -e "$TEMPDIR/versions/pristine" ];then
PRI=`ls $TEMPDIR/versions/pristine | sort | head -n1`
if [ -n "$PRI" -a -d "$TEMPDIR/versions/pristine/$PRI" ];then
mv -T "$TEMPDIR/versions/pristine/$PRI" "$DESTDIR"
rm -fr "$TEMPDIR"
else
rm -fr "$TEMPDIR/versions"
mv -T "$TEMPDIR" "$DESTDIR"
fi
else
rm -fr "$TEMPDIR/versions"
mv -T "$TEMPDIR" "$DESTDIR"
fi