diff --git a/bin/v-add-fs-archive b/bin/v-add-fs-archive new file mode 100755 index 00000000..d61f3621 --- /dev/null +++ b/bin/v-add-fs-archive @@ -0,0 +1,59 @@ +#!/bin/bash +# info: archive directory +# options: USER ARCHIVE DIRECTORY [DIRECTORY_N] +# +# The function creates tar archive + +user=$1 +archive=$2 +src1=$3 +src2=$4 +src3=$5 +src4=$6 +src5=$7 +src6=$8 +src7=$9 + +# Checking arguments +if [ -z "$src1" ]; then + echo "Usage: USER ARCHIVE DIRECTORY [DIRECTORY_N]" + exit 1 +fi + +# Checking vesta user +if [ ! -e "$VESTA/data/users/$user" ]; then + echo "Error: vesta user $user doesn't exist" + exit 3 +fi + +# Checking user homedir +homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) +if [ -z $homedir ]; then + echo "Error: user home directory doesn't exist" + exit 12 +fi + +# Checking archive +if [ -e "$archive.tar.gz" ]; then + echo "Error: archive already exist $archive.tar.gz" + exit 1 +fi + +# Checking source path +for src_path in $src1 $src2 $src3 $src4 $src5 $src6 $src7; do + rpath=$(readlink -f "$src_path") + if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then + echo "Error: invalid source path $src_path" + exit 1 + fi +done + +# Creating tar.gz archive +sudo -u $user tar -czf "$archive.tar.gz" \ + $src1 $src2 $src3 $src4 $src5 $src6 $src7 > /dev/null 2>&1 +if [ "$?" -ne 0 ]; then + echo "Error: archive $archive.tar.gz was not created" + exit 3 +fi + +exit diff --git a/bin/v-add-fs-directory b/bin/v-add-fs-directory index ead1640f..e507edf5 100755 --- a/bin/v-add-fs-directory +++ b/bin/v-add-fs-directory @@ -15,23 +15,30 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking destination path rpath=$(readlink -f "$dst_dir") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid destination path $dst_dir" + exit 2 fi # Adding directory -sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 +sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: directory $dst_dir was not created" + exit 3 +fi # Extiging -exit $? +exit diff --git a/bin/v-add-fs-file b/bin/v-add-fs-file index d173cda7..cc1621cc 100755 --- a/bin/v-add-fs-file +++ b/bin/v-add-fs-file @@ -15,23 +15,30 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking destination path rpath=$(readlink -f "$dst_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid destination path $dst_dir" + exit 2 fi # Creating file -sudo -u $user touch $dst_file >/dev/null 2>&1 +sudo -u $user touch "$dst_file" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: file $dst_file was not created" + exit 3 +fi # Exiting -exit $? +exit diff --git a/bin/v-change-fs-file-permission b/bin/v-change-fs-file-permission index ce5c923c..2b60865a 100755 --- a/bin/v-change-fs-file-permission +++ b/bin/v-change-fs-file-permission @@ -16,28 +16,36 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking source file if [ ! -f "$src_file" ]; then - exit 1 + echo "Error: source file doesn't exist $src_file" + exit 3 fi # Checking source path rpath=$(readlink -f "$src_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid source path $src_file" + exit 2 fi # Changing file permissions -sudo -u $user chmod $permisions $src_file >/dev/null 2>&1 +sudo -u $user chmod $permisions "$src_file" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: access permission on $src_file was not changed" + exit 3 +fi # Exiting -exit $? +exit diff --git a/bin/v-copy-fs-directory b/bin/v-copy-fs-directory index fd531ef1..11c647ed 100755 --- a/bin/v-copy-fs-directory +++ b/bin/v-copy-fs-directory @@ -16,34 +16,43 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking source dir if [ ! -e "$src_dir" ]; then - exit 1 + echo "Error: source directory $src_dir doesn't exist" + exit 3 fi # Checking source path rpath=$(readlink -f "$src_dir") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid source path $src_dir" + exit 2 fi # Checking destination path rpath=$(readlink -f "$dst_dir") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid destination path $dst_dir" + exit 2 fi # Copying directory -sudo -u $user cp -r $src_dir $dst_dir >/dev/null 2>&1 +sudo -u $user cp -r "$src_dir" "$dst_dir" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: directory $src_dir was not copied" + exit 3 +fi # Exiting -exit $? +exit diff --git a/bin/v-copy-fs-file b/bin/v-copy-fs-file index 4f971ec9..792956ec 100755 --- a/bin/v-copy-fs-file +++ b/bin/v-copy-fs-file @@ -16,34 +16,43 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking source file if [ ! -f "$src_file" ]; then - exit 1 + echo "Error: $src_file doesn't exist" + exit 3 fi # Checking source path rpath=$(readlink -f "$src_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid source path $src_file" + exit 2 fi # Checking destination path rpath=$(readlink -f "$dst_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: ivalid destination path $dst_file" + exit 2 fi # Copying file -sudo -u $user cp $src_file $dst_file >/dev/null 2>&1 +sudo -u $user cp "$src_file" "$dst_file" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: file $src_file was not copied" + exit 3 +fi # Exiting -exit $? +exit diff --git a/bin/v-delete-fs-dir b/bin/v-delete-fs-directory similarity index 64% rename from bin/v-delete-fs-dir rename to bin/v-delete-fs-directory index 258c5e9c..b1cedde7 100755 --- a/bin/v-delete-fs-dir +++ b/bin/v-delete-fs-directory @@ -16,23 +16,30 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking destination path rpath=$(readlink -f "$dst_dir") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then + echo "Error: invalid destination path $dst_dir" exit 1 fi # Deleting directory -sudo -u $user rm -rf $dst_dir >/dev/null 2>&1 +sudo -u $user rm -rf "$dst_dir" # >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: directory $dst_dir was not deleted" + exit 3 +fi # Exiting -exit $? +exit diff --git a/bin/v-delete-fs-file b/bin/v-delete-fs-file index 785ed98b..bca18ff0 100755 --- a/bin/v-delete-fs-file +++ b/bin/v-delete-fs-file @@ -16,23 +16,30 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking destination path rpath=$(readlink -f "$dst_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid destination path $dst_file" + exit 2 fi # Deleting file -sudo -u $user rm -f $dst_file >/dev/null 2>&1 +sudo -u $user rm -f "$dst_file" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: file $dst_file was not deleted" + exit 3 +fi # Exiting -exit $? +exit diff --git a/bin/v-extract-fs-archive b/bin/v-extract-fs-archive index 1c78c1da..ec70baba 100755 --- a/bin/v-extract-fs-archive +++ b/bin/v-extract-fs-archive @@ -16,85 +16,104 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking source dir if [ ! -e "$src_file" ]; then - exit 1 + echo "Error: source file $src_file doesn't exist" + exit 3 fi # Checking source path rpath=$(readlink -f "$src_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid source path $src_file" + exit 2 fi # Checking destination path rpath=$(readlink -f "$dst_dir") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid destination path $dst_dir" + exit 2 fi # Extracting gziped archive if [ ! -z "$(echo $src_file |egrep -i '.tgz|.tar.gz')" ]; then x='yes' - sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 - sudo -u $user tar -xzf $src_file -C $dst_dir >/dev/null 2>&1 + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user tar -xzf "$src_file" -C "$dst_dir" >/dev/null 2>&1 rc=$? fi # Extracting bziped archive if [ ! -z "$(echo $src_file |egrep -i '.tbz|.tar.bz')" ]; then x='yes' - sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 - sudo -u $user tar -xjf $src_file -C $dst_dir >/dev/null 2>&1 + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user tar -xjf "$src_file" -C "$dst_dir" >/dev/null 2>&1 rc=$? fi # Extracting gziped file if [ ! -z "$(echo $src_file |grep -i '.gz')" ] && [ -z "$x" ]; then - sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 - sudo -u $user mv $src_file $dst_dir >/dev/null 2>&1 - sudo -u $user gzip -d $dst_dir/$(basename $src_file) >/dev/null 2>&1 + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user mv "$src_file" "$dst_dir" >/dev/null 2>&1 + sudo -u $user gzip -d "$dst_dir/$(basename $src_file)" >/dev/null 2>&1 rc=$? fi # Extracting bziped file if [ ! -z "$(echo $src_file |grep -i '.bz')" ] && [ -z "$x" ]; then - sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 - sudo -u $user mv $src_file $dst_dir >/dev/null 2>&1 - sudo -u $user bzip2 -d $dst_dir/$(basename $src_file) >/dev/null 2>&1 + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user mv "$src_file" "$dst_dir"# >/dev/null 2>&1 + sudo -u $user bzip2 -d "$dst_dir/$(basename $src_file)" >/dev/null 2>&1 rc=$? fi # Extracting ziped archive if [ ! -z "$(echo $src_file |grep -i '.zip')" ]; then - sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 - sudo -u $user unzip $src_file -d $dst_dir >/dev/null 2>&1 + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user unzip "$src_file" -d "$dst_dir" >/dev/null 2>&1 + rc=$? +fi + +# Extracting ziped archive +if [ ! -z "$(echo $src_file |grep -i '.7z')" ]; then + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user mv "$src_file" "$dst_dir" >/dev/null 2>&1 + sudo -u $user p7zip -d "$src_file" >/dev/null 2>&1 rc=$? fi # Extracting tared archive if [ ! -z "$(echo $src_file |grep -i '.tar')" ] && [ -z "$x" ]; then x='yes' - sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 - sudo -u $user tar -xf $src_file -C $dst_dir >/dev/null 2>&1 + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user tar -xf "$src_file" -C "$dst_dir" >/dev/null 2>&1 rc=$? fi # Extracting rared archive if [ ! -z "$(echo $src_file |grep -i '.rar')" ]; then - sudo -u $user mkdir -p $dst_dir >/dev/null 2>&1 - sudo -u $user unrar $src_file $dst_dir >/dev/null 2>&1 + sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1 + sudo -u $user unrar "$src_file" "$dst_dir" >/dev/null 2>&1 rc=$? fi +# Checking result +if [ $rc -ne 0 ]; then + echo "Error: $src_file was not extracted" + exit 3 +fi + # Exiting -exit $rc +exit diff --git a/bin/v-list-fs-directory b/bin/v-list-fs-directory index bf4777e8..05b7e521 100755 --- a/bin/v-list-fs-directory +++ b/bin/v-list-fs-directory @@ -15,20 +15,23 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking path if [ ! -z "$path" ]; then rpath=$(readlink -f "$path") if [ -z "$(echo $rpath |grep $homedir)" ]; then - exit 1 + echo "Error: invalid path $dst_dir" + exit 2 fi else path=$homedir diff --git a/bin/v-move-fs-directory b/bin/v-move-fs-directory new file mode 100755 index 00000000..f101d995 --- /dev/null +++ b/bin/v-move-fs-directory @@ -0,0 +1,59 @@ +#!/bin/bash +# info: move file +# options: USER SRC_DIRECTORY DST_DIRECTORY +# +# The function moved file or directory on the file system. This function +# can also be used to rename files just like normal mv command. + +user=$1 +src_dir=$2 +dst_dir=$3 + +# Checking arguments +if [ -z "$dst_dir" ]; then + echo "Usage: USER SRC_DIRECTORY DST_DIRECTORY" + exit 1 +fi + +# Checking vesta user +if [ ! -e "$VESTA/data/users/$user" ]; then + echo "Error: vesta user $user doesn't exist" + exit 3 +fi + +# Checking user homedir +homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) +if [ -z $homedir ]; then + echo "Error: user home directory doesn't exist" + exit 12 +fi + +# Checking source file +if [ ! -d "$src_dir" ]; then + echo "Error: source directory $src_dir doesn't exist" + exit 3 +fi + +# Checking source path +rpath=$(readlink -f "$src_dir") +if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then + echo "Error: invalid source path $src_dir" + exit 2 +fi + +# Checking destination path +rpath=$(readlink -f "$dst_dir") +if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then + echo "Error: invalid destination path $dst_dir" + exit 2 +fi + +# Moving directory +sudo -u $user mv "$src_dir" "$dst_dir" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: directory $src_dir was not moved" + exit 3 +fi + +# Exiting +exit diff --git a/bin/v-move-fs-file b/bin/v-move-fs-file index ff9fb7d9..3671e0e5 100755 --- a/bin/v-move-fs-file +++ b/bin/v-move-fs-file @@ -17,34 +17,43 @@ fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking source file if [ ! -f "$src_file" ]; then - exit 1 + echo "Error: source file $src_file doesn't exist" + exit 3 fi # Checking source path rpath=$(readlink -f "$src_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid source path $src_file" + exit 2 fi # Checking destination path rpath=$(readlink -f "$dst_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid destination path $dst_file" + exit 2 fi -# Copying file -sudo -u $user mv $src_file $dst_file >/dev/null 2>&1 +# Moving file +sudo -u $user mv "$src_file" "$dst_file" >/dev/null 2>&1 +if [ $? -ne 0 ]; then + echo "Error: file $src_file was not moved" + exit 3 +fi # Exiting -exit $? +exit diff --git a/bin/v-open-fs-file b/bin/v-open-fs-file index 68eeb6a9..b04ad493 100755 --- a/bin/v-open-fs-file +++ b/bin/v-open-fs-file @@ -5,35 +5,42 @@ # The function opens/reads files on the file system user=$1 -path=$2 +src_file=$2 # Checking arguments -if [ -z "$path" ]; then - echo "Usage: USER PATH" +if [ -z "$src_file" ]; then + echo "Usage: USER FILE" exit 1 fi # Checking vesta user if [ ! -e "$VESTA/data/users/$user" ]; then - exit 1 + echo "Error: vesta user $user doesn't exist" + exit 3 fi # Checking user homedir homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :) if [ -z $homedir ]; then - exit 1 + echo "Error: user home directory doesn't exist" + exit 12 fi # Checking path -if [ ! -z "$path" ]; then - rpath=$(readlink -f "$path") +if [ ! -z "$src_file" ]; then + rpath=$(readlink -f "$src_file") if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then - exit 1 + echo "Error: invalid source path $src_file" + exit 2 fi fi # Reading file -sudo -u $user cat "$path" +sudo -u $user cat "$src_file" 2>/dev/null +if [ $? -ne 0 ]; then + echo "Error: file $src_file was not opened" + exit 3 +fi # Exiting -exit $? +exit