feature/auto-update-forgejo #2

Merged
jdaily merged 12 commits from feature/auto-update-forgejo into main 2025-03-24 01:46:34 +00:00
Showing only changes of commit 5941e13389 - Show all commits

View file

@ -61,26 +61,27 @@ get_latest_version() {
echo "$latest_version"
}
# Get current Forgejo version
get_current_version() {
local current_version
current_version=$(docker inspect --format='{% raw %}{{.Config.Image}}{% endraw %}' forgejo | \
awk -F':' '{print $2}' || true)
# Get current Forgejo version and image
get_current_image_details() {
local current_image
current_image=$(docker inspect --format='{% raw %}{{.Config.Image}}{% endraw %}' forgejo || true)
if [ -z "$current_version" ]; then
log "ERROR: Failed to retrieve the current Forgejo version."
if [ -z "$current_image" ]; then
log "ERROR: Failed to retrieve the current Forgejo image."
exit 1
fi
echo "$current_version"
echo "$current_image"
}
# Update Forgejo to the latest version
update_forgejo() {
local latest_version=$1
local image_name="codeberg.org/forgejo/forgejo"
local current_image=$(get_current_image_details)
local image_name=$(echo "$current_image" | cut -d':' -f1)
log "Starting Forgejo update process..."
log "Current image: $current_image"
log "Image name: $image_name"
# Check if Forgejo is running
if ! is_forgejo_running; then
@ -97,7 +98,7 @@ update_forgejo() {
# Update the docker-compose file with the new version
log "Updating docker-compose.yml with the new version..."
sed -i "s|codeberg.org/forgejo/forgejo:[0-9.]*\+*|$image_name:$latest_version|g" "$COMPOSE_FILE"
sed -i "s|$image_name:[0-9.]*\+*|$image_name:$latest_version|g" "$COMPOSE_FILE"
# Restart Forgejo with the new version
log "Restarting Forgejo with the new version..."
@ -107,12 +108,12 @@ update_forgejo() {
sleep 15
# Verify the update
NEW_VERSION=$(get_current_version)
NEW_IMAGE=$(get_current_image_details)
if [ "$NEW_VERSION" = "$latest_version" ]; then
if [[ "$NEW_IMAGE" == *":$latest_version" ]]; then
log "Forgejo successfully updated to version $latest_version"
else
log "ERROR: Update verification failed. Current version: $NEW_VERSION, Expected: $latest_version"
log "ERROR: Update verification failed. Current image: $NEW_IMAGE, Expected version: $latest_version"
log "Please check the container logs for more information."
exit 1
fi
@ -122,8 +123,9 @@ update_forgejo() {
log "=== Forgejo Auto-Update Script Started ==="
# Get versions
CURRENT_VERSION=$(get_current_version)
CURRENT_IMAGE=$(get_current_image_details)
LATEST_VERSION=$(get_latest_version)
CURRENT_VERSION=$(echo "$CURRENT_IMAGE" | cut -d':' -f2)
log "Current version: $CURRENT_VERSION"
log "Latest version: $LATEST_VERSION"