v-add-fs-directory 896 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. # info: add directory
  3. # options: USER DIRECTORY
  4. #
  5. # The function creates new directory on the file system
  6. user=$1
  7. dst_dir=$2
  8. # Checking arguments
  9. if [ -z "$dst_dir" ]; then
  10. echo "Usage: USER DIRECTORY"
  11. exit 1
  12. fi
  13. # Checking vesta user
  14. if [ ! -e "$VESTA/data/users/$user" ]; then
  15. echo "Error: vesta user $user doesn't exist"
  16. exit 3
  17. fi
  18. # Checking user homedir
  19. homedir=$(grep "^$user:" /etc/passwd | cut -f 6 -d :)
  20. if [ -z $homedir ]; then
  21. echo "Error: user home directory doesn't exist"
  22. exit 12
  23. fi
  24. # Checking destination path
  25. rpath=$(readlink -f "$dst_dir")
  26. if [ -z "$(echo $rpath |egrep "^/tmp|^$homedir")" ]; then
  27. echo "Error: invalid destination path $dst_dir"
  28. exit 2
  29. fi
  30. # Adding directory
  31. sudo -u $user mkdir -p "$dst_dir" >/dev/null 2>&1
  32. if [ $? -ne 0 ]; then
  33. echo "Error: directory $dst_dir was not created"
  34. exit 3
  35. fi
  36. # Extiging
  37. exit