173 lines
4.7 KiB
Bash
Executable File
173 lines
4.7 KiB
Bash
Executable File
#!/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() {
|
|
shift
|
|
echoinfoArgs "[FRIENDICA ROOT]"
|
|
echo -n "Create a backup"
|
|
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"
|
|
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 [ $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://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" "$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() { ALIAS="clean"; }
|
|
step_24() {
|
|
exe rm -rf "$tempDown"
|
|
}
|
|
|
|
VERSION_SEQREV=14
|
|
. /usr/local/bin/sequencer.sh
|