Files
shell_sequencer/seqs/torrentwatch.sh

147 lines
3.8 KiB
Bash
Executable File

#!/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"
seq_config() {
if initSeqConfig "$CONFIG_FILE_NAME" "$CONFIG_FILE_TEMPLATE" ; then
CONFIG=1
else
dry || return 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"`
info " git: $toolGitLoc"
info -a "config: $toolConfig"
info -a " html: $toolHtmlLoc"
info -a "backup: $toolBackupLoc"
}
step_1_info() { echo "Install $toolName [VERSION]"; }
step_1_alias() { echo "install"; }
step_1() {
shift
if [ -n "${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() { echo "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 [ -n "${1:-}" ] ; then
toolVersion="$1"
fi
exe git checkout $toolVersion
}
step_20_info() { echo "Backup $toolName"; }
step_20_alias() { echo "backup"; }
step_20() {
shift
if [ ! -e "$toolConfigLoc" ] ; then
error -e "No installation found"
return 1
fi
local buType="all"
if [ -n "${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() { echo "upgrade"; }
step_30() {
shift
if [ -n "${1:-}" ] ; then
toolVersion="$1"
fi
#step backup
if [ $? -ne 0 ]; then
error -e "Backup failed. Aborting upgrade."
return 1
fi
info "Upgrading data"
exe mv "$toolConfigLoc/lib" "$toolConfigLoc/lib_bu"
exe cp -ar "$gitLibLoc/lib" "$toolConfigLoc/"
info "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"
}
readonly sqr_minVersion=16
. /usr/local/bin/sequencer.sh