From b5e5bcba665481011a7d9b5b21e485e6334f3ab8 Mon Sep 17 00:00:00 2001 From: Martin Winkler Date: Wed, 27 Jan 2021 21:43:02 +0100 Subject: [PATCH] Seq to upgrade an existing torrentwatch installation Installation is WIP --- seqs/torrentwatch-xa.cfg.example | 6 ++ seqs/torrentwatch.sh | 147 +++++++++++++++++++++++++++++++ 2 files changed, 153 insertions(+) create mode 100644 seqs/torrentwatch-xa.cfg.example create mode 100755 seqs/torrentwatch.sh diff --git a/seqs/torrentwatch-xa.cfg.example b/seqs/torrentwatch-xa.cfg.example new file mode 100644 index 0000000..d65a9a1 --- /dev/null +++ b/seqs/torrentwatch-xa.cfg.example @@ -0,0 +1,6 @@ +#!/bin/bash + +TWXA_GIT_LOC='~/downloads/torrentwatch-xa' +TWXA_CONFIG_LOC='/var/lib/torrentwatch-xa' +TWXA_HTML_LOC='/var/www/torrentwatch-xa' +TWXA_BACKUP_LOC='~/backup/torrentwatch-xa' diff --git a/seqs/torrentwatch.sh b/seqs/torrentwatch.sh new file mode 100755 index 0000000..ab5c247 --- /dev/null +++ b/seqs/torrentwatch.sh @@ -0,0 +1,147 @@ +#!/bin/bash + +toolName=torrentwatch-xa +toolDeps="git php-mbstring php-curl php-xml" +toolGitUrl="https://github.com/dchang0/torrentwatch-xa.git" +toolConfigName="torrentwatch-xa.config" +# Initialized by config of input +toolVersion="master" +toolConfigLoc= +toolConfig= +toolHtmlLoc= +toolBackupLoc= + +# Get script working directory +# (when called from a different directory) +WDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >>/dev/null 2>&1 && pwd )" +CONFIG=0 +CONFIG_FILE_NAME="${toolName}.cfg" +CONFIG_FILE_TEMPLATE="$WDIR/${CONFIG_FILE_NAME}.example" + +step_config() { + initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" + if [ $? -eq 0 ] ; then + CONFIG=1 + else + exit 1 + fi + toolConfigLoc=`eval echo "$TWXA_CONFIG_LOC"` + toolConfig="$toolConfigLoc/config_cache/$toolConfigName" + toolHtmlLoc=`eval echo "$TWXA_HTML_LOC"` + toolBackupLoc=`eval echo "$TWXA_BACKUP_LOC"` + toolGitLoc=`eval echo "$TWXA_GIT_LOC"` + gitLibLoc=`eval echo "$TWXA_GIT_LOC/var/lib/torrentwatch-xa"` + gitHtmlLoc=`eval echo "$TWXA_GIT_LOC/var/www/html/torrentwatch-xa"` + echo " git: $toolGitLoc" + echo " config: $toolConfig" + echo " html: $toolHtmlLoc" + echo " backup: $toolBackupLoc" +} + +step_1_info() { echo "Install $toolName [VERSION]"; } +step_1_alias() { ALIAS="install"; } +step_1() { + shift + if [ ! -z $1 ] ; then + toolVersion="$1" + fi + echo $toolConfig +} + +step_2_info() { echo "Setup git repository at $toolGitLoc [VERSION e.g. 1.4.1]"; } +step_2_alias() { ALIAS="git"; } +step_2() { + shift + if [ ! -e "$toolGitLoc/.git" ] ; then + exe mkdir -p "$toolGitLoc" + exe cd "$toolGitLoc" + exe git clone $toolGitUrl . + else + exe cd "$toolGitLoc" + exe git pull + fi + if [ ! -z $1 ] ; then + toolVersion="$1" + fi + exe git checkout $toolVersion +} + +step_20_info() { echo "Backup $toolName"; } +step_20_alias() { ALIAS="backup"; } +step_20() { + shift + if [ ! -e "$toolConfigLoc" ] ; then + echoerr " [E] No installation found" + return 1 + fi + + local buType="all" + if [ ! -z $1 ] ; then + buType="$1" + fi + local buDate=`date +%Y%m%d-%H%M%S` + local buDir="$toolBackupLoc/$buDate" + local buConfig="$buDir/$toolConfigName" + local buHtmlConfig="$buDir/config.php" + local dataBackup="$buDir/${toolName}_data_${buDate}.tar.gz" + local htmlBackup="$buDir/${toolName}_html_${buDate}.tar.gz" + + if [ "$buType" == "all" ] || [ "$buType" == "config" ] ; then + exe mkdir -p "$buDir" + saveReturn $? + exe cd "$toolConfigLoc/.." + saveReturn $? + exe tar czf "$dataBackup" $(basename "$toolConfigLoc") + saveReturn $? + exe cp -ar "$toolConfig" "$buConfig" + saveReturn $? + exe ln -sf "$buConfig" "$toolBackupLoc" + saveReturn $? + fi + + if [ "$buType" == "all" ] || [ "$buType" == "html" ] ; then + exe mkdir -p "$buDir" + saveReturn $? + exe cd "$toolHtmlLoc/.." + saveReturn $? + exe tar czf "$htmlBackup" $(basename "$toolHtmlLoc") + saveReturn $? + exe cp -ar "$toolHtmlLoc/config.php" "$buHtmlConfig" + saveReturn $? + exe ln -sf "$buHtmlConfig" "$toolBackupLoc" + saveReturn $? + fi + endReturn +} + +step_30_info() { echo "Upgrade $toolName [VERSION]"; } +step_30_alias() { ALIAS="upgrade"; } +step_30() { + shift + if [ ! -z $1 ] ; then + toolVersion="$1" + fi + + #step backup + if [ $? -ne 0 ]; then + echoerr " [E] Backup failed. Aborting upgrade." + return 1 + fi + + echo " [I] Upgrading data" + exe mv "$toolConfigLoc/lib" "$toolConfigLoc/lib_bu" + exe cp -ar "$gitLibLoc/lib" "$toolConfigLoc/" + + echo " [I] Upgrading html" + exe mv "$toolHtmlLoc" "${toolHtmlLoc}_bu" + exe cp -ar "$gitHtmlLoc" "$toolHtmlLoc" + exe cp -arL "$toolBackupLoc/config.php" "$toolHtmlLoc" + + exe chown www-data: "$toolHtmlLoc/config.php" + exe touch /var/log/twxalog + exe chown www-data: /var/log/twxalog + exe chown -R www-data: "$toolConfigLoc/*_cache" +} + +VERSION_SEQREV=11 +. /usr/local/bin/sequencer.sh