Page MenuHomeGitPull.it

LimeSurvey update script for system administrators
ActivePublic

Authored by valerio.bozzolan on Sep 22 2023, 10:08.
Referenced Files
F1820838: LimeSurvey update script for system administrators
Sep 22 2023, 10:17
F1820830: LimeSurvey update script for system administrators
Sep 22 2023, 10:13
F1820825: LimeSurvey update script for system administrators
Sep 22 2023, 10:09
F1820824: LimeSurvey update script
Sep 22 2023, 10:08
Subscribers
None
#!/bin/sh
##################################################################
# LimeSurvey command line update script for system administrators.
#
# IMPORTANT: Please donate to LimeSurvey!
#
# Author: Valerio Bozzolan
# License: GNU GPL v3+
# Date: 2023
# Source code: https://gitpull.it/P24
##################################################################
set -e
#
# CONFIGURATION STARTS HERE! \o/
#
# URL of your LimeSurvey.
url="https://survey.wikimedia.ch"
# Parent directory of your LimeSurvey installation.
base="/var/www/wikimedia.ch/limesurvey"
# Temporary directory used to download stuff.
temp="/var/www/wikimedia.ch/limesurvey/tmp"
# Database name to be backupped.
dbname="limesurvey_production"
# Symbolic link that is supposed to point to the specific LimeSurvey version to be adopted.
# I organized in such way my filesystem, so "www" points to "limesurvey-1.2.3" and I can
# swap whenever I want.
production_symlink="/var/www/wikimedia.ch/limesurvey/www"
# Script that will be executed just before promoting the new version to production.
# In my case this scripts sets some files as "root:root" so are not writable, and some
# other files are assigned to the webserver user. Essentially it depends by you.
harden_script="/root/scripts/limesurvey-harden.sh"
# Services that will be restarted just after promoting the new version to production.
services_to_be_restarted="php7.3-fpm"
#
# CONFIGURATION ENDS HERE! \o/
#
# No hardening, no party.
if ! [ -x "$harden_script" ]; then
echo "The post-install script (hardening script) does not exist or is not executable."
echo " $harden_script"
exit 2
fi
# No symbolic link, no party.
if ! [ -L "$production_symlink" ]; thenù
echo "This path is supposed to be a symbolic link. Not applicable."
echo " $production_symlink"
exit 2
fi
# https://download.limesurvey.org/latest-stable-release/limesurvey5.2.5+211207.zip
lime_zip_url="$1"
# no lime_zip_url no party
if [ -z "$lime_zip_url" ]; then
echo "Missing download ZIP URL"
echo "Go here: https://community.limesurvey.org/downloads/"
echo "And paste the ZIP URL as first parameter"
exit 1
fi
# no lime_zip_url no party
lime_version="$2"
if [ -z "$lime_version" ]; then
echo "Please add the version code as second parameter"
echo "E.g. 5.4.1"
exit 2
fi
lime_version="limesurvey-$lime_version"
lime_version_base="$base/$lime_version"
lime_version_tmp="$temp/$lime_version"
lime_version_tmp_zip="$temp/$lime_version.zip"
# Do not re-extract over an already-existing LimeSurvey.
if [ -d "$lime_version_tmp" ]; then
echo "This path already exists. Please remove it before using as download destination:"
echo " $lime_version_tmp"
exit 2
fi
# Do not overwrite a dump.
if [ -f "$temp/$dbname-$lime_version.sql" ]; then
echo "There is already a dump with this name. Please move it or delete it:"
echo " $temp/$dbname-$lime_version.sql"
exit 2
fi
echo "Downloading"
wget "$lime_zip_url" -O "$lime_version_tmp_zip"
echo "Extraction"
mkdir --parents "$lime_version_tmp"
unzip "$lime_version_tmp_zip" -d "$lime_version_tmp"
echo "Backup database in a private file"
touch "$temp/$dbname-$lime_version.sql"
chmod o= "$temp/$dbname-$lime_version.sql"
mysqldump "$dbname" > "$temp/$dbname-$lime_version.sql"
# print firm
md5sum "$lime_version_tmp_zip"
sha1sum "$lime_version_tmp_zip"
sha256sum "$lime_version_tmp_zip"
# swap /limesurvey-123/limesurvey to just /limesurvey
echo "Preparation"
mv --no-target-directory "$lime_version_tmp/limesurvey" "$lime_version_base"
echo "Import config and upload"
cp --archive "$production_symlink/application/config/security.php" "$lime_version_base/application/config/security.php"
cp --archive "$production_symlink/application/config/config.php" "$lime_version_base/application/config/config.php"
cp --archive "$production_symlink/upload" "$lime_version_base/upload"
echo "Hardening"
$harden_script "$lime_version_base"
echo "Push in production"
rm --verbose "$production_symlink"
ln --verbose --symbolic --no-dereference "$lime_version_base" "$production_symlink"
# clean downloaded file
echo "Clean"
rmdir "$lime_version_tmp"
rm "$lime_version_tmp_zip"
echo "Now please update from your web interface"
echo "$url"
echo "Remember to clean this backup:"
echo " $temp/$dbname-$lime_version.sql"
echo "Restarting $services_to_be_restarted"
systemctl restart "$services_to_be_restarted"

Event Timeline

valerio.bozzolan changed the title of this paste from LimeSurvey update script to LimeSurvey update script for system administrators.
valerio.bozzolan updated the paste's language from php to bash.
valerio.bozzolan edited the content of this paste. (Show Details)
valerio.bozzolan added a project: LimeSurvey.