4 #get params: / targz / targz --root / targz --root dir /
8 [ "$2" = "--root" ] && ROOT
=/
9 [ ! -z "$3" ] && ROOT
="$3"
10 [ -z "$ROOT" ] && ROOT
="."
12 [ ! -d "$ROOT" ] && echo "No such directory" && exit 1
16 [ "$?" != 0 ] && echo "Cannot change to directory" && exit 1
19 [ "$?" != 0 ] && echo "Cannot change to original directory" && exit 1
22 tempfile1
=`mktemp --suffix=-tmp1 2> /dev/null`
23 tempfile2
=`mktemp --suffix=-tmp2 2> /dev/null`
24 tempfile3
=`mktemp --suffix=-tmp3 2> /dev/null`
25 trap "rm -f $tempfile1 $tempfile2 $tempfile3" 0 1 2 5 15
27 #remove multiple slashes and slash from the end (to zero if ROOT=/)
28 ROOT
=`echo -n "$ROOT" | sed -e 's%/\+$%%' -e 's%/\+%/%g'`
30 #cat list of directories to keep
31 [ -d "$ROOT"/var
/lib
/instpkg
/local ] && removedb
=1
32 keepdirs
=`cat "$ROOT"/var/lib/instpkg/local/*/keepdirs 2> /dev/null | cut -d ' ' -f 4-`
34 [ ! -z "$keepdirs" ] && keepdirs
=`echo "$keepdirs" | sed "s%.*%$ROOT/&/%"`
36 #list tar and add root dir and grep dirs
37 tar tzf
"$1" |
sed "s%.*%$ROOT/&%" |
tee $tempfile1 |
grep "/$" > $tempfile2
40 grep -v "/$" $tempfile1 > $tempfile3
43 cat $tempfile3 |
tr '\n' '\0' |
xargs -0 -r rm 2> /dev
/null
46 if [ "$removedb" = 1 ]; then
47 tac $tempfile2 |
grep -vFx "$keepdirs" |
tr '\n' '\0' |
xargs -0 -r rmdir 2> /dev
/null
49 tac $tempfile2 |
tr '\n' '\0' |
xargs -0 -r rmdir 2> /dev
/null