some updates
[cmdllinux.git] / scripts / _tar_xz_files4.sh
blobfd2479b90141e4109bf02cefd12fb3177c131080
1 #tar xz targzs to destination
3 chk_exist()
5 #check if files exist on destination except symlinks to directories
6 tar tzf "$targz_file" | grep -v "/$" | \
7 while read line; do
8 [ -e "$DIR_DST"/"$line" ] && echo "$line"
9 done | grep -vFx "$(cat "$DIR_DST"/var/lib/instpkg/local/*/dirlinks 2> /dev/null)"
12 untargz()
14 while read targz_file; do
15 #check if files exist
16 if [ $chk_dirlinks ]; then
17 LS_EXIST=`chk_exist`
18 [ ! -z "$LS_EXIST" ] && echo "$LS_EXIST" | sed "s%.*%$targz_file : '&' exists on destination path%" && exit 1
20 tar xzf "$targz_file" -C "$DIR_DST" 2> /dev/null
21 retval=$?
22 #2 return code (value) (error) eg.: overwriting an existing directory with symbolic link
23 if [ "$retval" = 2 ]; then
24 tar tzf "$targz_file" | grep -v "/$" | \
25 while read file; do
26 #[ -d "$DIR_DST"/"$file" -a ! -L "$DIR_DST"/"$file" ] && echo "$file"
27 [ -d "$DIR_DST"/"$file" -a ! -L "$DIR_DST"/"$file" ] && rm -rf "$DIR_DST"/"$file"
28 done
29 tar xzf "$targz_file" -C "$DIR_DST" 2> /dev/null
31 done < /dev/stdin
34 [ "$1" = "-c" ] && chk_dirlinks=1 && shift
36 if [ "$#" = 3 ]; then
37 TGZ="$1"
38 [ ! -f "$TGZ" ] && echo "No such targz file" && exit 1
39 shift
42 DIR_SRC="$1"
43 DIR_DST="$2"
45 [ ! -d "$DIR_SRC" ] && echo "No such source directory" && exit 1
46 [ ! -d "$DIR_DST" ] && echo "No such destination directory" && exit 1
48 DIR_DST=`cd "$DIR_DST" && pwd -P`
49 [ "$?" != 0 ] && echo "Cannot change to destination directory" && exit 1
51 cd "$DIR_SRC"
52 [ "$?" != 0 ] && echo "Cannot change to source directory" && exit 1
54 if [ -n "$TGZ" ]; then
55 echo "$TGZ" | untargz
56 else
57 ls *.tar.gz 2> /dev/null | untargz