one file at the time for now

This commit is contained in:
Serghey Rodin 2015-11-05 03:10:57 +02:00
commit a0ee9bbc98

View file

@ -1,22 +1,16 @@
#!/bin/bash #!/bin/bash
# info: archive directory # info: archive directory
# options: USER ARCHIVE DIRECTORY [DIRECTORY_N] # options: USER ARCHIVE SOURCE
# #
# The function creates tar archive # The function creates tar archive
user=$1 user=$1
archive=$2 archive=$2
src1=$3 src=$3
src2=$4
src3=$5
src4=$6
src5=$7
src6=$8
src7=$9
# Checking arguments # Checking arguments
if [ -z "$src1" ]; then if [ -z "$src" ]; then
echo "Usage: USER ARCHIVE DIRECTORY [DIRECTORY_N]" echo "Usage: USER ARCHIVE SOURCE"
exit 1 exit 1
fi fi
@ -40,19 +34,22 @@ if [ -e "$archive.tar.gz" ]; then
fi fi
# Checking source path # Checking source path
for src_path in $src1 $src2 $src3 $src4 $src5 $src6 $src7; do rpath=$(readlink -f "$src")
rpath=$(readlink -f "$src_path") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then echo "Error: invalid source path $src"
echo "Error: invalid source path $src_path" exit 1
exit 1 fi
fi
done # Parsing current directory
d=$(dirname "$src")
# Removing leading file path
f=$(echo "$src" |sed -e "s|$d/||")
# Creating tar.gz archive # Creating tar.gz archive
sudo -u $user tar -czf "$archive.tar.gz" \ sudo -u $user tar -czf "$archive.tar.gz" -C $d $f >/dev/null 2>&1
$src1 $src2 $src3 $src4 $src5 $src6 $src7 > /dev/null 2>&1
if [ "$?" -ne 0 ]; then if [ "$?" -ne 0 ]; then
# echo "Error: archive $archive.tar.gz was not created" echo "Error: archive $archive.tar.gz was not created"
exit 3 exit 3
fi fi