<commit_before>#!/bin/bash
# Author <NAME> Django developer
VERSION="0.1"
ERROR_STATUS=0
CONF_ROOT=/root/django_deployment_tool
POSTGRESQL_USER=postgres
# POSTGRESQL_CLUSTER_VERSION="$(sudo pg_lsclusters | egrep -o '[0-9]{1,}\.[0-9]{1,}' | (read a; echo $a;))" # $(pg_config --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
POSTGRESQL_UPGRADE_TO=9.5



function usage {
    echo -e "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"
    echo -e "\t Django Deployment Tool v$VERSION"
    echo -e "\t <NAME> - <EMAIL>"
    echo -e "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"
    echo -e "Usage: bash $0 <COMMAND>"
    echo -e "\nCommands:"

    echo -e "\t usage \t\t\t\t - For helping available commands to use"
    echo -e "\t deploy \t\t\t\t - Base command to deployment"
    echo -e "\t status \t\t\t\t - Show status of deployment"
    echo -e "\t delete \t\t\t - Delete DB"
    echo -e "\t create \t\t\t - Create DB"
    echo -e "\t upgrade \t\t\t - Upgrade cluster version of PostgreSQL to $POSTGRESQL_UPGRADE_TO"
    echo -e "\t dump <DIR> \t\t\t - Dump DB to given folder"
    echo -e "\t restore <SRC> \t\t\t - Restore DB from given SQL file"

    exit 1
}

function deployment_status() {
    . $CONF_ROOT/config.txt
    if [[ $APP_USER && $APP_USER_PASSWORD ]]; then
        echo -e "Current deploy status:"
        echo -e "\n"
        echo -e "\nDjango\t\t\t\t\tAlready Deploy"
        echo -e "\n"
        echo -e "The Application is ready to use please use"
        echo -e "Change the user by command sudo su - $APP_USER"
    else
        echo -e "Current deploy status:"
        echo -e "\n"
        echo -e "Django\t\t\t\t\tnot deploy"
        echo -e "\n"
        echo -e "The Application is not Deploy please use ./deploy.sh deploy"
    fi


}


function get_user_credential {
    . $CONF_ROOT/status.txt
    . $CONF_ROOT/config.txt
    if [ $INSTALLATION_STEP ]; then
        echo -e "Check the installation step .........."
        sleep 3
        echo -e "\e[32mInstallation step ....................... [OK]\e[0m"
    else
        echo -e "Ubuntu Update apt package ...."
        chmod +x config.txt
        chmod +x status.txt
        echo -e "Installing python2 pip and depencies ..."
        apt-get -y update
        apt-get -y install python-pip python-dev libpq-dev postgresql postgresql-contrib nginx gettext
        apt-get -y update
        echo -e "Installing python3 pip and depencies ..."
        apt-get -y install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx
        apt-get -y install python3-venv
        echo -e "Installing Pillow for $(uname -a)"
        apt-get -y install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
        apt-get -y install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
        echo "INSTALLATION_STEP=True" >> "$CONF_ROOT/status.txt"
    fi
    if [ $CREATE_LINUX_USER_STEP ]; then
        echo -e "Check Linux user ............"
        sleep 3
        echo -e "\e[32mLinux User step ......................... [OK]\e[0m"
    else
        echo -e "Creating new User for $(uname -a)"
        echo "APP_SERVER=$(curl -4 https://icanhazip.com/)" >> "$CONF_ROOT/config.txt"
        echo -e "Please write New Linux User name and password"
        read -p "Please enter your linux username: " APP_USER
        while true ; do
        if [ $APP_USER ]; then
            break
        fi
        read -p "Please enter your linux username: " APP_USER
        done
        echo "APP_USER=$APP_USER" >> "$CONF_ROOT/config.txt"
        echo -e "Please enter your linux user password: "
        echo -n "Password :"
        read -s APP_USER_PASSWORD
        while true ; do
        if [ $APP_USER_PASSWORD ]; then
            break
        fi
        echo -n "Password :"
        read -s APP_USER_PASSWORD
        done
        echo "APP_USER_PASSWORD=$<PASSWORD>" >> "$CONF_ROOT/config.txt"
        echo "CREATE_LINUX_USER_STEP=True" >> "$CONF_ROOT/status.txt"
    fi
}


function fix_perl_locale_error() {
    echo -e "Fixing perl  warning: Setting locale error..."
    uname -a
    perl -e exit
    export LANGUAGE=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    export LC_TYPE=en_US.UTF-8
}

