cleanup
[cmdllinux.git] / scripts / _tar_xz_files2.sh
blob4fe08c2387ab8172f5613a546bb241448f500230
1 #tar xz targzs to destination
2 DIR="$1"
3 DIR2="$2"
5 [ ! -d "$DIR" ] && echo "No such source directory" && exit 1
6 [ ! -d "$DIR2" ] && echo "No such destination directory" && exit 1
8 DIR2=`cd "$DIR2" && pwd -P`
9 [ "$?" != 0 ] && echo "Cannot change to destination directory" && exit 1
11 cd "$DIR"
12 [ "$?" != 0 ] && echo "Cannot change to source directory" && exit 1
14 ls *.tar.gz 2> /dev/null | \
15 while read targz_file; do
16 tar xzf "$targz_file" -C "$DIR2" 2> /dev/null
17 retval=$?
18 #2 return code (value) (error) eg.: overwriting an existing directory with symbolic link
19 if [ "$retval" = 2 ]; then
20 tar tzf "$targz_file" | grep -v "/$" | \
21 while read file; do
22 #[ -d "$DIR2"/"$file" -a ! -L "$DIR2"/"$file" ] && echo "$file"
23 [ -d "$DIR2"/"$file" -a ! -L "$DIR2"/"$file" ] && rm -rf "$DIR2"/"$file"
24 done
25 tar xzf "$targz_file" -C "$DIR2" 2> /dev/null
27 done