Last active
April 27, 2016 17:35
-
-
Save rudyryk/9197dbd561c8ce639722896bb9633bbd to your computer and use it in GitHub Desktop.
Quick setup scripts for Ubuntu 16.04 LTS Server and Python web applications (Nginx + PostgreSQL)
This file contains hidden or 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 | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES | |
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
# OTHER DEALINGS IN THE SOFTWARE. | |
# | |
# No Rights Reserved | |
# http://creativecommons.org/publicdomain/zero/1.0/ | |
# | |
# Run this script on fresh Ubuntu 16.04 LTS server | |
# under root user to prepare it for applications | |
# deployment. | |
# | |
read -r -p "Bootstrap server for application deployment? [Y/n] " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
echo "Starting..." | |
;; | |
*) | |
echo "Cancelled." | |
exit 0 | |
;; | |
esac | |
echo "Update repositories and setup utils" | |
apt-get update -y | |
apt-get install -y software-properties-common | |
echo "Remove Apache, we'll use Nginx" | |
apt-get remove -y apache2 | |
echo "Enable Universe repository" | |
add-apt-repository "deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) universe" | |
echo "Upgrade packages" | |
apt-get update -y | |
apt-get upgrade -y | |
echo "Install new packages" | |
apt-get install -y curl build-essential gcc gettext python3.5-dev \ | |
python3.5-venv python3-pip git-core liblcms2-dev libssl-dev \ | |
libffi-dev libfreetype6-dev libjpeg8-dev libpq-dev libtiff5-dev \ | |
libxml2-dev libxslt-dev postgresql-9.5 postgresql-client-9.5 \ | |
postgresql-contrib-9.5 zlib1g-dev nginx redis-server redis-tools \ | |
screen letsencrypt python-letsencrypt | |
echo "Rebuild locales" | |
locale-gen |
This file contains hidden or 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 | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES | |
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
# OTHER DEALINGS IN THE SOFTWARE. | |
# | |
# No Rights Reserved | |
# http://creativecommons.org/publicdomain/zero/1.0/ | |
# | |
# Run this script on Ubuntu 16.04 LTS server after init_server.sh | |
# under root user to prepare new user for applications deployment. | |
# | |
read -r -p "Setup new user for running an application? [Y/n] " response | |
case $response in | |
[yY][eE][sS]|[yY]) | |
echo "Starting..." | |
;; | |
*) | |
echo "Cancelled." | |
exit 0 | |
;; | |
esac | |
read -r -p "Enter username: " user | |
if [ -z "$user" ]; then | |
echo "Username is empty" | |
exit 0 | |
fi | |
echo "Creating new shell user $user..." | |
adduser $user | |
sudo -u $user ssh-keygen | |
cp ~/.ssh/authorized_keys /home/$user/.ssh/authorized_keys | |
chown $user:$user /home/$user/.ssh/authorized_keys | |
read -r -p "Enter new PostgreSQL password: " password | |
echo "Creating new database user..." | |
su -l postgres -c "createuser -dRS $user" | |
su -l postgres -c "psql -c \"ALTER ROLE $user WITH PASSWORD '$password';\"" | |
echo "127.0.0.1:*:*:$user:$password" > /home/$user/.pgpass | |
chown $user:$user /home/$user/.pgpass | |
chmod 600 /home/$user/.pgpass | |
echo "Please re-login under $user to setup application!" |
This file contains hidden or 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 | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | |
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | |
# IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES | |
# OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, | |
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | |
# OTHER DEALINGS IN THE SOFTWARE. | |
# | |
# No Rights Reserved | |
# http://creativecommons.org/publicdomain/zero/1.0/ | |
# | |
# Run this script on Ubuntu 16.04 LTS serverunder root user to get | |
# LetsEncrypt SSL certificate for domain. | |
# | |
read -r -p "Enter the domain name: " domain | |
letsencrypt certonly --webroot -w /var/www/html -d $domain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment