Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #last UID/GID used
- cur_uid="/opt/user_setup/cur_uid"
- #List of used usernames
- usr_list="/opt/user_setup/usr_list"
- #Get Unused GID
- gid=$(($(cat $cur_id)+1))
- uid=$gid
- echo $gid > $cur_uid
- echo -n "Please enter the desired username: "
- read name
- if [ $name == "" ]; then
- echo "Cannot use an empty username"
- exit 1
- grep -i "$name" "$usr_list"
- elif [ $? == 0 ]; then
- echo "Username already in use"
- exit 1
- else
- #SSH to NFS to setup the user accounts
- echo "Setting up user account on NFS"
- ssh root@10.0.0.1 -c groupadd -g $gid $name
- ssh root@10.0.0.1 -c useradd -u $uid -g $gid -M -N $name
- #NFS and Webserver usernames should have same UID to allow access
- groupadd -g $gid $name
- #Remove "-Z guest_u" if not using selinux
- useradd -u $uid -g $gid -M -N -Z guest_u $name
- #chown the folders used for holding the files
- echo "Setting NFS user permissions"
- ssh root@10.0.0.1 -c mkdir /opt/backup/main/home/$name
- ssh root@10.0.0.1 -c chown $name:$name /opt/backup/main/home/$name
- #create the ftp users
- echo "Setting up pure-ftpd user"
- pure-pw useradd -u $uid -g $gid -d /opt/nfs/main/home/$name
- pure-pw mkdb
- #Create the Nginx virtual host
- echo "Setting up nginx"
- #/etc/nginx/vh_templates/default is available at http://pastebin.com/0LmnQ8dZ
- sed "s/_username_/$name/" /etc/nginx/vh_templates/default > /etc/nginx/sites/$name
- #Setup a php-fpm process for user
- echo "Setting up php"
- mkdir /opt/php/sesh/$name
- chown $name:$name /opt/php/sesh/$name
- #/etc/php-fpm.d/default is available at http://pastebin.com/BDeaZApF
- sed "s/_username_/$name/" /etc/php-fpm.d/default > /etc/php-fpm.d/$name.conf
- #Add username to the list of existing users
- echo "$name" > $usr_list
- #Restarting all services
- #Restart Varnish (clear cache)
- service varnish restart
- #Restart php-fpm
- service php-fpm restart
- #Restart Nginx
- service nginx restart
- fi
- echo "Setup Complete!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement