File tree Expand file tree Collapse file tree 13 files changed +292
-82
lines changed
Expand file tree Collapse file tree 13 files changed +292
-82
lines changed Original file line number Diff line number Diff line change 1+ #! /bin/bash
2+ # info: archive directory
3+ # options: USER ARCHIVE DIRECTORY [DIRECTORY_N]
4+ #
5+ # The function creates tar archive
6+
7+ user=$1
8+ archive=$2
9+ src1=$3
10+ src2=$4
11+ src3=$5
12+ src4=$6
13+ src5=$7
14+ src6=$8
15+ src7=$9
16+
17+ # Checking arguments
18+ if [ -z " $src1 " ]; then
19+ echo " Usage: USER ARCHIVE DIRECTORY [DIRECTORY_N]"
20+ exit 1
21+ fi
22+
23+ # Checking vesta user
24+ if [ ! -e " $VESTA /data/users/$user " ]; then
25+ echo " Error: vesta user $user doesn't exist"
26+ exit 3
27+ fi
28+
29+ # Checking user homedir
30+ homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
31+ if [ -z $homedir ]; then
32+ echo " Error: user home directory doesn't exist"
33+ exit 12
34+ fi
35+
36+ # Checking archive
37+ if [ -e " $archive .tar.gz" ]; then
38+ echo " Error: archive already exist $archive .tar.gz"
39+ exit 1
40+ fi
41+
42+ # Checking source path
43+ for src_path in $src1 $src2 $src3 $src4 $src5 $src6 $src7 ; do
44+ rpath=$( readlink -f " $src_path " )
45+ if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
46+ echo " Error: invalid source path $src_path "
47+ exit 1
48+ fi
49+ done
50+
51+ # Creating tar.gz archive
52+ sudo -u $user tar -czf " $archive .tar.gz" \
53+ $src1 $src2 $src3 $src4 $src5 $src6 $src7 > /dev/null 2>&1
54+ if [ " $? " -ne 0 ]; then
55+ echo " Error: archive $archive .tar.gz was not created"
56+ exit 3
57+ fi
58+
59+ exit
Original file line number Diff line number Diff line change 1515
1616# Checking vesta user
1717if [ ! -e " $VESTA /data/users/$user " ]; then
18- exit 1
18+ echo " Error: vesta user $user doesn't exist"
19+ exit 3
1920fi
2021
2122# Checking user homedir
2223homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
2324if [ -z $homedir ]; then
24- exit 1
25+ echo " Error: user home directory doesn't exist"
26+ exit 12
2527fi
2628
2729# Checking destination path
2830rpath=$( readlink -f " $dst_dir " )
2931if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
30- exit 1
32+ echo " Error: invalid destination path $dst_dir "
33+ exit 2
3134fi
3235
3336# Adding directory
34- sudo -u $user mkdir -p $dst_dir > /dev/null 2>&1
37+ sudo -u $user mkdir -p " $dst_dir " > /dev/null 2>&1
38+ if [ $? -ne 0 ]; then
39+ echo " Error: directory $dst_dir was not created"
40+ exit 3
41+ fi
3542
3643# Extiging
37- exit $?
44+ exit
Original file line number Diff line number Diff line change 1515
1616# Checking vesta user
1717if [ ! -e " $VESTA /data/users/$user " ]; then
18- exit 1
18+ echo " Error: vesta user $user doesn't exist"
19+ exit 3
1920fi
2021
2122# Checking user homedir
2223homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
2324if [ -z $homedir ]; then
24- exit 1
25+ echo " Error: user home directory doesn't exist"
26+ exit 12
2527fi
2628
2729# Checking destination path
2830rpath=$( readlink -f " $dst_file " )
2931if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
30- exit 1
32+ echo " Error: invalid destination path $dst_dir "
33+ exit 2
3134fi
3235
3336# Creating file
34- sudo -u $user touch $dst_file > /dev/null 2>&1
37+ sudo -u $user touch " $dst_file " > /dev/null 2>&1
38+ if [ $? -ne 0 ]; then
39+ echo " Error: file $dst_file was not created"
40+ exit 3
41+ fi
3542
3643# Exiting
37- exit $?
44+ exit
Original file line number Diff line number Diff line change 1616
1717# Checking vesta user
1818if [ ! -e " $VESTA /data/users/$user " ]; then
19- exit 1
19+ echo " Error: vesta user $user doesn't exist"
20+ exit 3
2021fi
2122
2223# Checking user homedir
2324homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
2425if [ -z $homedir ]; then
25- exit 1
26+ echo " Error: user home directory doesn't exist"
27+ exit 12
2628fi
2729
2830# Checking source file
2931if [ ! -f " $src_file " ]; then
30- exit 1
32+ echo " Error: source file doesn't exist $src_file "
33+ exit 3
3134fi
3235
3336# Checking source path
3437rpath=$( readlink -f " $src_file " )
3538if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
36- exit 1
39+ echo " Error: invalid source path $src_file "
40+ exit 2
3741fi
3842
3943# Changing file permissions
40- sudo -u $user chmod $permisions $src_file > /dev/null 2>&1
44+ sudo -u $user chmod $permisions " $src_file " > /dev/null 2>&1
45+ if [ $? -ne 0 ]; then
46+ echo " Error: access permission on $src_file was not changed"
47+ exit 3
48+ fi
4149
4250# Exiting
43- exit $?
51+ exit
Original file line number Diff line number Diff line change 1616
1717# Checking vesta user
1818if [ ! -e " $VESTA /data/users/$user " ]; then
19- exit 1
19+ echo " Error: vesta user $user doesn't exist"
20+ exit 3
2021fi
2122
2223# Checking user homedir
2324homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
2425if [ -z $homedir ]; then
25- exit 1
26+ echo " Error: user home directory doesn't exist"
27+ exit 12
2628fi
2729
2830# Checking source dir
2931if [ ! -e " $src_dir " ]; then
30- exit 1
32+ echo " Error: source directory $src_dir doesn't exist"
33+ exit 3
3134fi
3235
3336# Checking source path
3437rpath=$( readlink -f " $src_dir " )
3538if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
36- exit 1
39+ echo " Error: invalid source path $src_dir "
40+ exit 2
3741fi
3842
3943# Checking destination path
4044rpath=$( readlink -f " $dst_dir " )
4145if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
42- exit 1
46+ echo " Error: invalid destination path $dst_dir "
47+ exit 2
4348fi
4449
4550# Copying directory
46- sudo -u $user cp -r $src_dir $dst_dir > /dev/null 2>&1
51+ sudo -u $user cp -r " $src_dir " " $dst_dir " > /dev/null 2>&1
52+ if [ $? -ne 0 ]; then
53+ echo " Error: directory $src_dir was not copied"
54+ exit 3
55+ fi
4756
4857# Exiting
49- exit $?
58+ exit
Original file line number Diff line number Diff line change 1616
1717# Checking vesta user
1818if [ ! -e " $VESTA /data/users/$user " ]; then
19- exit 1
19+ echo " Error: vesta user $user doesn't exist"
20+ exit 3
2021fi
2122
2223# Checking user homedir
2324homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
2425if [ -z $homedir ]; then
25- exit 1
26+ echo " Error: user home directory doesn't exist"
27+ exit 12
2628fi
2729
2830# Checking source file
2931if [ ! -f " $src_file " ]; then
30- exit 1
32+ echo " Error: $src_file doesn't exist"
33+ exit 3
3134fi
3235
3336# Checking source path
3437rpath=$( readlink -f " $src_file " )
3538if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
36- exit 1
39+ echo " Error: invalid source path $src_file "
40+ exit 2
3741fi
3842
3943# Checking destination path
4044rpath=$( readlink -f " $dst_file " )
4145if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
42- exit 1
46+ echo " Error: ivalid destination path $dst_file "
47+ exit 2
4348fi
4449
4550# Copying file
46- sudo -u $user cp $src_file $dst_file > /dev/null 2>&1
51+ sudo -u $user cp " $src_file " " $dst_file " > /dev/null 2>&1
52+ if [ $? -ne 0 ]; then
53+ echo " Error: file $src_file was not copied"
54+ exit 3
55+ fi
4756
4857# Exiting
49- exit $?
58+ exit
Original file line number Diff line number Diff line change 1616
1717# Checking vesta user
1818if [ ! -e " $VESTA /data/users/$user " ]; then
19- exit 1
19+ echo " Error: vesta user $user doesn't exist"
20+ exit 3
2021fi
2122
2223# Checking user homedir
2324homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
2425if [ -z $homedir ]; then
25- exit 1
26+ echo " Error: user home directory doesn't exist"
27+ exit 12
2628fi
2729
2830# Checking destination path
2931rpath=$( readlink -f " $dst_dir " )
3032if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
33+ echo " Error: invalid destination path $dst_dir "
3134 exit 1
3235fi
3336
3437# Deleting directory
35- sudo -u $user rm -rf $dst_dir > /dev/null 2>&1
38+ sudo -u $user rm -rf " $dst_dir " # >/dev/null 2>&1
39+ if [ $? -ne 0 ]; then
40+ echo " Error: directory $dst_dir was not deleted"
41+ exit 3
42+ fi
3643
3744# Exiting
38- exit $?
45+ exit
Original file line number Diff line number Diff line change 1616
1717# Checking vesta user
1818if [ ! -e " $VESTA /data/users/$user " ]; then
19- exit 1
19+ echo " Error: vesta user $user doesn't exist"
20+ exit 3
2021fi
2122
2223# Checking user homedir
2324homedir=$( grep " ^$user :" /etc/passwd | cut -f 6 -d :)
2425if [ -z $homedir ]; then
25- exit 1
26+ echo " Error: user home directory doesn't exist"
27+ exit 12
2628fi
2729
2830# Checking destination path
2931rpath=$( readlink -f " $dst_file " )
3032if [ -z " $( echo $rpath | egrep " ^/tmp|^$homedir " ) " ]; then
31- exit 1
33+ echo " Error: invalid destination path $dst_file "
34+ exit 2
3235fi
3336
3437# Deleting file
35- sudo -u $user rm -f $dst_file > /dev/null 2>&1
38+ sudo -u $user rm -f " $dst_file " > /dev/null 2>&1
39+ if [ $? -ne 0 ]; then
40+ echo " Error: file $dst_file was not deleted"
41+ exit 3
42+ fi
3643
3744# Exiting
38- exit $?
45+ exit
You can’t perform that action at this time.
0 commit comments