feature/auto-update-forgejo #2
1 changed files with 17 additions and 15 deletions
|
|
@ -61,26 +61,27 @@ get_latest_version() {
|
||||||
echo "$latest_version"
|
echo "$latest_version"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get current Forgejo version
|
# Get current Forgejo version and image
|
||||||
get_current_version() {
|
get_current_image_details() {
|
||||||
local current_version
|
local current_image
|
||||||
current_version=$(docker inspect --format='{% raw %}{{.Config.Image}}{% endraw %}' forgejo | \
|
current_image=$(docker inspect --format='{% raw %}{{.Config.Image}}{% endraw %}' forgejo || true)
|
||||||
awk -F':' '{print $2}' || true)
|
|
||||||
|
|
||||||
if [ -z "$current_version" ]; then
|
if [ -z "$current_image" ]; then
|
||||||
log "ERROR: Failed to retrieve the current Forgejo version."
|
log "ERROR: Failed to retrieve the current Forgejo image."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$current_version"
|
echo "$current_image"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Update Forgejo to the latest version
|
# Update Forgejo to the latest version
|
||||||
update_forgejo() {
|
update_forgejo() {
|
||||||
local latest_version=$1
|
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
|
# Check if Forgejo is running
|
||||||
if ! is_forgejo_running; then
|
if ! is_forgejo_running; then
|
||||||
|
|
@ -97,7 +98,7 @@ update_forgejo() {
|
||||||
|
|
||||||
# Update the docker-compose file with the new version
|
# Update the docker-compose file with the new version
|
||||||
log "Updating docker-compose.yml 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
|
# Restart Forgejo with the new version
|
||||||
log "Restarting Forgejo with the new version..."
|
log "Restarting Forgejo with the new version..."
|
||||||
|
|
@ -107,12 +108,12 @@ update_forgejo() {
|
||||||
sleep 15
|
sleep 15
|
||||||
|
|
||||||
# Verify the update
|
# 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"
|
log "Forgejo successfully updated to version $latest_version"
|
||||||
else
|
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."
|
log "Please check the container logs for more information."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -122,8 +123,9 @@ update_forgejo() {
|
||||||
log "=== Forgejo Auto-Update Script Started ==="
|
log "=== Forgejo Auto-Update Script Started ==="
|
||||||
|
|
||||||
# Get versions
|
# Get versions
|
||||||
CURRENT_VERSION=$(get_current_version)
|
CURRENT_IMAGE=$(get_current_image_details)
|
||||||
LATEST_VERSION=$(get_latest_version)
|
LATEST_VERSION=$(get_latest_version)
|
||||||
|
CURRENT_VERSION=$(echo "$CURRENT_IMAGE" | cut -d':' -f2)
|
||||||
|
|
||||||
log "Current version: $CURRENT_VERSION"
|
log "Current version: $CURRENT_VERSION"
|
||||||
log "Latest version: $LATEST_VERSION"
|
log "Latest version: $LATEST_VERSION"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue