initial commit

This commit is contained in:
2026-02-14 16:48:08 +01:00
commit 3cf1e0f4e6
4 changed files with 452 additions and 0 deletions

21
LICENSE Normal file
View File

@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2025 Allan Christensen
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

188
README.md Normal file
View File

@@ -0,0 +1,188 @@
# DokuWiki Updater for Ubuntu 24.04 Server
[![OS](https://img.shields.io/badge/ubuntu-24.04-E95420)](#)
[![Shell](https://img.shields.io/badge/shell-bash-121011)](#)
[![Feature](https://img.shields.io/badge/feature-safe_updates-0078D7)](#)
[![Cron](https://img.shields.io/badge/scheduler-cron-lightgrey)](#)
[![License](https://img.shields.io/badge/License-MIT-green)](./LICENSE)
Update DokuWiki installations safely on Ubuntu 24.04 server.
This updater replaces core files only and does not modify the `data` directory.
---
## Why this updater exists
DokuWikis built-in upgrade plugins sometimes fail due to permissions, plugin conflicts, or incomplete updates.
This updater provides:
- predictable updates
- scheduled updates via cron
- automatic backups
- clear logging
The goal is stability and long-term maintainability.
---
## What this updater does
✔ Detects installed version
✔ Downloads latest stable release
✔ Compares versions before updating
✔ Clears cache before backup
✔ Creates compressed core backup
✔ Replaces core files safely
✔ Leaves `data/` untouched
✔ Logs every run
---
## What this updater does NOT do
It wont stop you from running the script without reading the documentation like theres no tomorrow.
Skip the README, and whatever happens next is your headache, not a bug report.
---
## Compatibility
This updater is guaranteed to work on systems installed using:
- [DokuWiki for Ubuntu 24.04 Server](https://git.x-files.dk/webapps/dokuwiki-ubuntu)
Other installation methods may use different paths or layouts.
You are free to modify the script if your environment differs.
---
## 1. Clone
```
git clone https://git.x-files.dk/webapps/dokuwiki-updater-ubuntu.git
```
```
cd dokuwiki-updater-ubuntu
```
---
## 2. Install
```
sudo install -m 755 dokuwikiupdate /usr/local/sbin/dokuwikiupdate
```
---
## 3. Run manually
```
sudo dokuwikiupdate /var/www/html/wiki.example.com
```
---
## Automatic Updates (Cron)
Example weekly update:
```
# Minute Hour Day Month DayOfWeek User Command
15 5 * * 5 root /usr/local/sbin/dokuwikiupdate /var/www/html/wiki.example.com >/dev/null 2>&1
```
Logs are written to:
```
/var/log/dokuwiki/
```
---
## Running multiple wikis on one server
If you run several DokuWiki instances, schedule updates at different times rather than running them simultaneously.
Example:
```
# Test wiki (Monday)
5 5 * * 1 root /usr/local/sbin/dokuwikiupdate /var/www/html/wiki-test >/dev/null 2>&1
# Production wiki (Thursday)
5 5 * * 4 root /usr/local/sbin/dokuwikiupdate /var/www/html/wiki-prod >/dev/null 2>&1
```
This allows time to verify updates before production is updated.
Running multiple updates at the exact same time is not recommended.
---
## Backup Behavior
Before updating, the script creates a compressed backup of core files only:
- `conf/`
- `lib/`
- core PHP files
The following are NOT backed up:
- `data/`
- cache
- plugins
Backups are stored in:
```
/var/log/dokuwiki/
```
Only one backup per wiki is kept to prevent filling the filesystem.
---
## Logging
Each wiki has its own log file:
```
/var/log/dokuwiki/<wiki-path>.log
```
Logs include:
- version checks
- backup operations
- update results
---
## Disk Space
Before creating a backup, the script estimates required space and aborts safely if insufficient space is available.
---
## Troubleshooting
| Issue | Cause | Fix |
|--------|--------|--------|
| No update occurs | Already latest version | Normal behavior |
| Backup fails | Disk full or permissions | Check `/var/log` |
| Update fails | Permission or path issue | Check log file |
---
### More Information
More guides and documentation can be found on [wiki.x-files.dk](https://wiki.x-files.dk)
---
### License
Licensed under the [MIT License](./LICENSE).

239
dokuwikiupdate Executable file
View File

@@ -0,0 +1,239 @@
#!/usr/bin/env bash
# Author : Allan Christensen
# First Created : 14-02-2026 (DD-MM-YYYY)
# Description : Updates DokuWiki installations safely (does not modify the data directory)
# License : MIT License
#
# Are we root
#
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi
#
# Validate input
#
if [[ $# -ne 1 ]]; then
echo ""
echo "Usage:"
echo " dokuwikiupdate /path/to/wiki"
echo ""
exit 1
fi
wikidir="$1"
if [[ ! -d "$wikidir" ]]; then
echo ""
echo "Directory not found: $wikidir"
echo ""
exit 1
fi
if [[ ! -f "$wikidir/VERSION" ]]; then
echo ""
echo "VERSION file not found in $wikidir — not a valid DokuWiki installation."
echo ""
exit 1
fi
#
# Variables
#
logdir="/var/log/dokuwiki"
tmpdir=$(mktemp -d /tmp/dokuwiki-update.XXXXXX)
wikiid=$(echo "$wikidir" | sed 's#^/##; s#/#_#g')
logfile="$logdir/${wikiid}.log"
backupfile="$logdir/${wikiid}-core-backup.tar.gz"
tarball="$tmpdir/dokuwiki-stable.tgz"
extractdir="$tmpdir/extracted"
#
# Prepare logging
#
mkdir -p "$logdir"
touch "$logfile"
chmod 640 "$logfile"
#
# Detect interactive mode
#
if [[ -t 1 ]]; then
interactive=true
else
interactive=false
fi
#
# Redirect output to logfile
#
exec >>"$logfile" 2>&1
echo "============================================================"
echo "DokuWiki update run : $(date)"
echo "Wiki path : $wikidir"
echo "============================================================"
#
# Logging helper
#
log() {
echo "$1"
if [[ "$interactive" == true ]]; then
echo "$1" > /dev/tty
fi
}
#
# Cleanup tmpdir automatically
#
trap 'rm -rf "$tmpdir" 2>/dev/null' EXIT
#
# Read installed version
#
installed_version=$(tr -d '\r\n' < "$wikidir/VERSION")
if [[ -z "$installed_version" ]]; then
log ""
log "Could not determine installed version — aborting."
log ""
exit 1
fi
#
# Download latest DokuWiki
#
log ""
log "Downloading latest DokuWiki..."
curl -fL https://download.dokuwiki.org/src/dokuwiki/dokuwiki-stable.tgz -o "$tarball" \
|| { log "Download failed — aborting."; exit 1; }
#
# Extract archive
#
log "Extracting archive..."
mkdir -p "$extractdir"
tar -xzf "$tarball" -C "$extractdir" --strip-components=1 \
|| { log "Extraction failed — aborting."; exit 1; }
#
# Read latest version
#
if [[ ! -f "$extractdir/VERSION" ]]; then
log "VERSION file missing in downloaded archive — aborting."
exit 1
fi
latest_version=$(tr -d '\r\n' < "$extractdir/VERSION")
log ""
log "Installed version : $installed_version"
log "Latest version : $latest_version"
#
# Compare versions
#
if [[ "$installed_version" == "$latest_version" ]]; then
log ""
log "Already up to date. Nothing to do."
log ""
exit 0
fi
log ""
log "Updating DokuWiki to version: $latest_version"
#
# Clear cache before backup
#
log ""
log "Clearing DokuWiki cache..."
rm -rf "$wikidir/data/cache/"* 2>/dev/null
rm -rf "$wikidir/data/tmp/"* 2>/dev/null
#
# Estimate backup size
#
log ""
log "Checking available disk space..."
estimated_size=$(du -sb \
--exclude=data \
--exclude=lib/plugins \
"$wikidir" | awk '{print $1}')
available_space=$(df --output=avail -B1 "$logdir" | tail -1)
log "Estimated backup size : $estimated_size bytes"
log "Available space : $available_space bytes"
if (( available_space < estimated_size )); then
log ""
log "Not enough free space in $logdir to create backup."
log "Aborting update."
log ""
exit 1
fi
#
# Backup current installation (core only)
#
log ""
log "Creating backup..."
rm -f "$backupfile"
tar \
--exclude='data' \
--exclude='lib/plugins' \
-czf "$backupfile" \
-C "$wikidir" . \
|| { log "Backup failed — aborting."; exit 1; }
log "Backup saved to: $backupfile"
#
# Inform user what will happen
#
log ""
log "Core files will be overwritten with the latest DokuWiki release."
log "User data and plugins will NOT be modified."
#
# Prepare extracted files
#
log ""
log "Preparing files (setting ownership to www-data)..."
chown -R www-data:www-data "$extractdir"
#
# Copy files over existing installation
#
log "Updating core files..."
cp -a "$extractdir/." "$wikidir/" \
|| { log "Copy failed — aborting."; exit 1; }
#
# Completed
#
log ""
log "DokuWiki successfully updated to: $latest_version"
log ""
#
# All done
#
printf "\nAll Done...\n"
#
# End of script
#

4
last-tested Normal file
View File

@@ -0,0 +1,4 @@
------------------------------------
Last tested: 14-02-2026 (DD-MM-YYYY)
Environment: Ubuntu Server 24.04 LTS
------------------------------------