function  create_new_linux_user {
    . $CONF_ROOT/config.txt
    if [ $ALREADY_CREATE_USER ] ; then
        echo -e "Already You was created New user with Bellow credential"
        echo -e "\t Username : \t - $APP_USER"
        echo -e "\t Password : \t - $<PASSWORD>"
        echo -e "\t Created time \t - $(date)"
    else
        echo -e "Creating New Linux User please wait .."
        pass=$(perl -e 'print crypt($ARGV[0], "password")' $APP_USER_PASSWORD)
        useradd -m -p $pass $APP_USER
        echo -e "Users created and add to sudoers"
        echo "$APP_USER  ALL=(ALL:ALL) ALL" >> /etc/sudoers<commit_msg>Update version 1.5<commit_after>#!/bin/bash
# Author <NAME> Django developer
VERSION="1.5"
ERROR_STATUS=0
CONF_ROOT=/root/django_deployment_tool
POSTGRESQL_USER=postgres
# POSTGRESQL_CLUSTER_VERSION="$(sudo pg_lsclusters | egrep -o '[0-9]{1,}\.[0-9]{1,}' | (read a; echo $a;))" # $(pg_config --version | egrep -o '[0-9]{1,}\.[0-9]{1,}')
POSTGRESQL_UPGRADE_TO=9.5



function usage {
    echo -e "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"
    echo -e "\t Django Deployment Tool v$VERSION"
    echo -e "\t <NAME> - <EMAIL>"
    echo -e "-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=\n"
    echo -e "Usage: bash $0 <COMMAND>"
    echo -e "\nCommands:"

    echo -e "\t usage \t\t\t\t - For helping available commands to use"
    echo -e "\t deploy \t\t\t\t - Base command to deployment"
    echo -e "\t status \t\t\t\t - Show status of deployment"
    echo -e "\t delete \t\t\t - Delete DB"
    echo -e "\t create \t\t\t - Create DB"
    echo -e "\t upgrade \t\t\t - Upgrade cluster version of PostgreSQL to $POSTGRESQL_UPGRADE_TO"
    echo -e "\t dump <DIR> \t\t\t - Dump DB to given folder"
    echo -e "\t restore <SRC> \t\t\t - Restore DB from given SQL file"

    exit 1
}

function deployment_status() {
    . $CONF_ROOT/config.txt
    if [[ $APP_USER && $APP_USER_PASSWORD ]]; then
        echo -e "Current deploy status:"
        echo -e "\n"
        echo -e "\nDjango\t\t\t\t\tAlready Deploy"
        echo -e "\n"
        echo -e "The Application is ready to use please use"
        echo -e "Change the user by command sudo su - $APP_USER"
    else
        echo -e "Current deploy status:"
        echo -e "\n"
        echo -e "Django\t\t\t\t\tnot deploy"
        echo -e "\n"
        echo -e "The Application is not Deploy please use ./deploy.sh deploy"
    fi


}


function get_user_credential {
    . $CONF_ROOT/status.txt
    . $CONF_ROOT/config.txt
    if [ $INSTALLATION_STEP ]; then
        echo -e "Check the installation step .........."
        sleep 3
        echo -e "\e[32mInstallation step ....................... [OK]\e[0m"
    else
        echo -e "Ubuntu Update apt package ...."
        chmod +x config.txt
        chmod +x status.txt
        echo -e "Installing python2 pip and depencies ..."
        apt-get -y update
        apt-get -y install python-pip python-dev libpq-dev postgresql postgresql-contrib nginx gettext
        apt-get -y update
        echo -e "Installing python3 pip and depencies ..."
        apt-get -y install python3-pip python3-dev libpq-dev postgresql postgresql-contrib nginx
        apt-get -y install python3-venv
        echo -e "Installing Pillow for $(uname -a)"
        apt-get -y install libtiff5-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.6-dev tk8.6-dev python-tk
        apt-get -y install libtiff4-dev libjpeg8-dev zlib1g-dev libfreetype6-dev liblcms2-dev libwebp-dev tcl8.5-dev tk8.5-dev python-tk
        echo "INSTALLATION_STEP=True" >> "$CONF_ROOT/status.txt"
    fi
    if [ $CREATE_LINUX_USER_STEP ]; then
        echo -e "Check Linux user ............"
        sleep 3
        echo -e "\e[32mLinux User step ......................... [OK]\e[0m"
    else
        echo -e "Creating new User for $(uname -a)"
        echo "APP_SERVER=$(curl -4 https://icanhazip.com/)" >> "$CONF_ROOT/config.txt"
        echo -e "Please write New Linux User name and password"
        read -p "Please enter your linux username: " APP_USER
        while true ; do
        if [ $APP_USER ]; then
            break
        fi
        read -p "Please enter your linux username: " APP_USER
        done
        echo "APP_USER=$APP_USER" >> "$CONF_ROOT/config.txt"
        echo -e "Please enter your linux user password: "
        echo -n "Password :"
        read -s APP_USER_PASSWORD
        while true ; do
        if [ $APP_USER_PASSWORD ]; then
            break
        fi
        echo -n "Password :"
        read -s APP_USER_PASSWORD
        done
        echo "APP_USER_PASSWORD=$<PASSWORD>" >> "$CONF_ROOT/config.txt"
        echo "CREATE_LINUX_USER_STEP=True" >> "$CONF_ROOT/status.txt"
    fi
}


function fix_perl_locale_error() {
    echo -e "Fixing perl  warning: Setting locale error..."
    export LANGUAGE=en_US.UTF-8
    export LC_ALL=en_US.UTF-8
    export LANG=en_US.UTF-8
    export LC_TYPE=en_US.UTF-8
    uname -a
    perl -e exit
}

function  create_new_linux_user {
    . $CONF_ROOT/config.txt
    if [ $ALREADY_CREATE_USER ] ; then
        echo -e "Already You was created New user with Bellow credential"
        echo -e "\t Username : \t - $APP_USER"
        echo -e "\t Password : \t - $<PASSWORD>"
        echo -e "\t Created time \t - $(date)"
    else
        echo -e "Creating New Linux User please wait .."
        pass=$(perl -e 'print crypt($ARGV[0], "password")' $APP_USER_PASSWORD)
        useradd -m -p $pass $APP_USER
        echo -e "Users created and add to sudoers"
        echo "$APP_USER  ALL=(ALL:ALL) ALL" >> /etc/sudoers
{'fraction_non_alphanumeric': 0.1589569387551204, 'fraction_numerical': 0.011389749225696872, 'mean_word_length': 2.0296610169491527, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 43, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '278945', 'n_tokens_mistral': 3574, 'n_tokens_neox': 3378, 'n_words': 1021}