diff --git a/seqs/wallabag.cfg.example b/seqs/wallabag.cfg.example new file mode 100644 index 0000000..041ae6d --- /dev/null +++ b/seqs/wallabag.cfg.example @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +sc_wallabagDir="/var/www/wallabag" +sc_wallabagBackupDir="/root/backup" +sc_wallabagDb="wallabag_db" +sc_wallabagDbUser="wallabag" +sc_wallabagUser="www-data" # user running the webserver diff --git a/seqs/wallabag.sh b/seqs/wallabag.sh new file mode 100755 index 0000000..fdc342a --- /dev/null +++ b/seqs/wallabag.sh @@ -0,0 +1,176 @@ +#!/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 <