DEV Community

Cover image for Keep Your Immich Server Up-to-Date ๐Ÿš€
OmkarBhede
OmkarBhede

Posted on

Keep Your Immich Server Up-to-Date ๐Ÿš€

Running your own Immich server is awesome, but keeping it updated can be a tiny hassle. Hereโ€™s a simple Bash script that checks your current version, compares it with the latest GitHub release, and even helps you update safely.

How it Works:

  1. Check Current Version โ€“ Pulls your running Immich version via API.
  2. Check Latest Release โ€“ Fetches the latest release from GitHub.
  3. Compare Versions โ€“ Detects major, minor, or patch updates.
  4. Update Easily โ€“ Prompts you to update, then pulls the new Docker image and restarts the server.

How to find api token?
go to settings > API keys > New API key [only server permission is required]

immich api token step

๐Ÿ’ก Community tip: You can even run this on a cron job to get regular reminders about updates.

#!/bin/bash set -e # ------------------------------- # Configuration # ------------------------------- IMMICH_PORT=xxxxx IMMICH_API_KEY="xxxxx" # ------------------------------- # Function to get current Immich version # ------------------------------- get_current_version() { RESPONSE=$(curl -s -H "x-immich-api-key: $IMMICH_API_KEY" \ http://localhost:$IMMICH_PORT/api/server/version) # Extract version from major.minor.patch VERSION=$(echo "$RESPONSE" | sed -n 's/.*"major":\([0-9]*\).*"minor":\([0-9]*\).*"patch":\([0-9]*\).*/\1.\2.\3/p') if [[ -z "$VERSION" ]]; then VERSION="unknown" fi echo "$VERSION" # NO 'v' prefix here } # ------------------------------- # Function to get latest release from GitHub # ------------------------------- get_latest_version() { TAG=$(curl -s https://api.github.com/repos/immich-app/immich/releases/latest \ | sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p') # Strip leading 'v' if present echo "${TAG#v}" } # ------------------------------- # Compare versions # ------------------------------- compare_versions() { IFS='.' read -r c_major c_minor c_patch <<< "$1" IFS='.' read -r l_major l_minor l_patch <<< "$2" if [[ "$c_major" -lt "$l_major" ]]; then echo "major" elif [[ "$c_minor" -lt "$l_minor" ]]; then echo "minor" elif [[ "$c_patch" -lt "$l_patch" ]]; then echo "patch" else echo "none" fi } # ------------------------------- # Main script # ------------------------------- echo "๐Ÿ” Checking Immich versions..." CURRENT_VERSION=$(get_current_version) LATEST_VERSION=$(get_latest_version) if [[ -z "$LATEST_VERSION" ]]; then LATEST_VERSION="unknown" fi echo "โžก๏ธ Current running version: v$CURRENT_VERSION" echo "โžก๏ธ Latest available version: v$LATEST_VERSION" if [[ "$CURRENT_VERSION" == "$LATEST_VERSION" ]] || [[ "$LATEST_VERSION" == "unknown" ]]; then echo "โœ… No update required. You are running the latest version." exit 0 fi UPDATE_TYPE=$(compare_versions "$CURRENT_VERSION" "$LATEST_VERSION") case $UPDATE_TYPE in major) echo "โš ๏ธ Major update available!" ;; minor) echo "โ„น๏ธ Minor update available." ;; patch) echo "๐Ÿ”ง Patch update available." ;; esac read -p "Do you want to update Immich to v$LATEST_VERSION? (y/n): " confirm if [[ "$confirm" =~ ^[Yy]$ ]]; then echo "๐Ÿš€ Updating Immich..." docker compose down docker compose pull docker compose up -d echo "โœ… Immich update complete." else echo "โŒ Update cancelled." fi 
Enter fullscreen mode Exit fullscreen mode

Top comments (0)