====== DokuWiki Upgrade ====== #!/bin/bash dokuwikiDir=data backupDir=backups releaseDir=releases # apache, vagy www-data chownUser=www-data chownGroup=www-data deleteInstallPhp=true curTime=$(date '+%F_%T' | tr -d ':') backup() { # Making sure directory exist [[ -d $backupDir ]] || mkdir $backupDir # Create backup from $dokuwikiDir to $backupFile backupFile=$backupDir/dokuwiki_${curTime}_backup.tar.gz tar --use-compress-program="pigz -9 -k" -cf $backupFile $dokuwikiDir 2>/dev/null } get_release() { # Making sure directory exist [[ -d $releaseDir ]] || mkdir $releaseDir # Get version of stable release from download.dokuwiki.org version=$(curl -s https://download.dokuwiki.org/ | grep "dokuwiki-stable.tgz" -A 1 | tail -n 1 | sed -E 's/.*hint">(.*) .*<\/span>.*/\1/') echo -e "Latest stable version: \e[33m$version\e[0m (download.dokuwiki.org)" # Fetch release to $releaseFile releaseFile=$releaseDir/dokuwiki-stable-$version.tgz wget -q https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz -O $releaseFile } install_release() { # Extract tarball tmpDir=$(mktemp -d) tar zxf $releaseFile -C $tmpDir echo "Installing" 'cp' -af $tmpDir/dokuwiki-$version/* $dokuwikiDir # Delete extracted release rm -rf $tmpDir } cleanup_install() { # Delete unused files" grep -Ev '^($|#)' $dokuwikiDir/data/deleted.files | xargs -n 1 rm -vf # Delete install.php if [[ $deleteInstallPhp == "true" ]]; then rm -f $dokuwikiDir/install.php fi } fix_permissions() { echo "Fixing permissions" find $dokuwikiDir -type d -exec chown $chownUser:$chownGroup {} \; find $dokuwikiDir -type f -exec chown $chownUser:$chownGroup {} \; find $dokuwikiDir -type d -exec chmod 0750 {} \; find $dokuwikiDir -type f -exec chmod 0640 {} \; } upgrade() { backup get_release install_release cleanup_install fix_permissions echo "Finished upgrade to $version" } case "$1" in backup) backup ;; fix-permissions) fix_permissions ;; upgrade|"") upgrade ;; *) echo "Usage: $0 [upgrade|backup|fix-permissions] (default: upgrade)"; exit 1 ;; esac