177 lines
4.6 KiB
Bash
Executable File
177 lines
4.6 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
readonly toolName=wallabag
|
|
readonly toolComposerVersion="2.2.18"
|
|
readonly toolDeps="make"
|
|
readonly toolRepo="https://github.com/wallabag/wallabag.git"
|
|
|
|
# Already defined by sequencer.sh, but may be overwritten
|
|
#readonly seq_configName="${sq_scriptName:?}.cfg"
|
|
#readonly seq_configTemplate="${seq_origin:?}/${sq_configName:?}.example"
|
|
|
|
sq_aptOpt=
|
|
sq_config=0
|
|
|
|
seq_config() {
|
|
## or to use sequencer api with global config file:
|
|
if initSeqConfig "${seq_configName:?}" "${seq_configTemplate:?}" ; then
|
|
sq_config=1
|
|
else
|
|
# End if no configuration file exists
|
|
dry || return 1
|
|
fi
|
|
|
|
## Apt cmdline option to suppress user interaction
|
|
interactive || sq_aptOpt="-y"
|
|
|
|
## Disable error checks if external scripts are used
|
|
## e.g. error on unbound variables
|
|
#disableErrorCheck
|
|
|
|
## Return of non zero value will abort the sequence
|
|
return 0
|
|
}
|
|
|
|
step_1_info() { echo "${toolName} installation status"; }
|
|
step_1_alias() { echo "status"; }
|
|
step_1() {
|
|
if [[ -e "${sc_wallabagDir}" ]] ; then
|
|
color green
|
|
info "${toolName} installed"
|
|
else
|
|
color red
|
|
info "${toolName} not installed"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
step_10_info() {
|
|
echo -n "Install ${toolName}"
|
|
[[ -n "${sc_wallabagDir:-}" ]] && echo " to ${sc_wallabagDir}" || echo " to configured folder"
|
|
}
|
|
step_10_alias() { echo "install"; }
|
|
step_10() {
|
|
if [[ -e "${sc_wallabagDir}" ]] ; then
|
|
error "${toolName} already installed"
|
|
return 1
|
|
fi
|
|
exe apt update
|
|
exe apt install ${toolDeps} "${sq_aptOpt}"
|
|
}
|
|
|
|
step_11_info() { echo "Clone and prepare repository"; }
|
|
step_11() {
|
|
exe git clone "${toolRepo}" "${sc_wallabagDir}"
|
|
exe mkdir "${sc_wallabagDir}/vendor"
|
|
step postupgrade
|
|
}
|
|
|
|
step_12_info() { echo "Get supported composer version"; }
|
|
step_12() {
|
|
local result=1
|
|
local composerSetup="composer-setup.php"
|
|
local expected_checksum="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
|
|
exe cd "${sc_wallabagDir}"
|
|
exe php -r "copy('https://getcomposer.org/installer', '${composerSetup}');"
|
|
local actual_checksum="$(php -r "echo hash_file('sha384', '${composerSetup}');")"
|
|
|
|
if [ "$expected_checksum" != "$actual_checksum" ]
|
|
then
|
|
error 'Invalid installer checksum'
|
|
exe rm "${composerSetup}"
|
|
return 1
|
|
fi
|
|
|
|
exe php "${composerSetup}" --quiet --version="${toolComposerVersion}"
|
|
result="$?"
|
|
exe rm "${composerSetup}"
|
|
return "${result}"
|
|
}
|
|
|
|
step_13_info() { echo "Create mysql database for wallabag"; }
|
|
step_13() {
|
|
exe "${seq_origin}/mysql.sh" -q createdb -c utf8mb4 -d "${sc_wallabagDb:-"wallabag_db"}" -u "${sc_wallabagDbUser:-"wallabag"}"
|
|
}
|
|
|
|
step_14_info() { echo "Start ${toolName} installation procedure"; }
|
|
step_14() {
|
|
exe cd "${sc_wallabagDir}"
|
|
exe sudo -u "${sc_wallabagUser}" make install
|
|
}
|
|
|
|
step_20_info() { echo "Backup ${toolName}"; }
|
|
step_20_alias() { echo "backup"; }
|
|
step_20() {
|
|
info "Backing up configuration..."
|
|
exe cd "${sc_wallabagDir}"
|
|
exe tar czf "${sc_wallabagBackupDir:?}/wallabag_conf_$(date +%Y%m%d-%H%M%S).tar.gz" "app/config"
|
|
exe "${seq_origin}/mysql.sh" -qq backup "${sc_wallabagDb}" "${sc_wallabagBackupDir:?}"
|
|
}
|
|
|
|
step_22_info() { echo "Upgrade ${toolName}"; }
|
|
step_22_alias() { echo "upgrade"; }
|
|
step_22() {
|
|
step backup
|
|
exe cd "${sc_wallabagDir}"
|
|
exe sudo -u "${sc_wallabagUser}" make update
|
|
}
|
|
step_23_info() { echo "Post upgrade steps"; }
|
|
step_23_alias() { echo "postupgrade"; }
|
|
step_23() {
|
|
# Upgrade using user www-data is only successfull like this:
|
|
exe chown -R "${sc_wallabagUser}": "${sc_wallabagDir}"
|
|
}
|
|
|
|
step_100_alias() { echo "notes"; }
|
|
step_100() {
|
|
color green
|
|
cat <<NOTES_EOF
|
|
# Nginx - ${toolName} in subfolder /pocket
|
|
|
|
To be used with a reverse proxy for https.
|
|
|
|
---
|
|
upstream php-handler-wallabag {
|
|
server unix:/var/run/php/php7.4-fpm.sock;
|
|
}
|
|
|
|
server {
|
|
listen 80;
|
|
|
|
access_log off; #/var/log/nginx/wallabag_access.log;
|
|
error_log /var/log/nginx/wallabag_error.log;
|
|
|
|
# Set the root folder in a variable (optional)
|
|
set \$frontRoot ${sc_wallabagDir};
|
|
set \$sfApp app.php; # Change to app_dev.php for dev
|
|
|
|
|
|
set_real_ip_from 10.0.0.0/24;
|
|
real_ip_header X-Real-IP;
|
|
real_ip_recursive on;
|
|
|
|
# wallabag is Symfony 2 app
|
|
location /pocket/ { # Static files
|
|
root \$frontRoot;
|
|
rewrite ^/pocket/(.*)\$ /\$1 break;
|
|
try_files \$uri @sfFront;
|
|
}
|
|
|
|
location @sfFront {
|
|
fastcgi_pass php-handler-wallabag;
|
|
include fastcgi_params;
|
|
fastcgi_param SCRIPT_FILENAME \$frontRoot/\$sfApp;
|
|
fastcgi_param SCRIPT_NAME /pocket/\$sfApp;
|
|
fastcgi_param REQUEST_URI /pocket\$uri?\$args;
|
|
fastcgi_param HTTPS on;
|
|
}
|
|
}
|
|
---
|
|
NOTES_EOF
|
|
}
|
|
|
|
# shellcheck disable=SC2034 # Appears unused
|
|
readonly sqr_minVersion=16
|
|
# shellcheck disable=SC1091 # Don't follow this source
|
|
. /usr/local/bin/sequencer.sh
|