#!/bin/sh
# Set target Alpine version here
TARGET_VERSION="3.24"

echo "Current Alpine:"
cat /etc/alpine-release

echo "Upgrading to Alpine ${TARGET_VERSION}..."

# Safety backup
BACKUP="/etc/apk/repositories.backup.$(date +%Y%m%d-%H%M%S)"
cp /etc/apk/repositories "$BACKUP"
echo "Repository backup saved: $BACKUP"

# Update repositories
sed -i "s/v[0-9]\+\.[0-9]\+/v${TARGET_VERSION}/g" /etc/apk/repositories

echo "New repositories:"
cat /etc/apk/repositories

# Refresh indexes
apk update

# Upgrade apk tooling first
apk add --upgrade apk-tools

# Upgrade all packages to target branch
apk upgrade --available

# Clean cache
apk cache clean

echo
echo "Upgrade finished."
echo "New Alpine version:"
cat /etc/alpine-release

echo
echo "Kernel:"
uname -r


