Skip to content
Snippets Groups Projects
freedombone-app-akaunting 16.4 KiB
Newer Older
Bob Mottram's avatar
Bob Mottram committed
#!/bin/bash
Bob Mottram's avatar
Bob Mottram committed
#  _____               _           _
# |   __|___ ___ ___ _| |___ _____| |_ ___ ___ ___
# |   __|  _| -_| -_| . | . |     | . | . |   | -_|
# |__|  |_| |___|___|___|___|_|_|_|___|___|_|_|___|
Bob Mottram's avatar
Bob Mottram committed
#
Bob Mottram's avatar
Bob Mottram committed
#                              Freedom in the Cloud
Bob Mottram's avatar
Bob Mottram committed
#
# Personal or small business accounts
#
# License
# =======
#
Bob Mottram's avatar
Bob Mottram committed
# Copyright (C) 2018 Bob Mottram <bob@freedombone.net>
Bob Mottram's avatar
Bob Mottram committed
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

VARIANTS='full full-vim media'

IN_DEFAULT_INSTALL=0
SHOW_ON_ABOUT=1

Bob Mottram's avatar
Bob Mottram committed
APP_CATEGORY=office

Bob Mottram's avatar
Bob Mottram committed
AKAUNTING_DOMAIN_NAME=
AKAUNTING_CODE=
AKAUNTING_ONION_PORT=8341
AKAUNTING_REPO="https://github.com/akaunting/akaunting"
Bob Mottram's avatar
Bob Mottram committed
AKAUNTING_COMMIT='398c8d38a6b75e68f7651ecb5ffb896a63e49e8a'
Bob Mottram's avatar
Bob Mottram committed
AKAUNTING_ADMIN_PASSWORD=

AKAUNTING_BACKGROUND_IMAGE_URL=

AKAUNTING_SHORT_DESCRIPTION=$'Personal accounting'
AKAUNTING_DESCRIPTION=$'Personal or small business accounting'
AKAUNTING_MOBILE_APP_URL=

Bob Mottram's avatar
Bob Mottram committed
akaunting_variables=(ONION_ONLY
                     AKAUNTING_DOMAIN_NAME
                     AKAUNTING_CODE
                     DDNS_PROVIDER
                     MY_USERNAME)

function akaunting_remove_bad_links {
Bob Mottram's avatar
Bob Mottram committed
    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 365873658

    # copy jquery locally
    jquery_version='1.12.4'
    if [ ! -f jquery-${jquery_version}.js ]; then
Bob Mottram's avatar
Bob Mottram committed
        cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 3276324
        wget https://code.jquery.com/jquery-${jquery_version}.js
        jquery_hash=$(sha256sum jquery-${jquery_version}.js | awk -F ' ' '{print $1}')
        if [[ "$jquery_hash" != '430f36f9b5f21aae8cc9dca6a81c4d3d84da5175eaedcf2fdc2c226302cb3575' ]]; then
            echo $'Unexpected jquery hash value'
            exit 78363527
        fi
    fi

    sed -i '/googleapi/d' resources/assets/sass/app.scss
    sed -i "s|ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js|$AKAUNTING_DOMAIN_NAME/jquery-${jquery_version}.js|g" vendor/league/flysystem/docs/_layouts/default.html
    sed -i '/googleapi/d' vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views/503.blade.php
    sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/build/less/AdminLTE-without-plugins.less
    sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/build/less/AdminLTE.less
    sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/dist/css/AdminLTE.css
    sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/dist/css/AdminLTE.min.css
    sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/dist/css/alt/AdminLTE-without-plugins.css
    sed -i '/googleapi/d' vendor/almasaeed2010/adminlte/dist/css/alt/AdminLTE-without-plugins.min.css
    sed -i "s|ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js|$AKAUNTING_DOMAIN_NAME/jquery-${jquery_version}.js|g" vendor/almasaeed2010/adminlte/plugins/ckeditor/samples/old/jquery.html

Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
Bob Mottram's avatar
Bob Mottram committed
function logging_on_akaunting {
    echo -n ''
}

function logging_off_akaunting {
    echo -n ''
}

function remove_user_akaunting {
    remove_username="$1"

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$remove_username" --rmapp akaunting
Bob Mottram's avatar
Bob Mottram committed
}

function add_user_akaunting {
    new_username="$1"
    new_user_password="$2"

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$new_username" -a akaunting -p "$new_user_password"
Bob Mottram's avatar
Bob Mottram committed

    echo '0'
}

function install_interactive_akaunting {
Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$ONION_ONLY" ]; then
Bob Mottram's avatar
Bob Mottram committed
        ONION_ONLY='no'
    fi

Bob Mottram's avatar
Bob Mottram committed
    if [[ "$ONION_ONLY" != "no" ]]; then
Bob Mottram's avatar
Bob Mottram committed
        AKAUNTING_DOMAIN_NAME='akaunting.local'
    else
        AKAUNTING_DETAILS_COMPLETE=
        while [ ! $AKAUNTING_DETAILS_COMPLETE ]
        do
Bob Mottram's avatar
Bob Mottram committed
            data=$(mktemp 2>/dev/null)
            if [[ $DDNS_PROVIDER == *"freedns"* ]]; then
Bob Mottram's avatar
Bob Mottram committed
                dialog --backtitle $"Freedombone Configuration" \
                       --title $"Akaunting Configuration" \
Bob Mottram's avatar
Bob Mottram committed
                       --form $"\\nPlease enter your Akaunting details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
Bob Mottram's avatar
Bob Mottram committed
                       $"Domain:" 1 1 "$(grep 'AKAUNTING_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
                       $"Code:" 2 1 "$(grep 'AKAUNTING_CODE' temp.cfg | awk -F '=' '{print $2}')" 2 25 33 255 \
Bob Mottram's avatar
Bob Mottram committed
                       2> "$data"
Bob Mottram's avatar
Bob Mottram committed
            else
                dialog --backtitle $"Freedombone Configuration" \
                       --title $"Akaunting Configuration" \
Bob Mottram's avatar
Bob Mottram committed
                       --form $"\\nPlease enter your Akaunting details.\\n\\nIMPORTANT: This should be a domain name which is supported by Let's Encrypt:" 14 65 2 \
Bob Mottram's avatar
Bob Mottram committed
                       $"Domain:" 1 1 "$(grep 'AKAUNTING_DOMAIN_NAME' temp.cfg | awk -F '=' '{print $2}')" 1 25 33 40 \
Bob Mottram's avatar
Bob Mottram committed
                       2> "$data"
Bob Mottram's avatar
Bob Mottram committed
            fi
            sel=$?
            case $sel in
Bob Mottram's avatar
Bob Mottram committed
                1) rm -f "$data"
                   exit 1;;
                255) rm -f "$data"
                     exit 1;;
Bob Mottram's avatar
Bob Mottram committed
            esac
Bob Mottram's avatar
Bob Mottram committed
            AKAUNTING_DOMAIN_NAME=$(sed -n 1p < "$data")
            if [ "$AKAUNTING_DOMAIN_NAME" ]; then
Bob Mottram's avatar
Bob Mottram committed
                if [[ $AKAUNTING_DOMAIN_NAME == "$HUBZILLA_DOMAIN_NAME" ]]; then
                    AKAUNTING_DOMAIN_NAME=""
                fi
                TEST_DOMAIN_NAME=$AKAUNTING_DOMAIN_NAME
                validate_domain_name
Bob Mottram's avatar
Bob Mottram committed
                if [[ "$TEST_DOMAIN_NAME" != "$AKAUNTING_DOMAIN_NAME" ]]; then
Bob Mottram's avatar
Bob Mottram committed
                    AKAUNTING_DOMAIN_NAME=
                    dialog --title $"Domain name validation" --msgbox "$TEST_DOMAIN_NAME" 15 50
                else
                    if [[ $DDNS_PROVIDER == *"freedns"* ]]; then
Bob Mottram's avatar
Bob Mottram committed
                        AKAUNTING_CODE=$(sed -n 2p < "$data")
Bob Mottram's avatar
Bob Mottram committed
                        validate_freedns_code "$AKAUNTING_CODE"
Bob Mottram's avatar
Bob Mottram committed
                        if [ ! "$VALID_CODE" ]; then
Bob Mottram's avatar
Bob Mottram committed
                            AKAUNTING_DOMAIN_NAME=
                        fi
                    fi
                fi
            fi
            if [ $AKAUNTING_DOMAIN_NAME ]; then
                AKAUNTING_DETAILS_COMPLETE="yes"
            fi
Bob Mottram's avatar
Bob Mottram committed
            rm -f "$data"
Bob Mottram's avatar
Bob Mottram committed
        done

        write_config_param "AKAUNTING_CODE" "$AKAUNTING_CODE"
    fi
    write_config_param "AKAUNTING_DOMAIN_NAME" "$AKAUNTING_DOMAIN_NAME"
    APP_INSTALLED=1
}

function change_password_akaunting {
    curr_username="$1"
    new_user_password="$2"

    read_config_param 'AKAUNTING_DOMAIN_NAME'

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$curr_username" -a akaunting -p "$new_user_password"
Bob Mottram's avatar
Bob Mottram committed
}

function akaunting_create_database {
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "$IMAGE_PASSWORD_FILE" ]; then
        AKAUNTING_ADMIN_PASSWORD="$(printf "%s" "$(cat "$IMAGE_PASSWORD_FILE")")"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        if [ ! "$AKAUNTING_ADMIN_PASSWORD" ]; then
            AKAUNTING_ADMIN_PASSWORD="$(create_password "${MINIMUM_PASSWORD_LENGTH}")"
Bob Mottram's avatar
Bob Mottram committed
        fi
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$AKAUNTING_ADMIN_PASSWORD" ]; then
Bob Mottram's avatar
Bob Mottram committed
        return
    fi

    function_check create_database
Bob Mottram's avatar
Bob Mottram committed
    create_database akaunting "$AKAUNTING_ADMIN_PASSWORD" "$MY_USERNAME"
Bob Mottram's avatar
Bob Mottram committed
}

function reconfigure_akaunting {
    echo -n ''
}

function upgrade_akaunting {
    CURR_AKAUNTING_COMMIT=$(get_completion_param "akaunting commit")
    if [[ "$CURR_AKAUNTING_COMMIT" == "$AKAUNTING_COMMIT" ]]; then
        return
    fi

Bob Mottram's avatar
Bob Mottram committed
    if grep -q "akaunting domain" "$COMPLETION_FILE"; then
Bob Mottram's avatar
Bob Mottram committed
        AKAUNTING_DOMAIN_NAME=$(get_completion_param "akaunting domain")
    fi

    # update to the next commit
    function_check set_repo_commit
Bob Mottram's avatar
Bob Mottram committed
    set_repo_commit "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" "akaunting commit" "$AKAUNTING_COMMIT" "$AKAUNTING_REPO"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 367835
    install_composer
    akaunting_remove_bad_links
Bob Mottram's avatar
Bob Mottram committed
    chown -R www-data:www-data "/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
Bob Mottram's avatar
Bob Mottram committed
}


function backup_local_akaunting {
Bob Mottram's avatar
Bob Mottram committed
    akaunting_path="/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
    if [ -d "$akaunting_path" ]; then
        suspend_site "${AKAUNTING_DOMAIN_NAME}"
        function_check backup_database_to_usb
        backup_database_to_usb akaunting
Bob Mottram's avatar
Bob Mottram committed
        backup_directory_to_usb "$akaunting_path" akaunting
        restart_site
    fi
Bob Mottram's avatar
Bob Mottram committed
}

function restore_local_akaunting {
    temp_restore_dir=/root/tempakaunting
Bob Mottram's avatar
Bob Mottram committed
    akaunting_dir="/var/www/${AKAUNTING_DOMAIN_NAME}/htdocs"
Bob Mottram's avatar
Bob Mottram committed
    suspend_site "${AKAUNTING_DOMAIN_NAME}"

    function_check akaunting_create_database
    akaunting_create_database

Bob Mottram's avatar
Bob Mottram committed
    restore_database akaunting "${AKAUNTING_DOMAIN_NAME}"
    chown www-data:www-data "$akaunting_dir"

    restart_site
Bob Mottram's avatar
Bob Mottram committed
}

function backup_remote_akaunting {
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
}

function restore_remote_akaunting {
    echo -n ''
Bob Mottram's avatar
Bob Mottram committed
}

function remove_akaunting {
    if [ ${#AKAUNTING_DOMAIN_NAME} -eq 0 ]; then
        return
    fi

    read_config_param "AKAUNTING_DOMAIN_NAME"
    read_config_param "MY_USERNAME"
    echo "Removing $AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    nginx_dissite "$AKAUNTING_DOMAIN_NAME"
    remove_certs "$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
    if [ -d "/var/www/$AKAUNTING_DOMAIN_NAME" ]; then
        rm -rf "/var/www/$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ -f "/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME" ]; then
        rm "/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
    function_check drop_database
    drop_database akaunting
    function_check remove_onion_service
Bob Mottram's avatar
Bob Mottram committed
    remove_onion_service akaunting "${AKAUNTING_ONION_PORT}"
Bob Mottram's avatar
Bob Mottram committed
    if grep -q "akaunting" /etc/crontab; then
        sed -i "/akaunting/d" /etc/crontab
    fi
    remove_app akaunting
    remove_completion_param install_akaunting
Bob Mottram's avatar
Bob Mottram committed
    sed -i '/akaunting/d' "$COMPLETION_FILE"
Bob Mottram's avatar
Bob Mottram committed

    function_check remove_ddns_domain
Bob Mottram's avatar
Bob Mottram committed
    remove_ddns_domain "$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
}

function install_akaunting {
    if [ ! $ONION_ONLY ]; then
        ONION_ONLY='no'
    fi

Bob Mottram's avatar
Bob Mottram committed
    if [ ! "$AKAUNTING_DOMAIN_NAME" ]; then
Bob Mottram's avatar
Bob Mottram committed
        echo $'No domain name was given for akaunting'
Bob Mottram's avatar
Bob Mottram committed
        exit 89353
Bob Mottram's avatar
Bob Mottram committed
    fi

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    function_check install_mariadb
    install_mariadb

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    function_check get_mariadb_password
    get_mariadb_password

    increment_app_install_progress

    $INSTALL_PACKAGES php-gettext php-curl php-gd php-mysql git curl

    increment_app_install_progress

    $INSTALL_PACKAGES memcached php-memcached php-intl exiftool libfcgi0ldbl

    increment_app_install_progress

    # shellcheck disable=SC2086
    $INSTALL_PACKAGES php${PHP_VERSION}-curl php${PHP_VERSION}-gd php${PHP_VERSION}-mbstring php${PHP_VERSION}-xml php${PHP_VERSION}-zip
Bob Mottram's avatar
Bob Mottram committed

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$AKAUNTING_DOMAIN_NAME" ]; then
        mkdir "/var/www/$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    if [ ! -d "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" ]; then
Bob Mottram's avatar
Bob Mottram committed
        if [ -d /repos/akaunting ]; then
Bob Mottram's avatar
Bob Mottram committed
            mkdir -p "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
Bob Mottram's avatar
Bob Mottram committed
            cp -r -p /repos/akaunting/. "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
            cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 23458735
Bob Mottram's avatar
Bob Mottram committed
            git pull
        else
            function_check git_clone
Bob Mottram's avatar
Bob Mottram committed
            git_clone "$AKAUNTING_REPO" "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
Bob Mottram's avatar
Bob Mottram committed
        fi

Bob Mottram's avatar
Bob Mottram committed
        if [ ! -d "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" ]; then
Bob Mottram's avatar
Bob Mottram committed
            echo $'Unable to clone akaunting repo'
Bob Mottram's avatar
Bob Mottram committed
            exit 2589389
    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 23468724527
    git checkout "$AKAUNTING_COMMIT" -b "$AKAUNTING_COMMIT"
Bob Mottram's avatar
Bob Mottram committed
    set_completion_param "akaunting commit" "$AKAUNTING_COMMIT"

Bob Mottram's avatar
Bob Mottram committed
    chmod g+w "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
    chown -R www-data:www-data "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs"
Bob Mottram's avatar
Bob Mottram committed

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    cd "/var/www/$AKAUNTING_DOMAIN_NAME/htdocs" || exit 34783524
    install_composer

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    function_check akaunting_create_database
    akaunting_create_database

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    function_check add_ddns_domain
Bob Mottram's avatar
Bob Mottram committed
    add_ddns_domain "$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

    AKAUNTING_ONION_HOSTNAME=$(add_onion_service akaunting 80 ${AKAUNTING_ONION_PORT})

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    akaunting_nginx_site=/etc/nginx/sites-available/$AKAUNTING_DOMAIN_NAME
    if [[ $ONION_ONLY == "no" ]]; then
        function_check nginx_http_redirect
Bob Mottram's avatar
Bob Mottram committed
        nginx_http_redirect "$AKAUNTING_DOMAIN_NAME" "index index.php"
        { echo 'server {';
          echo '  listen 443 ssl;';
          echo '  #listen [::]:443 ssl;';
          echo "  server_name $AKAUNTING_DOMAIN_NAME;";
          echo ''; } >> "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_compress
Bob Mottram's avatar
Bob Mottram committed
        nginx_compress "$AKAUNTING_DOMAIN_NAME"
        echo '' >> "$akaunting_nginx_site"
        echo '  # Security' >> "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_ssl
Bob Mottram's avatar
Bob Mottram committed
        nginx_ssl "$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_security_options
        nginx_security_options "$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

        { echo '  add_header Strict-Transport-Security max-age=15768000;';
          echo '';
          echo '  access_log /dev/null;';
          echo '  error_log /dev/null;';
          echo '';
          echo "  root /var/www/$AKAUNTING_DOMAIN_NAME/htdocs;";
          echo '';
          echo '  index index.php;';
          echo '';
          echo '  location ~ \.php {';
          echo '    include snippets/fastcgi-php.conf;';
          echo "    fastcgi_pass unix:/var/run/php/php${PHP_VERSION}-fpm.sock;";
Bob Mottram's avatar
Bob Mottram committed
          echo '    fastcgi_read_timeout 30;';
          echo '  }';
          echo '';
          echo '  location / {'; } >> "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
        function_check nginx_limits
Bob Mottram's avatar
Bob Mottram committed
        nginx_limits "$AKAUNTING_DOMAIN_NAME" '15m'
        { echo "    try_files \$uri \$uri/ @akaunting;";
          echo '  }';
          echo '';
          echo '  location @akaunting {';
          echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
          echo '  }';
          echo '';
          echo '  location ~ /\.(ht|git) {';
          echo '    deny all;';
          echo '  }';
          echo '';
          echo '}'; } >> "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    else
Bob Mottram's avatar
Bob Mottram committed
        echo -n '' > "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    fi
Bob Mottram's avatar
Bob Mottram committed
    { echo 'server {';
      echo "    listen 127.0.0.1:$AKAUNTING_ONION_PORT default_server;";
      echo '    port_in_redirect off;';
Bob Mottram's avatar
Bob Mottram committed
      echo "    server_name $AKAUNTING_ONION_HOSTNAME;";
      echo ''; } >> "$akaunting_nginx_site"
      function_check nginx_compress
    nginx_compress "$AKAUNTING_DOMAIN_NAME"
    echo '' >> "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    function_check nginx_security_options
    nginx_security_options "$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed
    { echo '';
      echo '  access_log /dev/null;';
      echo '  error_log /dev/null;';
      echo '';
      echo "  root /var/www/$AKAUNTING_DOMAIN_NAME/htdocs;";
      echo '';
      echo '  index index.php;';
      echo '';
      echo '  location ~ \.php {';
      echo '    include snippets/fastcgi-php.conf;';
      echo "    fastcgi_pass unix:/var/run/php/php${PHP_VERSION}-fpm.sock;";
Bob Mottram's avatar
Bob Mottram committed
      echo '    fastcgi_read_timeout 30;';
      echo '  }';
      echo '';
      echo '  location / {'; } >> "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed
    function_check nginx_limits
Bob Mottram's avatar
Bob Mottram committed
    nginx_limits "$AKAUNTING_DOMAIN_NAME" '15m'
    { echo "    try_files \$uri \$uri/ @akaunting;";
      echo '  }';
      echo '';
      echo '  location @akaunting {';
      echo "    rewrite ^(.*)\$ /index.php?p=\$1 last;";
      echo '  }';
      echo '';
      echo '  location ~ /\.(ht|git) {';
      echo '    deny all;';
      echo '  }';
      echo '}'; } >> "$akaunting_nginx_site"
Bob Mottram's avatar
Bob Mottram committed

    function_check configure_php
    configure_php

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    function_check create_site_certificate
Bob Mottram's avatar
Bob Mottram committed
    create_site_certificate "$AKAUNTING_DOMAIN_NAME" 'yes'
Bob Mottram's avatar
Bob Mottram committed

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    function_check nginx_ensite
Bob Mottram's avatar
Bob Mottram committed
    nginx_ensite "$AKAUNTING_DOMAIN_NAME"
Bob Mottram's avatar
Bob Mottram committed

    akaunting_remove_bad_links

Bob Mottram's avatar
Bob Mottram committed
    systemctl restart mariadb
    # shellcheck disable=SC2086
    systemctl restart php${PHP_VERSION}-fpm
Bob Mottram's avatar
Bob Mottram committed
    systemctl restart nginx

    increment_app_install_progress

Bob Mottram's avatar
Bob Mottram committed
    "${PROJECT_NAME}-pass" -u "$MY_USERNAME" -a akaunting -p "$AKAUNTING_ADMIN_PASSWORD"
Bob Mottram's avatar
Bob Mottram committed

    set_completion_param "akaunting domain" "$AKAUNTING_DOMAIN_NAME"

    APP_INSTALLED=1
}

# NOTE: deliberately there is no "exit 0"