105 lines
2.6 KiB
Bash
105 lines
2.6 KiB
Bash
#!/bin/bash
|
|
|
|
# Configuratie
|
|
APP="Gitea"
|
|
LOG_FILE="/var/log/gitea-update.log"
|
|
LOCK_FILE="/tmp/gitea-update.lock"
|
|
|
|
# Kleuren voor logging
|
|
GREEN='\033[0;32m'
|
|
RED='\033[0;31m'
|
|
YELLOW='\033[1;33m'
|
|
NC='\033[0m'
|
|
|
|
# Helper functies voor logging
|
|
log_info() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') [INFO] $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
log_error() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') [ERROR] $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
log_success() {
|
|
echo "$(date '+%Y-%m-%d %H:%M:%S') [SUCCESS] $1" | tee -a "$LOG_FILE"
|
|
}
|
|
|
|
# Controleer of het script als root draait
|
|
if [[ $EUID -ne 0 ]]; then
|
|
log_error "Dit script moet als root worden uitgevoerd"
|
|
exit 1
|
|
fi
|
|
|
|
# Controleer en creëer lock file
|
|
if [ -f "$LOCK_FILE" ]; then
|
|
log_error "Update proces is al actief. Lock file bestaat: $LOCK_FILE"
|
|
exit 1
|
|
fi
|
|
touch "$LOCK_FILE"
|
|
|
|
# Cleanup functie
|
|
cleanup() {
|
|
rm -f "$LOCK_FILE"
|
|
log_info "Cleanup uitgevoerd"
|
|
}
|
|
|
|
# Registreer cleanup voor als het script stopt
|
|
trap cleanup EXIT
|
|
|
|
# Start update proces
|
|
log_info "Start $APP update controle"
|
|
|
|
# Controleer of Gitea is geïnstalleerd
|
|
if [[ ! -f /usr/local/bin/gitea ]]; then
|
|
log_error "Geen ${APP} installatie gevonden!"
|
|
exit 1
|
|
fi
|
|
|
|
# Haal huidige en laatste versie op
|
|
CURRENT_VERSION=$(/usr/local/bin/gitea --version | cut -d' ' -f3)
|
|
LATEST_VERSION=$(wget -q https://github.com/go-gitea/gitea/releases/latest -O - | grep "title>Release" | cut -d " " -f 4 | sed 's/^v//')
|
|
|
|
if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]]; then
|
|
log_info "Gitea is al up-to-date (versie $CURRENT_VERSION)"
|
|
exit 0
|
|
fi
|
|
|
|
log_info "Update beschikbaar: $CURRENT_VERSION -> $LATEST_VERSION"
|
|
|
|
# Download nieuwe versie
|
|
log_info "Downloaden van nieuwe versie..."
|
|
if ! wget -q https://github.com/go-gitea/gitea/releases/download/v$LATEST_VERSION/gitea-$LATEST_VERSION-linux-amd64; then
|
|
log_error "Download mislukt"
|
|
exit 1
|
|
fi
|
|
|
|
# Backup huidige versie
|
|
log_info "Maken van backup..."
|
|
cp /usr/local/bin/gitea /usr/local/bin/gitea.backup
|
|
|
|
# Stop service
|
|
log_info "Stoppen van Gitea service..."
|
|
systemctl stop gitea
|
|
|
|
# Installeer nieuwe versie
|
|
log_info "Installeren van nieuwe versie..."
|
|
mv gitea-$LATEST_VERSION-linux-amd64 /usr/local/bin/gitea
|
|
chmod +x /usr/local/bin/gitea
|
|
chown root:root /usr/local/bin/gitea
|
|
|
|
# Start service
|
|
log_info "Starten van Gitea service..."
|
|
systemctl start gitea
|
|
|
|
# Controleer of service draait
|
|
if systemctl is-active --quiet gitea; then
|
|
log_success "Update succesvol afgerond naar versie $LATEST_VERSION"
|
|
rm -f /usr/local/bin/gitea.backup
|
|
else
|
|
log_error "Service start mislukt, terugdraaien naar vorige versie..."
|
|
mv /usr/local/bin/gitea.backup /usr/local/bin/gitea
|
|
systemctl start gitea
|
|
exit 1
|
|
fi
|
|
|
|
exit 0 |