Files
django_installer/install.sh
2019-04-16 21:37:38 -04:00

233 lines
6.4 KiB
Bash
Executable File

#!/bin/bash
################################################################################s
# Dependencies
# Installs Dependencies automatically
################################################################################
# check if root
if [ $EUID -ne 0 ] ; then
echo -e "This script must be run as root"
exit 1
fi
# source vars
source vars
echo -e "Installing dependencies"
# create necessary dirs
if [ ! -d $logdir ] ; then
mkdir $logdir
fi;
# install dependencies
echo -e "\tRunning apt update";
apt update 1> $aptlogloc 2>> $aptlogloc 3>> $aptlogloc;
for package in ${packages[@]};
do
echo -e "\tInstalling $package"
apt install -y $package 1>> $aptlogloc 2>> $aptlogloc 3>> $aptlogloc
if [ $? -ne 0 ] ; then
echo -e "apt failed to install $package. $aptlogmsg"
exit 1
fi
done
###############################################################################
# Sqlite3
# Download and setup Sqlite3 and modules
################################################################################
echo -e "Installing Sqlite3"
if [ ! -d sqlite ] ; then
# fetch Sqlite
wget -O sqlite.tar.gz $sqlink 1> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "Failed to fetch sqlite, make sure wget is installed and $pylink is what you're after. $pylogmsg"
exit 1
fi
mkdir sqlite
tar xf sqlite.tar.gz -C sqlite --strip-components=1 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "Failed to unzip sqlite. $pylogmsg"
exit 1
fi
fi;
cd sqlite
if [ $? -ne 0 ] ; then
echo -e "Something went wrong while unzipping. $pylogmsg"
exit 1
fi
# install Sqlite3
echo -e "\tConfigure"
./configure 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "./configure failed. $pylogmsg"
exit 1
fi
echo -e "\tMake"
make 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "make failed. $pylogmsg"
exit 1
fi
echo -e "\tMake install"
make install 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "make install failed. $pylogmsg"
exit 1
fi
cd ..
rm sqlite.tar.gz 1>> $pylogloc 2>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "\tNot removing Sqlite3 tar.gz file."
fi
################################################################################
# Python
# Download and setup Python and modules
################################################################################
echo -e "Installing Python"
if [ ! -d python ] ; then
wget -O python.tar.gz $pylink 1> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "Failed to fetch python, make sure wget is installed and $pylink is what you're after. $pylogmsg"
exit 1
fi
mkdir python
tar xf python.tar.gz -C python --strip-components=1 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "Failed to unzip python. $pylogmsg"
exit 1
fi
fi
cd python
if [ $? -ne 0 ] ; then
echo -e "Something went wrong while unzipping. $pylogmsg"
exit 1
fi
# install Python
echo -e "\tConfigure"
./configure 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "./configure failed. $pylogmsg"
exit 1
fi
echo -e "\tMake"
make 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "make failed. $pylogmsg"
exit 1
fi
echo -e "\tMake install"
make install 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "make install failed. $pylogmsg"
exit 1
fi
# upgrade pip and install virtualenv
echo -e "\tUpgrading pip"
python3 -m pip install --upgrade pip 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "pip upgrade failed. $pylogmsg"
exit 1
fi
echo -e "\tInstalling virtualenv"
python3 -m pip install virtualenv 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "installing virtualenv failed. $pylogmsg"
exit 1
fi
cd ..
rm python.tar.gz 1>> $pylogloc 2>> $pylogloc
if [ $? -ne 0 ] ; then
echo -e "\tNot removing Python tar.gz file."
fi
# create the sites directory
echo -e "\tCreating project directory"
mkdir /sites/ 1>> $pylogloc 2>> $pylogloc 3>> $pylogloc
# ################################################################################
# # Gunicorn
# # configure gunicorn.conf file
# ################################################################################
# tput setaf 2
# echo -e "Setting up gunicorn"
# tput setaf 9
# echo -e "
# [Unit]
# Description=gunicorn daemon
# After=network.target
# [Service]
# User=$user
# Group=www-data
# WorkingDirectory=/home/$user/$projectname
# ExecStart=/home/$user/$projectname/venv/bin/gunicorn --workers 3 --bind unix:/home/$user/$projectname/$projectname.sock config.wsgi:application
# Environment=HOST=$hostname
# [Install]
# WantedBy=multi-user.target" > /etc/systemd/system/gunicorn.service
# echo -e "\tStarting gunicorn"
# systemctl daemon-reload > $gunicornlogloc
# systemctl start gunicorn >> $gunicornlogloc
# systemctl status gunicorn >> $gunicornlogloc
# echo -e "\tEnabling gunicorn at startup"
# systemctl enable gunicorn 1>> $gunicornlogloc 2>> $gunicornlogloc
# ################################################################################
# # Nginx
# # configure nginx
# ################################################################################
# tput setaf 2
# echo -e "Configuring Nginx"
# tput setaf 9
# echo -e "
# server {
# listen 80;
# server_name $hostname;
# location = /favicon.ico { access_log off; log_not_found off; }
# location /static/ {
# root /home/$user/$projectname;
# }
# location / {
# proxy_set_header Host \$http_host;
# proxy_set_header X-Real-IP \$remote_addr;
# proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
# proxy_set_header X-Forwarded-Proto \$scheme;
# proxy_pass http://unix:/home/$user/$projectname/$projectname.sock;
# }
# }" > /etc/nginx/conf.d/$projectname.conf
# # set the nginx user
# if [ ! $user = "nginx" ] ; then
# sed -i "s/user nginx/user $user nginx/" /etc/nginx/nginx.conf
# fi
# echo -e "\tStarting nginx"
# systemctl restart nginx >> $nginxlogloc
# systemctl status nginx >> $nginxlogloc
# echo -e "\tEnabling nginx"
# systemctl enable nginx 1>> $nginxlogloc 2>> $nginxlogloc
# tput setaf 2
# echo -e "Done! Navigate to $hostname to access the site. Logs can be found in $logdir"
# tput setaf 9
# exit 0