You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3KB

  1. #!/bin/bash
  2. echo "pamela_manager $@" >> /tmp/pamela.log
  3. # init sessions
  4. sdir=/tmp/.pamela_sessions
  5. mkdir -p $sdir
  6. chmod -R 700 $sdir
  7. #echo "$sdir is initialized to 700"
  8. #chmod 700 /home/.pamela
  9. # init arguments
  10. action=$1
  11. user=$2
  12. if [ "$action" = "" ] || [ "$user" = "" ]; then
  13. echo "Not enough arguments (need 2 <action> <user>)"
  14. exit 1
  15. fi
  16. #echo "Parameters are $action and $user"
  17. # init dir arguments
  18. dir="/home/$user/private"
  19. usdir="$sdir/$user"
  20. if [ "$user" = "root" ]; then
  21. dir="/root/private"
  22. fi
  23. partition="/home/.pamela/$user"
  24. #echo "pamela_manager $action $user $dir $partition" >> /tmp/pamela.log
  25. #echo "pamela_manager $action $user $dir $partition"
  26. # execute script
  27. if [ "$action" = "open" ]; then
  28. [ -d $partition ] || mkdir -p $partition && chown $user $partition
  29. mkdir -p $dir && chown $user $dir
  30. if [ -f $usdir ] && [ "$(cat $usdir)" != "0" ]; then
  31. nb=$(cat $usdir)
  32. nb=$((nb+1))
  33. #echo $nb > $usdir
  34. echo "Already mounted. $nb times" >> /tmp/pamela.log
  35. else
  36. su -l $user -c "encfs $partition $dir" && echo 1 > $usdir && chmod go-xrw $partition
  37. fi
  38. elif [ "$action" = "close" ]; then
  39. nb=$(cat $usdir)
  40. if [ "$nb" -eq "1" ]; then
  41. #echo "rm $usdir" >> /tmp/logx
  42. su -l $user -c "fusermount -u $dir" && rm $usdir
  43. else
  44. nb=$((nb-1))
  45. #echo "$nb" > $usdir
  46. fi
  47. fi