Last active
September 30, 2015 05:48
-
-
Save versae/1732441 to your computer and use it in GitHub Desktop.
Script to setup an account for cloned template virtual machines with Nginx and uWsgi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
server { | |
listen 80; | |
#server_name yourdomain.com; | |
access_log /home/template/log/access.log; | |
error_log /home/template/log/error.log; | |
location /static/admin { | |
alias /home/template/.virtualenvs/projectenv/lib/python2.7/site-packages/django/contrib/admin/media/; | |
} | |
location /static { | |
#autoindex on; | |
alias /home/template/www/static; | |
} | |
location /media { | |
alias /home/template/www/media; | |
} | |
location / { | |
uwsgi_pass unix:/home/template/run/uwsgi.sock; | |
include /etc/nginx/uwsgi_params; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Script to setup an account for cloned template virtual machines | |
# ------------------------------------------------------------------------- | |
# It may be necessary to remove the file /etc/udev/rules.d/70-persistent-net.rules as well | |
sudo echo "Starting setup..." | |
read -p "Enter username: " username | |
read -s -p "Enter password (be carefull, you will type it just one time): " password | |
echo "" | |
read -p "Enter hostname: " host | |
echo "" | |
read -p "Enter virtualenv name: " projectenv | |
echo "" | |
sudo egrep "^$username" /etc/passwd >/dev/null | |
if [ $? -eq 0 ]; then | |
echo "$username exists, aborting..." | |
echo "Please, run setup.sh and try again" | |
exit 1 | |
else | |
pass=$(perl -e 'print crypt($ARGV[0], "password")' $password) | |
sudo useradd -d /home/$username -s /bin/bash -U -m -p $pass $username | |
[ $? -eq 0 ] && echo "User has been added to system." || echo "Failed to add a user, exiting..." | |
fi | |
echo "Setting home..." | |
sudo usermod -a -G sudo $username | |
sudo cp /home/template/.bashrc.template "/home/$username/.bashrc" | |
sudo cp /home/template/.gitconfig "/home/$username/.gitconfig" | |
sudo cp /home/template/.gitignore "/home/$username/.gitignore" | |
sudo rpl "template" "$username" /home/template/README | |
sudo rpl "projectenv" "$projectenv" /home/template/README | |
echo "Setting webserver..." | |
sudo rpl "template" "$username" /etc/nginx/nginx.conf | |
rpl -q "template" "$username" /home/template/projectenv.conf | |
rpl -q "projectenv" "$projectenv" /home/template/projectenv.conf | |
sudo cp /home/template/projectenv.conf "/etc/nginx/sites-available/$projectenv" | |
sudo ln -s "/etc/nginx/sites-available/$projectenv" "/etc/nginx/sites-enabled/$projectenv" | |
sudo rm /etc/nginx/sites-enabled/default | |
sudo cp /home/template/README "/home/$username/README" | |
sudo mkdir "/home/$username/www" | |
sudo mkdir "/home/$username/run" | |
sudo mkdir "/home/$username/log" | |
rpl -q "template" "$username" /home/template/wsgi.py | |
rpl -q "projectenv" "$projectenv" /home/template/wsgi.py | |
sudo cp /home/template/wsgi.py "/home/$username/run/wsgi.py" | |
sudo rpl -q "template" "$username" /etc/init/uwsgi.conf | |
sudo rpl -q "projectenv" "$projectenv" /etc/init/uwsgi.conf | |
sudo su "$username" -lc ls | |
sudo su "$username" -lc "virtualenv /home/$username/.virtualenvs/$projectenv --no-site-packages" | |
sudo su "$username" -lc "pip install uwsgi -E /home/$username/.virtualenvs/$projectenv/" | |
echo "Setting system and server..." | |
sudo su "$username" -lc "ssh-keygen -t rsa" | |
sudo chown -R "$username.$username" "/home/$username" | |
sudo rpl "template" "$host" /etc/hosts | |
sudo rpl "template" "$host" /etc/hostname | |
sudo hostname $host | |
sudo rm /etc/ssh/ssh_host_* | |
sudo dpkg-reconfigure openssh-server | |
sudo userdel -r -f template | |
kill -HUP $PPID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And before restart: