From 3b9e4bee896872200e3a093b7e189730c4296fb5 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Thu, 9 May 2019 20:28:00 +0000 Subject: [PATCH] [WIP] new seqs --- seqs/paperless.sh | 29 +++++++ seqs/webserverUbuntu.sh | 188 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100755 seqs/paperless.sh create mode 100755 seqs/webserverUbuntu.sh diff --git a/seqs/paperless.sh b/seqs/paperless.sh new file mode 100755 index 0000000..cb513fa --- /dev/null +++ b/seqs/paperless.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +step_1_info() { echo "Install python3"; } +step_1() { + exe apt update + exe apt install python3 python3-pip +} + +step_2_info() { echo "Get paperless using git (checkout 2.7.0)"; } +step_2() { + exe git clone https://github.com/the-paperless-project/paperless.git /opt/paperless + exe cd /opt/paperless && git checkout 2.7.0 +} + +step_3_info() { echo "Install other dependcies"; } +step_3() { + exe apt install gnupg tesseract-ocr tesseract-ocr-deu imagemagick unpaper libpoppler-cpp-dev optipng + exe pip3 install --user --requirement /opt/paperless/requirements.txt +} + +step_4_info() { echo "Paperless configuration file"; } +step_4() { + if [ ! -f /etc/paperless.conf ] ; then + cp -ar paperless.conf.example /etc/paperless.conf + else + echo "[ WARN ] Configuration already exists. Doing nothing" + fi +} +. sequencer.sh diff --git a/seqs/webserverUbuntu.sh b/seqs/webserverUbuntu.sh new file mode 100755 index 0000000..cbff1cc --- /dev/null +++ b/seqs/webserverUbuntu.sh @@ -0,0 +1,188 @@ +#!/bin/bash + +serverName="nginx" +serverPackages="nginx" +databaseName="mariadb" +databasePackages="mariadb-server mariadb-client" +phpVersion="7.2" +phpName="php$phpVersion" +phpPackages="${phpName}-fpm ${phpName}-json ${phpName}-mysql ${phpName}-curl ${phpName}-intl ${phpName}-gd ${phpName}-zip ${phpName}-xml ${phpName}-mbstring php-imagick php-apcu" + +step_1_info() { echo -e "Installation of $serverName and ${databaseName} packages:\n $serverPackages $databasePackages"; } +step_1_alias() { ALIAS=install; } +step_1() { + exe apt update + exe apt install $databasePackages + saveReturn $? + endReturn + exe apt install $serverPackages + saveReturn $? +} + +step_2_info() { echo "Basic nginx configuration for initial letsencrypt certificate creation"; } +step_2() { + # Writing acme-challenge code snipped for certbot web root authentication + addConf "$snippetLetsencrypt" "$snippetLetsencryptLoc" + + # Writing minimal default (see below) + addConf "$siteDefaultIp4" "$siteDefaultLoc" + + # try fix errors on first install attempt + # (possible missing ipv6 support on system) + if [ $ERNO -ne 0 ] ; then + exe apt install nginx + fi + + # create webroot + exe mkdir -p "$siteLetsencryptWww" + + echo -n "Restarting Nginx ... " + exe service nginx restart && echo "ok" + saveReturn $? + endReturn +} + +snippetLetsencryptLoc="/etc/nginx/snippets/letsencrypt.conf" +siteLetsencryptWww="/var/www/letsencrypt" +snippetLetsencrypt="\ +location ^~ /.well-known/acme-challenge/ { + default_type \"text/plain\"; + root ${siteLetsencryptWww}; +}" +siteDefaultLoc="/etc/nginx/sites-available/default" +siteDefaultIp4="server { + listen 80 default_server; + + include ${snippetLetsencryptLoc}; +}" + +step_3_info() { echo "Secure mariadb installation"; } +step_3() { + exe mysql_secure_installation +} + +step_4_info() { echo "Mariadb configuration"; } +step_4() { + addConf "$mariadbConfig" "$mariadbConfigLoc" + + echo -n "Restarting mysql ... " + exe service mysql restart && echo "ok" +} + +mariadbConfigLoc="/etc/mysql/mariadb.conf.d/90-myconfig.cnf" +mariadbConfig="\ +[mysqld] +innodb_large_prefix=on +innodb_file_format=barracuda +innodb_file_per_table=true + +lower_case_table_names=0 + +#innodb_force_recovery=6" + +step_5_info() { echo -e "Installation of $phpName packages:\n $phpPackages"; } +step_5() { + exe apt install $phpPackages +} + +phpFpmConfigLocation="/etc/php/${phpVersion}/fpm/conf.d/90-custom_pi.ini" +phpFpmConfig="\ +post_max_size=64M +max_execution_time=600 + +apc.enable_cli=1 + +date.timezone = Europe/Berlin + +opcache.enable=1 +opcache.enable_cli=1 +opcache.interned_strings_buffer=8 +opcache.max_accelerated_files=10000 +opcache.memory_consumption=128 +opcache.save_comments=1 +opcache.revalidate_freq=1" + +phpCliConfigLocation="/etc/php/${phpVersion}/cli/conf.d/90-custom_pi.ini" +phpCliConfig="\ +date.timezone = Europe/Berlin" + +step_6_info() { echo -e "Configuration of ${phpName} fpm and cli\n"; } +step_6() { + addConf "$phpFpmConfig" "$phpFpmConfigLocation" + addConf "$phpCliConfig" "$phpCliConfigLocation" + + echo -n "Restarting ${phpName} ... " + exe service ${phpName}-fpm restart && echo "ok" +} + +step_10_info() { echo -e "Create mysql database without specific characterset\n"; } +step_10_alias() { ALIAS="createdb"; } +step_10() { + local mysqlDatabase + local mysqlUser + local mysqlPass + + echo "Existing mysql databases:" + exe mysql -u root -e 'SHOW DATABASES;' + + read -p "Enter database name: " mysqlDatabase + endCheckEmpty mysqlDatabase "database name" + exe mysql -u root -e 'CREATE DATABASE '$mysqlDatabase';' + saveReturn $? + endReturn + + echo "Existing mysql user:" + exe mysql -u root -e 'SELECT User, Host FROM mysql.user;' + read -p "Enter mysql user name: " mysqlUser + endCheckEmpty mysqlDatabase "user name" + + read -p "Enter mysql user password: " mysqlPass + endCheckEmpty mysqlPass "password" + exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';' + saveReturn $? + endReturn + + exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';' + saveReturn $? + endReturn + + exe mysql -u root -e 'FLUSH PRIVILEGES;' +} + +step_12_info() { echo -e "Create mysql database with characterset utf8mb4\n"; } +step_12_alias() { ALIAS="createdb_utf8mb4"; } +step_12() { + local mysqlDatabase + local mysqlUser + local mysqlPass + + echo "Existing mysql databases:" + exe mysql -u root -e 'SHOW DATABASES;' + + read -p "Enter database name: " mysqlDatabase + endCheckEmpty mysqlDatabase "database name" + # it is recommended NOT to use utf8mb4_general_ci anymore + exe mysql -u root -e 'CREATE DATABASE '$mysqlDatabase' CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;' + saveReturn $? + endReturn + + echo "Existing mysql user:" + exe mysql -u root -e 'SELECT User, Host FROM mysql.user;' + read -p "Enter mysql user name: " mysqlUser + endCheckEmpty mysqlDatabase "user name" + + read -p "Enter mysql user password: " mysqlPass + endCheckEmpty mysqlPass "password" + exe mysql -u root -e 'CREATE USER '"'"$mysqlUser"'"'@'"'"'localhost'"'"' IDENTIFIED BY '"'"$mysqlPass"'"';' + saveReturn $? + endReturn + + exe mysql -u root -e 'GRANT ALL PRIVILEGES ON '$mysqlDatabase'.* TO '"'"$mysqlUser"'"'@'"'"'localhost'"'"';' + saveReturn $? + endReturn + + exe mysql -u root -e 'FLUSH PRIVILEGES;' +} + +VERSION_SEQREV=2 +. sequencer.sh