Advertisement
sandyd

Nginx + Pure-ftpd virtual host setup tool

Jul 26th, 2012
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.93 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #last UID/GID used
  4. cur_uid="/opt/user_setup/cur_uid"
  5.  
  6. #List of used usernames
  7. usr_list="/opt/user_setup/usr_list"
  8.  
  9. #Get Unused GID
  10. gid=$(($(cat $cur_id)+1))
  11.  
  12. uid=$gid
  13. echo $gid > $cur_uid
  14.  
  15. echo -n "Please enter the desired username: "
  16. read name
  17.  
  18. if [ $name == "" ]; then
  19.     echo "Cannot use an empty username"
  20.     exit 1
  21.  
  22. grep -i "$name" "$usr_list"
  23.  
  24. elif    [ $? == 0 ]; then
  25.     echo "Username already in use"
  26.     exit 1
  27. else
  28.     #SSH to NFS to setup the user accounts
  29.     echo "Setting up user account on NFS"
  30.     ssh root@10.0.0.1 -c groupadd -g $gid $name
  31.     ssh root@10.0.0.1 -c useradd -u $uid -g $gid -M -N $name
  32.  
  33.     #NFS and Webserver usernames should have same UID to allow access
  34.     groupadd -g $gid $name
  35.     #Remove "-Z guest_u" if not using selinux
  36.     useradd -u $uid -g $gid -M -N -Z guest_u $name
  37.  
  38.     #chown the folders used for holding the files
  39.     echo "Setting NFS user permissions"
  40.     ssh root@10.0.0.1 -c mkdir /opt/backup/main/home/$name
  41.     ssh root@10.0.0.1 -c chown $name:$name /opt/backup/main/home/$name
  42.  
  43.     #create the ftp users
  44.     echo "Setting up pure-ftpd user"
  45.     pure-pw useradd -u $uid -g $gid -d /opt/nfs/main/home/$name
  46.     pure-pw mkdb
  47.    
  48.     #Create the Nginx virtual host
  49.     echo "Setting up nginx"
  50.     #/etc/nginx/vh_templates/default is available at http://pastebin.com/0LmnQ8dZ
  51.     sed "s/_username_/$name/" /etc/nginx/vh_templates/default > /etc/nginx/sites/$name
  52.  
  53.     #Setup a php-fpm process for user
  54.     echo "Setting up php"
  55.     mkdir /opt/php/sesh/$name
  56.     chown $name:$name /opt/php/sesh/$name
  57.     #/etc/php-fpm.d/default is available at http://pastebin.com/BDeaZApF
  58.     sed "s/_username_/$name/" /etc/php-fpm.d/default > /etc/php-fpm.d/$name.conf
  59.    
  60.     #Add username to the list of existing users
  61.     echo "$name" > $usr_list
  62.  
  63.     #Restarting all services
  64.    
  65.     #Restart Varnish (clear cache)
  66.     service varnish restart
  67.  
  68.     #Restart php-fpm
  69.     service php-fpm restart
  70.  
  71.     #Restart Nginx
  72.     service nginx restart
  73. fi
  74. echo "Setup Complete!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement