fix: _brightness.sh - find brighness files with '*video*' path (multiple files)
[cmdllinux.git] / buildroot / _pkg / _remove_targz
blob59cd280f01679906a19dea444c363fab0bf930fd
1 #! /bin/bash
3 export LC_COLLATE=C
4 #get params: / targz / targz --root / targz --root dir /
5 [ -z "$1" ] && exit 1
6 REMOVE_FROM_ROOT=0
7 [ "$2" = "--root" ] && REMOVE_FROM_ROOT=1 && ROOT=/
8 [ ! -z "$3" ] && ROOT="$3"
10 #setup tempfiles
11 tempfile1=`mktemp --suffix=-tmp1 2> /dev/null`
12 tempfile2=`mktemp --suffix=-tmp2 2> /dev/null`
13 tempfile3=`mktemp --suffix=-tmp3 2> /dev/null`
14 trap "rm -f $tempfile1 $tempfile2 $tempfile3" 0 1 2 5 15
16 #deal with tempfiles
17 if [ $REMOVE_FROM_ROOT = 0 ]; then
18 tar tzf "$1" | rev | sort -V | rev | tee $tempfile1 | grep "/$" > $tempfile2
19 else
20 if [ "$ROOT" = "/" ]; then
21 tar tzf "$1" | sed "s%.*%/&%" | rev | sort -V | rev | tee $tempfile1 | grep "/$" > $tempfile2
22 else
23 tar tzf "$1" | sed "s%.*%$ROOT/&%" | rev | sort -V | rev | tee $tempfile1 | grep "/$" > $tempfile2
27 grep -v "/$" $tempfile1 > $tempfile3
28 cat $tempfile3 | tr '\n' '\0' | xargs -0 -r rm 2> /dev/null
29 sort -t / $tempfile2 | tac > $tempfile1
30 cat $tempfile1 | tr '\n' '\0' | xargs -0 -r rmdir 2> /dev/null