Skip to content

Instantly share code, notes, and snippets.

@tribut
Created March 2, 2025 11:16
Show Gist options
  • Save tribut/e74550f1e50658fef141d9e34947a6d8 to your computer and use it in GitHub Desktop.
Save tribut/e74550f1e50658fef141d9e34947a6d8 to your computer and use it in GitHub Desktop.
Refresh immich library from CLI with (optional) progress display
IMMICH_KEY=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
IMMICH_HOST=https://immich.example.com
#!/bin/bash
set -eEuo pipefail
cd "$(dirname "$(readlink -e "$0")")"
. .env-cli
QUIET=
NOWAIT=
while getopts "qn" opt; do
case $opt in
q)
QUIET=1
;;
n)
NOWAIT=1
;;
*)
echo "Use me like this: $0 [-q] [-n]" >&1
exit 1
;;
esac
done
info() { [ -n "$QUIET" ] || echo "$@" >&2; }
immich_api() {
method="$1"
endpoint="$2"
shift 2
curl -sS -X "$method" -L "${IMMICH_HOST}${endpoint}" \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H "x-api-key: $IMMICH_KEY" "$@"
}
info "Requesting library refresh..."
j_status="$(immich_api PUT /api/jobs/library \
-d '{
"command": "start",
"force": true
}')"
[ -z "$NOWAIT" ] || exit 0
while true; do
j_status="$(immich_api GET "/api/jobs")"
im_active="$(echo "$j_status" | jq -r '.library.queueStatus.isActive')"
im_paused="$(echo "$j_status" | jq -r '.library.queueStatus.isPaused')"
if [ "$im_active" = "false" ] || [ "$im_paused" = true ]; then break; fi
im_waiting="$(echo "$j_status" | jq -r '.library.jobCounts.waiting')"
info -ne "\rwaiting: $(LC_NUMERIC=C printf "%8d" "$im_waiting") (feel free to ^C, will continue in background)"
sleep 1
done
info ""
info "... done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment