initial commit

This commit is contained in:
2026-02-14 12:40:12 +01:00
commit 5886507712
4 changed files with 367 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.

144
README.md Normal file
View File

@@ -0,0 +1,144 @@
# Gitea 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)](#)
[![App](https://img.shields.io/badge/app-gitea-609926)](#)
[![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 Gitea on Ubuntu 24.04 server.
Not a demo, not a quick hack.
This updater is designed for production systems.
---
## Why this updater exists
Keeping Gitea updated should be simple, safe, and predictable.
This script updates the shared Gitea binary and restarts only the instances that were running, leaving stopped instances untouched.
No menus. No guesswork. No surprises.
---
## What this updater does
✔ Detects installed and latest Gitea version
✔ Skips update if already current
✔ Downloads and replaces binary safely
✔ Backs up previous binary automatically
✔ Restarts only running Gitea services
✔ Logs all activity for auditing
---
## 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:
- [Gitea for Ubuntu 24.04 Server](https://git.x-files.dk/webapps/gitea-ubuntu)
- [Gitea Multi-Instance for Ubuntu 24.04](https://git.x-files.dk/webapps/gitea-ubuntu-multi)
Other installation methods may use different paths, service names, or layouts.
You are free to modify the script if your environment differs.
---
## 1. Clone
```
git clone https://git.x-files.dk/webapps/gitea-updater-ubuntu.git
```
```
cd gitea-updater-ubuntu
```
---
## 2. Install the updater
```
sudo install -m 755 giteaupdate /usr/local/sbin/giteaupdate
```
---
## 3. Run manually
```
sudo giteaupdate
```
All activity is logged to:
```
/var/log/gitea/gitea-update.log
```
Backups are stored in:
```
/var/log/gitea/
```
---
## Optional: Automatic Updates (Cron)
Create:
```
/etc/cron.d/giteaupdate
```
Example:
```
#
# Gitea automatic updater
# Runs weekly to keep Gitea current
#
# Minute Hour Day Month DayOfWeek User Command
5 5 * * 5 root /usr/local/sbin/giteaupdate >/dev/null 2>&1
```
---
## File Locations
| Path | Purpose |
|------|--------|
| `/usr/local/bin/gitea` | Gitea binary |
| `/var/log/gitea/gitea-update.log` | Update log |
| `/var/log/gitea/` | Backup binaries |
---
## Troubleshooting
| Issue | Cause | Fix |
|------|------|-----|
| Update fails | Network issue | Re-run script |
| Service not starting | Config or system issue | `systemctl status gitea*` |
| No update performed | Already current | Expected behavior |
---
### 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).

198
giteaupdate Executable file
View File

@@ -0,0 +1,198 @@
#!/usr/bin/env bash
# Author : Allan Christensen
# First Created : 14-02-2026 (DD-MM-YYYY)
# Description : Updates Gitea Single And Multi Instances On Ubuntu 24.04
# License : MIT License
#
# Are we root
#
if [[ $(id -u) -ne 0 ]]; then echo "" && echo "Must be root or use sudo" && echo "" ; exit ; fi
#
# Variables
#
giteabin="/usr/local/bin/gitea"
logdir="/var/log/gitea"
logfile="$logdir/giteaupdate.log"
backupdir="/var/log/gitea"
log_date_format="+%Y-%m-%d-%H%M%S"
#
# Prepare logging
#
mkdir -p "$logdir"
touch "$logfile"
chmod 640 "$logfile"
#
# Detect interactive mode
#
if [[ -t 1 ]]; then
interactive=true
else
interactive=false
fi
#
# Redirect all output to logfile
#
exec >>"$logfile" 2>&1
echo ""
echo "============================================================"
echo "Gitea update run : $(date)"
echo "============================================================"
#
# Logging helper
#
log() {
echo "$1"
if [[ "$interactive" == true ]]; then
echo "$1" > /dev/tty
fi
}
#
# Check Gitea binary exists
#
if [[ ! -x "$giteabin" ]]; then
log ""
log "Gitea binary not found at $giteabin — aborting."
log ""
exit 1
fi
#
# Get installed version
#
installed_version=$("$giteabin" -v 2>/dev/null | awk '{print $3}')
if [[ -z "$installed_version" ]]; then
log ""
log "Could not determine installed Gitea version — aborting."
log ""
exit 1
fi
#
# Get latest version
#
latest_version=$(curl -fsSL https://dl.gitea.com/gitea/version.json | grep -oP '"version"\s*:\s*"\K[^"]+')
if [[ -z "$latest_version" ]]; then
log ""
log "Could not determine latest Gitea version — aborting."
log ""
exit 1
fi
#
# Compare versions
#
log ""
log "Installed version : $installed_version"
log "Latest version : $latest_version"
if [[ "$installed_version" == "$latest_version" ]]; then
log ""
log "Already up to date. Nothing to do."
log ""
exit 0
fi
log ""
log "Updating Gitea to version $latest_version"
#
# Detect running Gitea services
#
mapfile -t running_services < <(
systemctl list-units --type=service --state=running --no-legend |
awk '{print $1}' | grep '^gitea'
)
#
# Download new binary
#
tmpbin="${giteabin}.new"
log ""
log "Downloading new Gitea binary..."
curl -fL "https://dl.gitea.com/gitea/${latest_version}/gitea-${latest_version}-linux-amd64" -o "$tmpbin" \
|| { log "Download failed — aborting." ; exit 1 ; }
chmod 755 "$tmpbin"
#
# Validate downloaded binary
#
log "Validating downloaded binary..."
if ! "$tmpbin" -v >/dev/null 2>&1; then
log "Downloaded binary failed validation — aborting."
rm -f "$tmpbin"
exit 1
fi
log "Binary validation successful."
#
# Stop running services
#
if [[ ${#running_services[@]} -gt 0 ]]; then
log ""
log "Stopping running Gitea services..."
for svc in "${running_services[@]}"; do
log "Stopping $svc"
systemctl stop "$svc"
done
else
log ""
log "No running Gitea services detected."
fi
#
# Backup current binary
#
mkdir -p "$backupdir"
backupfile="$backupdir/giteaupdate-binary.log.$(date "$log_date_format")"
cp -p "$giteabin" "$backupfile"
log ""
log "Backup saved to: $backupfile"
#
# Replace binary
#
mv "$tmpbin" "$giteabin"
chmod 755 "$giteabin"
#
# Start services that were previously running
#
if [[ ${#running_services[@]} -gt 0 ]]; then
log ""
log "Starting Gitea services..."
for svc in "${running_services[@]}"; do
log "Starting $svc"
systemctl start "$svc"
done
log ""
log "Restarted services: ${running_services[*]}"
fi
log ""
log "Update complete."
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
------------------------------------