Skip to content

Commit 15d1f4f

Browse files
committed
Improved file manager API functions
1 parent 7bc8af4 commit 15d1f4f

13 files changed

+292
-82
lines changed

bin/v-add-fs-archive

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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

bin/v-add-fs-directory

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,30 @@ fi
1515

1616
# Checking vesta user
1717
if [ ! -e "$VESTA/data/users/$user" ]; then
18-
exit 1
18+
echo "Error: vesta user $user doesn't exist"
19+
exit 3
1920
fi
2021

2122
# Checking user homedir
2223
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
2324
if [ -z $homedir ]; then
24-
exit 1
25+
echo "Error: user home directory doesn't exist"
26+
exit 12
2527
fi
2628

2729
# Checking destination path
2830
rpath=$(readlink -f "$dst_dir")
2931
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
30-
exit 1
32+
echo "Error: invalid destination path $dst_dir"
33+
exit 2
3134
fi
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

bin/v-add-fs-file

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,30 @@ fi
1515

1616
# Checking vesta user
1717
if [ ! -e "$VESTA/data/users/$user" ]; then
18-
exit 1
18+
echo "Error: vesta user $user doesn't exist"
19+
exit 3
1920
fi
2021

2122
# Checking user homedir
2223
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
2324
if [ -z $homedir ]; then
24-
exit 1
25+
echo "Error: user home directory doesn't exist"
26+
exit 12
2527
fi
2628

2729
# Checking destination path
2830
rpath=$(readlink -f "$dst_file")
2931
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
30-
exit 1
32+
echo "Error: invalid destination path $dst_dir"
33+
exit 2
3134
fi
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

bin/v-change-fs-file-permission

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,36 @@ fi
1616

1717
# Checking vesta user
1818
if [ ! -e "$VESTA/data/users/$user" ]; then
19-
exit 1
19+
echo "Error: vesta user $user doesn't exist"
20+
exit 3
2021
fi
2122

2223
# Checking user homedir
2324
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
2425
if [ -z $homedir ]; then
25-
exit 1
26+
echo "Error: user home directory doesn't exist"
27+
exit 12
2628
fi
2729

2830
# Checking source file
2931
if [ ! -f "$src_file" ]; then
30-
exit 1
32+
echo "Error: source file doesn't exist $src_file"
33+
exit 3
3134
fi
3235

3336
# Checking source path
3437
rpath=$(readlink -f "$src_file")
3538
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
36-
exit 1
39+
echo "Error: invalid source path $src_file"
40+
exit 2
3741
fi
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

bin/v-copy-fs-directory

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,43 @@ fi
1616

1717
# Checking vesta user
1818
if [ ! -e "$VESTA/data/users/$user" ]; then
19-
exit 1
19+
echo "Error: vesta user $user doesn't exist"
20+
exit 3
2021
fi
2122

2223
# Checking user homedir
2324
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
2425
if [ -z $homedir ]; then
25-
exit 1
26+
echo "Error: user home directory doesn't exist"
27+
exit 12
2628
fi
2729

2830
# Checking source dir
2931
if [ ! -e "$src_dir" ]; then
30-
exit 1
32+
echo "Error: source directory $src_dir doesn't exist"
33+
exit 3
3134
fi
3235

3336
# Checking source path
3437
rpath=$(readlink -f "$src_dir")
3538
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
36-
exit 1
39+
echo "Error: invalid source path $src_dir"
40+
exit 2
3741
fi
3842

3943
# Checking destination path
4044
rpath=$(readlink -f "$dst_dir")
4145
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
42-
exit 1
46+
echo "Error: invalid destination path $dst_dir"
47+
exit 2
4348
fi
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

bin/v-copy-fs-file

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,34 +16,43 @@ fi
1616

1717
# Checking vesta user
1818
if [ ! -e "$VESTA/data/users/$user" ]; then
19-
exit 1
19+
echo "Error: vesta user $user doesn't exist"
20+
exit 3
2021
fi
2122

2223
# Checking user homedir
2324
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
2425
if [ -z $homedir ]; then
25-
exit 1
26+
echo "Error: user home directory doesn't exist"
27+
exit 12
2628
fi
2729

2830
# Checking source file
2931
if [ ! -f "$src_file" ]; then
30-
exit 1
32+
echo "Error: $src_file doesn't exist"
33+
exit 3
3134
fi
3235

3336
# Checking source path
3437
rpath=$(readlink -f "$src_file")
3538
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
36-
exit 1
39+
echo "Error: invalid source path $src_file"
40+
exit 2
3741
fi
3842

3943
# Checking destination path
4044
rpath=$(readlink -f "$dst_file")
4145
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
42-
exit 1
46+
echo "Error: ivalid destination path $dst_file"
47+
exit 2
4348
fi
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
Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,30 @@ fi
1616

1717
# Checking vesta user
1818
if [ ! -e "$VESTA/data/users/$user" ]; then
19-
exit 1
19+
echo "Error: vesta user $user doesn't exist"
20+
exit 3
2021
fi
2122

2223
# Checking user homedir
2324
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
2425
if [ -z $homedir ]; then
25-
exit 1
26+
echo "Error: user home directory doesn't exist"
27+
exit 12
2628
fi
2729

2830
# Checking destination path
2931
rpath=$(readlink -f "$dst_dir")
3032
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
33+
echo "Error: invalid destination path $dst_dir"
3134
exit 1
3235
fi
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

bin/v-delete-fs-file

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,30 @@ fi
1616

1717
# Checking vesta user
1818
if [ ! -e "$VESTA/data/users/$user" ]; then
19-
exit 1
19+
echo "Error: vesta user $user doesn't exist"
20+
exit 3
2021
fi
2122

2223
# Checking user homedir
2324
homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
2425
if [ -z $homedir ]; then
25-
exit 1
26+
echo "Error: user home directory doesn't exist"
27+
exit 12
2628
fi
2729

2830
# Checking destination path
2931
rpath=$(readlink -f "$dst_file")
3032
if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
31-
exit 1
33+
echo "Error: invalid destination path $dst_file"
34+
exit 2
3235
fi
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

0 commit comments

Comments
 (0)