#!/bin/bash readonly toolName=friendica readonly latestUrl="https://api.github.com/repos/friendica/friendica/releases/latest" sq_config=0 seq_config() { initSeqConfig "${seq_configName}" "${seq_configTemplate}" if [ $? -eq 0 ] ; then sq_config=1 fi } step_20_info() { shift echoinfoArgs "[FRIENDICA ROOT]" echo -n "Create a backup" if [ $sq_config -ne 0 ] ; then echo " at $FR_BACKUP" else echo fi } step_20_alias() { echo "backup"; } step_20() { shift local tempRoot= if [ $sq_config -eq 0 ] ; then error -e "No configuration file found" return 1 fi if [ -n "$FR_BACKUP" ] ; then exe mkdir -p "$FR_BACKUP" fi if [ -n "${1:-}" ] ; then tempRoot="$1" else tempRoot="$FR_LOC" fi exe "${seq_dir}/mysql.sh" -qq backup "$FR_DATABASE" "$FR_BACKUP" endReturn -o $? "Backup mysql database failed" [ ! -e "$tempRoot" ] && endReturn -o 1 -f "Friendica root $tempRoot not found" 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 ! contextHelp ; 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() { echo "upgrade"; } step_22() { shift # don't need step number local latestVersion= if [ -n "${1:-}" ] ; then latestVersion="$1" else latestVersion=$(curl --silent "$latestUrl" | grep -Po '"tag_name": "\K.*?(?=")') fi if [ -z $latestVersion ] ; then error -e "Cannot determine latest version from github repository" return 1 elif interactive ; then echo exe read -p "Install $latestVersion to $FR_LOC [n]o/(y)es? " answer case $answer in [yY]) ;; *) info -e "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 error -e "Version $latestVersion is already installed" return 2 fi # Download local downUrl="https://files.friendi.ca/friendica-full-${latestVersion}.tar.gz" local downUrlAddons="https://files.friendi.ca/friendica-addons-${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 wget -O "$tempLocAddons" $downUrlAddons endReturn -o $? "Download failed: $downUrlAddons" exe cd "$tempDown" exe mkdir -p "$tempExtractAddons" exe tar -xC "${tempExtractAddons}" -f "$tempLocAddons" endReturn -o $? "Extract failed: $tempLocAddons" else echo " [I] Found existing download: $tempExtractAddons" fi # Installation local tempBu="${FR_LOC}_bu_`date +%Y%m%d-%H%M%S`" 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/addon" "$tempAddons" exe chown -R www-data: "$FR_LOC" # Configuration echo " [I] Copying configuration" exe cp -ar "$tempBu/config/local.config.php" "$FR_LOC/config/" if [ -f "$tempBu/config/addon.config.php" ]; then exe cp -ar "$tempBu/config/addon.config.php" "$FR_LOC/config/" fi # Custom landing page if [ -f "$tempBu/home.html" ]; then exe cp -ar "$tempBu/home".* "$FR_LOC/" fi 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() { echo "clean"; } step_24() { exe rm -rf "$tempDown" } readonly sqr_minVersion=16 . /usr/local/bin/sequencer.sh