#!/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 echo -n "Create a backup" if (( sq_config )) ; then echo " at $FR_BACKUP" else echo fi } step_20_options() { echo "[FRIENDICA ROOT]"; } step_20_alias() { echo "backup"; } step_20() { shift local tempRoot= if (( ! sq_config )) ; 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 "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" info "Backing up webserver directory to $wwwBackup" exe cd "$tempRoot/.." exe tar czf "$wwwBackup" $(basename "$tempRoot") info "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 fi else echo "Get version $1 from github" fi } step_22_options() { echo "[CUSTOM VERSION]"; } 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 "Download failed: $downUrl" exe cd "$tempDown" exe tar -xf "$tempLoc" endReturn "Extract failed: $tempLoc" else info "Found existing download: $tempExtract" fi if [ ! -e "$tempExtractAddons" ] ; then exe wget -O "$tempLocAddons" $downUrlAddons endReturn "Download failed: $downUrlAddons" exe cd "$tempDown" exe mkdir -p "$tempExtractAddons" exe tar -xC "${tempExtractAddons}" -f "$tempLocAddons" endReturn "Extract failed: $tempLocAddons" else info "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" exe systemctl stop friendica.service step backup "$tempBu" endReturn "Backup failed; $FR_LOC renamed!" info "Installing version $latestVersion to $FR_LOC" exe mv "$tempExtract" "$FR_LOC" exe mv "$tempExtractAddons/addon" "$tempAddons" exe chown -R www-data: "$FR_LOC" # Configuration info "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 exe systemctl start friendica.service info "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" } step_40_info() { echo 'Notes'; } step_40_alias() { echo 'notes'; } step_40() { color green cat < [ [...] 'pidfile' => '/run/friendica/daemon.pid', ], * Install Service file [Unit] Description=Friendica Worker Daemon After=network.target mariadb.service [Service] Type=simple Restart=always User=www-data Group=www-data RuntimeDirectory=friendica WorkingDirectory=${FR_LOC} ExecStart=/usr/bin/php ./bin/daemon.php start ExecStop=/usr/bin/php ./bin/daemon.php stop PIDFile=friendica/daemon.pid [Install] WantedBy=multi-user.target * RuntimeDirectory: creates a folder below \`/run\` NOTES_END } # shellcheck disable=SC2034 # Appears unused readonly sqr_minVersion=16 # shellcheck disable=SC1091 # Don't follow this source . /usr/local/bin/sequencer.sh