some updates
[cmdllinux.git] / scripts / _tar_xz_files3.sh
blob3b7f132d82d756965af2b2aa02c728f03e3c6c3e
1 #tar xz targzs to destination
3 untargz()
5 while read targz_file; do
6 tar xzf "$targz_file" -C "$DIR_DST" 2> /dev/null
7 retval=$?
8 #2 return code (value) (error) eg.: overwriting an existing directory with symbolic link
9 if [ "$retval" = 2 ]; then
10 tar tzf "$targz_file" | grep -v "/$" | \
11 while read file; do
12 #[ -d "$DIR_DST"/"$file" -a ! -L "$DIR_DST"/"$file" ] && echo "$file"
13 [ -d "$DIR_DST"/"$file" -a ! -L "$DIR_DST"/"$file" ] && rm -rf "$DIR_DST"/"$file"
14 done
15 tar xzf "$targz_file" -C "$DIR_DST" 2> /dev/null
17 done < /dev/stdin
20 if [ "$#" = 3 ]; then
21 TGZ="$1"
22 [ ! -f "$TGZ" ] && echo "No such targz file" && exit 1
23 shift
26 DIR_SRC="$1"
27 DIR_DST="$2"
29 [ ! -d "$DIR_SRC" ] && echo "No such source directory" && exit 1
30 [ ! -d "$DIR_DST" ] && echo "No such destination directory" && exit 1
32 DIR_DST=`cd "$DIR_DST" && pwd -P`
33 [ "$?" != 0 ] && echo "Cannot change to destination directory" && exit 1
35 cd "$DIR_SRC"
36 [ "$?" != 0 ] && echo "Cannot change to source directory" && exit 1
38 if [ -n "$TGZ" ]; then
39 echo "$TGZ" | untargz
40 else
41 ls *.tar.gz 2> /dev/null | untargz