diff --git a/seqs/friendica.cfg.example b/seqs/friendica.cfg.example new file mode 100644 index 0000000..432b364 --- /dev/null +++ b/seqs/friendica.cfg.example @@ -0,0 +1,9 @@ +#!/bin/bash + +# Friendica sequence configuration +# FR = Friendica + +FR_LOC="/var/www/friendica" +FR_LOC_DATA="/var/fd_data" +FR_BACKUP="/root/backup/friendica" +FR_DATABASE="friendica_db" diff --git a/seqs/friendica.sh b/seqs/friendica.sh new file mode 100755 index 0000000..03766f5 --- /dev/null +++ b/seqs/friendica.sh @@ -0,0 +1,160 @@ +#!/bin/bash + +toolName=friendica +latestUrl="https://api.github.com/repos/friendica/friendica/releases/latest" + +# 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 + fi +} + +step_20_info() { + echo -n "Create a backup [FRIENDICA ROOT]" + if [ $CONFIG -ne 0 ] ; then + echo " at $FR_BACKUP" + else + echo + fi +} +step_20_alias() { ALIAS="backup"; } +step_20() { + shift + local tempRoot= + if [ $CONFIG -eq 0 ] ; then + echoerr " [E] No configuration file found" + return 1 + fi + if [ ! -z $FR_BACKUP ] ; then + exe mkdir -p "$FR_BACKUP" + fi + if [ ! -z $1 ] ; then + tempRoot="$1" + else + tempRoot="$FR_LOC" + fi + + exe $WDIR/mysql.sh -qq backup "$FR_DATABASE" "$FR_BACKUP" + local wwwBackup="$FR_BACKUP/${toolName}_www_`date +%Y%m%d-%H%M%S`.tar.gz" + local dataBackup="$FR_BACKUP/${toolName}_data_`date +%Y%m%d-%H%M%S`.tar.gz" + echo " [I] Backing up webserver directory to $wwwBackup" + exe cd "$tempRoot/.." + exe tar czf "$wwwBackup" $(basename "$tempRoot") + echo " [I] Backing up data directory to $dataBackup" + exe cd "$FR_LOC_DATA/.." + exe tar czf "$dataBackup" $(basename "$FR_LOC_DATA") +} + +step_22_info() { + shift + if [ -z $1 ] ; then + echo -n "Get latest version from github" + if [ $CONTEXT_HELP -eq 0 ] ; then + echo ": $(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")')" + else + echo " [CUSTOM VERSION]" + fi + else + echo "Get version $1 from github" + fi +} +step_22_alias() { ALIAS="upgrade"; } +step_22() { + shift # don't need step number + local latestVersion= + if [ ! -z $1 ] ; then + latestVersion="$1" + else + latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")') + fi + + if [ -z $latestVersion ] ; then + echoerr " [E] Cannot determine latest version from github repository" + return 1 + elif [ $QUIET -eq 0 ] ; then + echo + exe read -p "Install $latestVersion to $FR_LOC [n]o/(y)es? " answer + case $answer in + [yY]) + ;; + *) + echoerr " [I] Upgrade aborted" + return 1 + ;; + esac + fi + + local isInstalled=$(grep -E "Version $latestVersion" "${FR_LOC}/CHANGELOG" >>/dev/null && echo "1" || echo "0") + if [ $isInstalled -eq 1 ] ; then + echoerr " [E] Version $latestVersion is already installed" + return 2 + fi + + # Download + + local downUrl="https://github.com/friendica/friendica/releases/download/${latestVersion}/friendica-full-${latestVersion}.tar.gz" + local downUrlAddons="https://github.com/friendica/friendica-addons/archive/${latestVersion}.tar.gz" + local tempExtract="$tempDown/friendica-full-$latestVersion" + local tempExtractAddons="$tempDown/friendica-addons-$latestVersion" + + if [ ! -e "$tempExtract" ] ; then + exe mkdir -p "$tempDown" + exe wget -O "$tempLoc" $downUrl + endReturn -o $? "Download failed: $downUrl" + exe cd "$tempDown" + exe tar -xf "$tempLoc" + endReturn -o $? "Extract failed: $tempLoc" + else + echo " [I] Found existing download: $tempExtract" + fi + + if [ ! -e "$tempExtractAddons" ] ; then + exe mkdir -p "$tempDown" + exe wget -O "$tempLocAddons" $downUrlAddons + endReturn -o $? "Download failed: $downUrlAddons" + exe cd "$tempDown" + exe tar -xf "$tempLocAddons" + endReturn -o $? "Extract failed: $tempLocAddons" + else + echo " [I] Found existing download: $tempExtractAddons" + fi + + # Installation + local tempBu="${FR_LOC}_bu" + local tempAddons="${FR_LOC}/addon" + + exe mv "$FR_LOC" "$tempBu" + step backup "$tempBu" + endReturn -o $? "Backup failed; $FR_LOC renamed!" + echo " [I] Installing version $latestVersion to $FR_LOC" + exe mv "$tempExtract" "$FR_LOC" + exe mv "$tempExtractAddons" "$tempAddons" + exe chown -R www-data: "$FR_LOC" + + # Configuration + echo " [I] Copying configuration" + exe cp -ar "$tempBu/config/local.config.php" "$FR_LOC/config/" + exe cp -ar "$tempBu/config/addon.config.php" "$FR_LOC/config/" + + echo " [I] Don't forget to \"clean\" if everything is working as expected" +} +tempDown="/tmp/friendica" +tempLoc="$tempDown/fr.tar.gz" +tempLocAddons="$tempDown/fradd.tar.gz" + +step_24_info() { echo "Clean temporary files: $tempDown"; } +step_24_alias() { ALIAS="clean"; } +step_24() { + exe rm -rf "$tempDown" +} + +VERSION_SEQREV=11 +. /usr/local/bin/sequencer.sh