diff options
| author | Paul Buetow <paul@buetow.org> | 2026-05-30 16:53:30 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-05-30 16:53:30 +0300 |
| commit | f2fecaa6ffef505da254b7083116ad840588634b (patch) | |
| tree | 5662004b072ec15a509a45b87a31e811e7180b2f /scripts | |
| parent | cab9ae5285a140fab9f4341a8e20eb24b08adca5 (diff) | |
new
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/immich-upload | 262 | ||||
| -rwxr-xr-x | scripts/usbimport | 468 |
2 files changed, 730 insertions, 0 deletions
diff --git a/scripts/immich-upload b/scripts/immich-upload new file mode 100755 index 0000000..82e9c3a --- /dev/null +++ b/scripts/immich-upload @@ -0,0 +1,262 @@ +#!/usr/bin/env bash +# Upload images to Immich, skipping duplicates via SHA1 checksum. +# Usage: immich-upload <file_or_directory> +# +# If <file_or_directory> is a single file, upload just that file. +# If it is a directory, recursively find all image files and upload them. +# Duplicates are detected via the bulk-upload-check API before uploading. + +set -euo pipefail + +IMMICH_URL="http://immich.f3s.lan.buetow.org" +API_KEY_FILE="$HOME/.immich_paul_key" + +# Supported image extensions (case-insensitive) +IMAGE_EXTENSIONS='\.(jpg|jpeg|png|gif|webp|heic|heif|raw|cr2|nef|arw|dng|tiff|tif|bmp)$' + +# ------------------------------------------------------------------ +# Helpers +# ------------------------------------------------------------------ + +die() { echo "ERROR: $1" >&2; exit 1; } + +warn() { echo "WARN: $1" >&2; } + +info() { echo "==> $1"; } + +# Compute SHA1 (hex, lowercase) for a file. +file_sha1() { + sha1sum "$1" | awk '{print $1}' +} + +# Extract fileCreatedAt and fileModifiedAt from exiftool if available, +# otherwise fall back to filesystem timestamps. +# Output is ISO 8601 with milliseconds, e.g. 2024-01-15T10:30:00.000Z +file_timestamps() { + local path="$1" + local created modified + + if command -v exiftool &>/dev/null; then + # Try to get DateTimeOriginal first, then CreateDate, then FileModifyDate + created=$(exiftool -s3 -DateTimeOriginal "$path" 2>/dev/null || true) + if [[ -z "$created" ]]; then + created=$(exiftool -s3 -CreateDate "$path" 2>/dev/null || true) + fi + if [[ -z "$created" ]]; then + created=$(exiftool -s3 -FileModifyDate "$path" 2>/dev/null || true) + fi + # exiftool returns something like "2024:01:15 10:30:00" or + # "2024:01:15 10:30:00+03:00" with timezone offset. + if [[ -n "$created" ]]; then + # Strip timezone offset if present, replace colons with dashes for date part, + # replace space with T, append .000Z + created=$(echo "$created" | sed -E 's/([0-9]{4}):([0-9]{2}):([0-9]{2})/\1-\2-\3/; s/ /T/; s/[+-][0-9]{2}:[0-9]{2}$//; s/$/.000Z/') + fi + fi + + if [[ -z "$created" ]]; then + created=$(date -r "$path" -u '+%Y-%m-%dT%H:%M:%S.000Z') + fi + + modified=$(date -r "$path" -u '+%Y-%m-%dT%H:%M:%S.000Z') + + echo "$created" + echo "$modified" +} + +# ------------------------------------------------------------------ +# Upload a single file +# ------------------------------------------------------------------ + +upload_file() { + local file="$1" + local api_key="$2" + local filename + filename=$(basename "$file") + local checksum + checksum=$(file_sha1 "$file") + + local fileCreatedAt fileModifiedAt + local timestamps + timestamps=$(file_timestamps "$file") + fileCreatedAt=$(echo "$timestamps" | sed -n '1p') + fileModifiedAt=$(echo "$timestamps" | sed -n '2p') + + info "Uploading: $filename" + + local response tmpfile + tmpfile=$(mktemp) + trap "rm -f $tmpfile" RETURN + + local http_code + http_code=$(curl -s -o "$tmpfile" -w '%{http_code}' -X POST \ + -H "x-api-key: $api_key" \ + -H "x-immich-checksum: $checksum" \ + -F "assetData=@$file" \ + -F "fileCreatedAt=$fileCreatedAt" \ + -F "fileModifiedAt=$fileModifiedAt" \ + -F "filename=$filename" \ + -F "deviceAssetId=$checksum" \ + -F "deviceId=immich-upload-cli" \ + "$IMMICH_URL/api/assets" 2>/dev/null) || { http_code="000"; } + + if [[ "$http_code" == "200" ]]; then + info " Skipped (duplicate): $filename" + elif [[ "$http_code" == "201" ]]; then + info " Uploaded: $filename" + elif [[ "$http_code" == "000" ]]; then + warn " Failed to upload: $filename (curl error)" + else + warn " Unexpected response $http_code for: $filename" + cat "$tmpfile" >&2 || true + fi + + rm -f "$tmpfile" +} + +# ------------------------------------------------------------------ +# Bulk upload with duplicate checking +# ------------------------------------------------------------------ + +bulk_upload() { + local api_key="$1" + local files_list="$2" + + local total missing_count + total=$(wc -l < "$files_list") + + # Compute SHA1 for each file and build the bulk check JSON + local check_json tmp_json tmp_missing + tmp_json=$(mktemp) + tmp_missing=$(mktemp) + + info "Computing SHA1 checksums for $total file(s)..." + while IFS= read -r file; do + local checksum + checksum=$(file_sha1 "$file") + printf '%s\t%s\n' "$checksum" "$file" >> "$tmp_json" + done < "$files_list" + + # Build the bulk-upload-check JSON + { + echo '{"assets":[' + local first=1 + while IFS=$'\t' read -r checksum file; do + [[ "$first" -eq 1 ]] || echo ',' + printf '{"id":"%s","checksum":"%s"}' "$file" "$checksum" + first=0 + done < "$tmp_json" + echo ']}' + } > "$tmp_json.json" + + info "Checking for duplicates on server..." + local response + response=$(curl -sf -X POST \ + -H "x-api-key: $api_key" \ + -H "Content-Type: application/json" \ + -d @"$tmp_json.json" \ + "$IMMICH_URL/api/assets/bulk-upload-check" 2>/dev/null) || die "bulk-upload-check failed" + + # Parse the response to find which files are duplicates. + # Response: { "results": [{ "id": "...", "action": "reject", "reason": "duplicate", ... }] } + local resp_file + resp_file=$(mktemp) + echo "$response" > "$resp_file" + python3 -c " +import json, sys +try: + with open('$resp_file') as f: + d = json.load(f) + for r in d.get('results', []): + if r.get('action') == 'reject' and r.get('reason') == 'duplicate': + print(r['id']) +except Exception: + pass +" > "$tmp_missing.exists" + rm -f "$resp_file" + + # Build the missing files list + while IFS=$'\t' read -r checksum file; do + if ! grep -Fxq "$file" "$tmp_missing.exists"; then + echo "$file" >> "$tmp_missing" + fi + done < "$tmp_json" + + missing_count=$(wc -l < "$tmp_missing" | awk '{print $1}') + local dup_count=$(( total - missing_count )) + info "Found $dup_count duplicate(s), $missing_count file(s) to upload" + + if [[ "$missing_count" -eq 0 ]]; then + info "Nothing to upload." + rm -f "$tmp_json" "$tmp_json.json" "$tmp_missing" "$tmp_missing.exists" + return + fi + + # Upload missing files + local n=0 + while IFS= read -r file; do + ((n++)) || true + echo "[$n/$missing_count] $file" + upload_file "$file" "$api_key" + done < "$tmp_missing" + + rm -f "$tmp_json" "$tmp_json.json" "$tmp_missing" "$tmp_missing.exists" +} + +# ------------------------------------------------------------------ +# Main +# ------------------------------------------------------------------ + +main() { + if [[ $# -ne 1 ]]; then + die "Usage: $(basename "$0") <file_or_directory>" + fi + + local src="$1" + + if [[ ! -e "$src" ]]; then + die "Path does not exist: $src" + fi + + if [[ ! -r "$src" ]]; then + die "Path is not readable: $src" + fi + + if [[ ! -f "$API_KEY_FILE" ]]; then + die "API key file not found: $API_KEY_FILE" + fi + + local api_key + api_key=$(cat "$API_KEY_FILE") + if [[ -z "$api_key" ]]; then + die "API key file is empty: $API_KEY_FILE" + fi + + if [[ -f "$src" ]]; then + # Single file upload + info "Uploading single file: $src" + upload_file "$src" "$api_key" + elif [[ -d "$src" ]]; then + # Directory: collect image files recursively + local files_list + files_list=$(mktemp) + trap "rm -f $files_list" EXIT + + info "Scanning directory: $src" + find "$src" -type f -regextype posix-extended -iregex ".*$IMAGE_EXTENSIONS" -print > "$files_list" + + local count + count=$(wc -l < "$files_list" | awk '{print $1}') + if [[ "$count" -eq 0 ]]; then + die "No image files found in: $src" + fi + info "Found $count image file(s)" + + bulk_upload "$api_key" "$files_list" + rm -f "$files_list" + else + die "Unsupported path type: $src" + fi +} + +main "$@" diff --git a/scripts/usbimport b/scripts/usbimport new file mode 100755 index 0000000..cf738b8 --- /dev/null +++ b/scripts/usbimport @@ -0,0 +1,468 @@ +#!/usr/bin/env bash +set -euo pipefail + +GVFS_ROOT=${GVFS_ROOT:-"/run/user/$(id -u)/gvfs"} +FUJIFILM_DEST=${FUJIFILM_DEST:-"$HOME/Documents/Inbox/Fujifilm"} +SUPERNOTE_DEST=${SUPERNOTE_DEST:-"$HOME/Documents/Inbox/Note"} +SUPERNOTE_PDF_DEST=${SUPERNOTE_PDF_DEST:-"$HOME/Documents/Supernote"} +SUPERNOTE_BACKUP_DEST=${SUPERNOTE_BACKUP_DEST:-"$HOME/Books/journals/Supernote"} +SUPERNOTE_BACKUP_TIMEOUT=${SUPERNOTE_BACKUP_TIMEOUT:-20s} + +TOTAL_FOUND=0 +TOTAL_COPIED=0 +TOTAL_SKIPPED=0 +TOTAL_FAILED=0 +TOTAL_CONVERTED=0 +TOTAL_CONVERT_SKIPPED=0 +TOTAL_BACKED_UP=0 +TOTAL_BACKUP_SKIPPED=0 +TOTAL_BACKUP_FAILED=0 + +log() { + printf '%s\n' "$*" +} + +usage() { + cat <<EOF_USAGE +Usage: ${0##*/} [auto|fujifilm|fuji|camera|supernote|nomad] [destination] + +Import files from supported USB devices mounted through GVFS. + +Modes: + auto Import from the single supported device currently connected. + fujifilm Copy only JPEG files from a Fuji/Fujifilm camera. + supernote Copy only the Note folder from a Supernote Nomad, then convert .note files to PDF. + +Default destinations: + Fujifilm JPEGs: $FUJIFILM_DEST + Supernote Note files: $SUPERNOTE_DEST + Supernote PDF files: $SUPERNOTE_PDF_DEST + Optional backup mirror: $SUPERNOTE_BACKUP_DEST + +Environment overrides: + FUJIFILM_DEST=/path/to/dir + SUPERNOTE_DEST=/path/to/dir + SUPERNOTE_PDF_DEST=/path/to/dir + SUPERNOTE_BACKUP_DEST=/path/to/dir + SUPERNOTE_BACKUP_TIMEOUT=20s + GVFS_ROOT=/run/user/UID/gvfs +EOF_USAGE +} + +require_gio() { + if ! command -v gio >/dev/null 2>&1; then + log "gio is required but was not found in PATH." >&2 + return 1 + fi +} + +find_fujifilm_root() { + local root + shopt -s nullglob + for root in "$GVFS_ROOT"/gphoto2:*; do + if gio info "$root" >/dev/null 2>&1; then + printf '%s\n' "$root" + shopt -u nullglob + return 0 + fi + done + shopt -u nullglob + return 1 +} + +find_supernote_root() { + local root storage + shopt -s nullglob + for root in "$GVFS_ROOT"/mtp:*Supernote* "$GVFS_ROOT"/mtp:*supernote*; do + [[ -e "$root" ]] || continue + storage="$root/Internal shared storage" + if gio info "$storage" >/dev/null 2>&1; then + printf '%s\n' "$storage" + shopt -u nullglob + return 0 + fi + if gio info "$root" >/dev/null 2>&1; then + printf '%s\n' "$root" + shopt -u nullglob + return 0 + fi + done + shopt -u nullglob + return 1 +} + +copy_fujifilm_jpegs_from_dir() { + local dir=$1 dest_root=$2 + local name type src dest + + while IFS=$'\t' read -r name _ type _; do + [[ -n ${name:-} ]] || continue + src="$dir/$name" + + case "$type" in + *directory*) + copy_fujifilm_jpegs_from_dir "$src" "$dest_root" + ;; + *regular*) + case "$name" in + *.[Jj][Pp][Gg]|*.[Jj][Pp][Ee][Gg]) + TOTAL_FOUND=$((TOTAL_FOUND + 1)) + dest="$dest_root/$name" + if [[ -e "$dest" ]]; then + log "skip existing: $name" + TOTAL_SKIPPED=$((TOTAL_SKIPPED + 1)) + continue + fi + + log "copy: $src -> $dest" + if gio copy -- "$src" "$dest"; then + TOTAL_COPIED=$((TOTAL_COPIED + 1)) + else + TOTAL_FAILED=$((TOTAL_FAILED + 1)) + fi + ;; + esac + ;; + esac + done < <(gio list -a standard::name,standard::type "$dir") +} + +copy_supernote_files_from_dir() { + local src_dir=$1 dest_dir=$2 rel_dir=${3:-} + local name size type src dest rel_path src_mtime dest_size dest_mtime + + mkdir -p "$dest_dir" + + while IFS=$'\t' read -r name size type _; do + [[ -n ${name:-} ]] || continue + src="$src_dir/$name" + dest="$dest_dir/$name" + rel_path="${rel_dir:+$rel_dir/}$name" + + case "$type" in + *directory*) + copy_supernote_files_from_dir "$src" "$dest" "$rel_path" + ;; + *regular*) + TOTAL_FOUND=$((TOTAL_FOUND + 1)) + if [[ -e "$dest" ]]; then + src_mtime=$(gio info -a time::modified "$src" 2>/dev/null | awk -F': ' '/time::modified:/ {print $2; exit}') + dest_size=$(stat -c '%s' "$dest") + dest_mtime=$(stat -c '%Y' "$dest") + if [[ -n "$src_mtime" && "$size" == "$dest_size" && "$src_mtime" == "$dest_mtime" ]]; then + log "skip unchanged: $rel_path" + TOTAL_SKIPPED=$((TOTAL_SKIPPED + 1)) + continue + fi + rm -f -- "$dest" + fi + + log "copy: $rel_path" + if gio copy -- "$src" "$dest"; then + TOTAL_COPIED=$((TOTAL_COPIED + 1)) + else + TOTAL_FAILED=$((TOTAL_FAILED + 1)) + fi + ;; + esac + done < <(gio list -a standard::name,standard::type,standard::size "$src_dir") +} + +copy_if_changed() { + local src=$1 dest=$2 label=$3 + local src_size dest_size src_mtime dest_mtime + + mkdir -p "$(dirname "$dest")" + if [[ -e "$dest" ]]; then + src_size=$(stat -c '%s' "$src") + dest_size=$(stat -c '%s' "$dest") + src_mtime=$(stat -c '%Y' "$src") + dest_mtime=$(stat -c '%Y' "$dest") + if [[ "$src_size" == "$dest_size" && "$src_mtime" == "$dest_mtime" ]]; then + log "skip existing $label: ${dest#"$HOME"/}" + return 1 + fi + fi + + if timeout "$SUPERNOTE_BACKUP_TIMEOUT" cp -pf -- "$src" "$dest"; then + log "copy $label: ${dest#"$HOME"/}" + return 0 + fi + + log "backup copy timed out or failed: ${dest#"$HOME"/}" >&2 + return 2 +} + +note_signature() { + local note=$1 + + printf 'size=%s\nmtime=%s\n' "$(stat -c '%s' "$note")" "$(stat -c '%Y' "$note")" +} + +pdf_is_current_for_note() { + local note=$1 pdf=$2 meta=$3 + local current recorded + + [[ -e "$pdf" && -e "$meta" ]] || return 1 + current=$(note_signature "$note") + recorded=$(cat "$meta") + [[ "$current" == "$recorded" ]] +} + +convert_supernote_notes_to_pdfs() { + local notes_dir=$1 pdf_dir=$2 + local note rel pdf meta status_dir todo converted_log failed_log converted_count failed_count + + if ! command -v supernote-tool >/dev/null 2>&1; then + log "supernote-tool is required to convert .note files to PDF but was not found in PATH." >&2 + TOTAL_FAILED=$((TOTAL_FAILED + 1)) + return 1 + fi + + mkdir -p "$pdf_dir" + find "$pdf_dir" -type f -name '*.pdf.tmp.*' -delete + status_dir=$(mktemp -d) + todo="$status_dir/todo" + converted_log="$status_dir/converted" + failed_log="$status_dir/failed" + + while IFS= read -r -d '' note; do + rel=${note#"$notes_dir"/} + pdf="$pdf_dir/${rel%.note}.pdf" + meta="${pdf}.note-meta" + mkdir -p "$(dirname "$pdf")" + + if pdf_is_current_for_note "$note" "$pdf" "$meta"; then + log "skip current PDF: ${pdf#"$HOME"/}" + TOTAL_CONVERT_SKIPPED=$((TOTAL_CONVERT_SKIPPED + 1)) + continue + fi + + printf '%s\0' "$note" >>"$todo" + done < <(find "$notes_dir" -type f -iname '*.note' -print0) + + if [[ -s "$todo" ]]; then + export NOTES_DIR=$notes_dir + export PDF_DIR=$pdf_dir + export CONVERTED_LOG=$converted_log + export FAILED_LOG=$failed_log + + # Worker variables are intentionally expanded inside bash -c. + # shellcheck disable=SC2016 + xargs -0 -r -n 1 -P 3 bash -c ' + set -euo pipefail + note=$1 + rel=${note#"$NOTES_DIR"/} + pdf="$PDF_DIR/${rel%.note}.pdf" + meta="${pdf}.note-meta" + tmp="${pdf}.tmp.$$" + + mkdir -p "$(dirname "$pdf")" + printf "convert: %s -> %s\n" "$rel" "${pdf#"$HOME"/}" + if supernote-tool convert -a -t pdf "$note" "$tmp" >/dev/null; then + mv -f -- "$tmp" "$pdf" + { + printf "size=%s\n" "$(stat -c "%s" "$note")" + printf "mtime=%s\n" "$(stat -c "%Y" "$note")" + } >"$meta" + printf "%s\n" "$rel" >>"$CONVERTED_LOG" + else + printf "failed to convert: %s\n" "$rel" >&2 + rm -f -- "$tmp" + printf "%s\n" "$rel" >>"$FAILED_LOG" + fi + ' _ <"$todo" + fi + + converted_count=0 + failed_count=0 + [[ -f "$converted_log" ]] && converted_count=$(wc -l <"$converted_log") + [[ -f "$failed_log" ]] && failed_count=$(wc -l <"$failed_log") + TOTAL_CONVERTED=$((TOTAL_CONVERTED + converted_count)) + TOTAL_FAILED=$((TOTAL_FAILED + failed_count)) + rm -rf -- "$status_dir" + + log "Conversion summary: converted=$TOTAL_CONVERTED skipped=$TOTAL_CONVERT_SKIPPED" +} + +backup_supernote_notes_and_pdfs() { + local notes_dir=$1 pdf_dir=$2 backup_dir=$3 + local src rel dest rc + + if [[ ! -d "$backup_dir" ]]; then + log "Backup directory not found; skipping backup mirror: $backup_dir" + return 0 + fi + + while IFS= read -r -d '' src; do + rel=${src#"$notes_dir"/} + dest="$backup_dir/$rel" + if copy_if_changed "$src" "$dest" "backup note"; then + TOTAL_BACKED_UP=$((TOTAL_BACKED_UP + 1)) + else + rc=$? + if [[ $rc -eq 1 ]]; then + TOTAL_BACKUP_SKIPPED=$((TOTAL_BACKUP_SKIPPED + 1)) + else + TOTAL_BACKUP_FAILED=$((TOTAL_BACKUP_FAILED + 1)) + fi + fi + done < <(find "$notes_dir" -type f -iname '*.note' -print0) + + if [[ -d "$pdf_dir" ]]; then + while IFS= read -r -d '' src; do + rel=${src#"$pdf_dir"/} + dest="$backup_dir/$rel" + if copy_if_changed "$src" "$dest" "backup PDF"; then + TOTAL_BACKED_UP=$((TOTAL_BACKED_UP + 1)) + else + rc=$? + if [[ $rc -eq 1 ]]; then + TOTAL_BACKUP_SKIPPED=$((TOTAL_BACKUP_SKIPPED + 1)) + else + TOTAL_BACKUP_FAILED=$((TOTAL_BACKUP_FAILED + 1)) + fi + fi + done < <(find "$pdf_dir" -type f -iname '*.pdf' -print0) + fi + + log "Backup summary: copied=$TOTAL_BACKED_UP skipped=$TOTAL_BACKUP_SKIPPED failed=$TOTAL_BACKUP_FAILED destination=$backup_dir" +} + +finish_import() { + local dest=$1 + + log "Summary: found=$TOTAL_FOUND copied=$TOTAL_COPIED skipped=$TOTAL_SKIPPED failed=$TOTAL_FAILED" + if [[ $TOTAL_BACKUP_FAILED -gt 0 ]]; then + log "Optional backup failures: $TOTAL_BACKUP_FAILED" >&2 + fi + if [[ $TOTAL_FAILED -eq 0 ]]; then + log "Flushing copied files to disk..." + sync + log "Imported files to: $dest" + log "Import complete. It is safe to unplug the USB device." + return 0 + fi + + log "Imported files to: $dest" >&2 + log "Import finished with failures. It is safe to unplug the USB device, but some files were not copied or converted." >&2 + return 1 +} + +import_fujifilm() { + local dest=${1:-$FUJIFILM_DEST} + local root + + root=$(find_fujifilm_root) || { + log "No GVFS Fuji/Fujifilm camera mount found under $GVFS_ROOT" >&2 + log "Open the camera in your file manager first, then rerun ${0##*/} fujifilm." >&2 + return 1 + } + + mkdir -p "$dest" + log "Device: Fujifilm camera" + log "Source: $root" + log "Destination: $dest" + log "Importing JPEG files only; RAW files are ignored." + copy_fujifilm_jpegs_from_dir "$root" "$dest" + finish_import "$dest" +} + +import_supernote() { + local dest=${1:-$SUPERNOTE_DEST} + local root note_root + + root=$(find_supernote_root) || { + log "No GVFS Supernote mount found under $GVFS_ROOT" >&2 + log "Open the Supernote in your file manager first, then rerun ${0##*/} supernote." >&2 + return 1 + } + note_root="$root/Note" + + if ! gio info "$note_root" >/dev/null 2>&1; then + log "Supernote is mounted, but its Note folder was not found at: $note_root" >&2 + return 1 + fi + + mkdir -p "$dest" + log "Device: Supernote Nomad" + log "Source: $note_root" + log "Destination: $dest" + log "PDF destination: $SUPERNOTE_PDF_DEST" + log "Optional backup destination: $SUPERNOTE_BACKUP_DEST" + log "Importing only the Supernote Note folder." + copy_supernote_files_from_dir "$note_root" "$dest" + log "Supernote note files are copied locally. It is safe to unplug the Supernote now if you eject/unmount it safely." + convert_supernote_notes_to_pdfs "$dest" "$SUPERNOTE_PDF_DEST" + backup_supernote_notes_and_pdfs "$dest" "$SUPERNOTE_PDF_DEST" "$SUPERNOTE_BACKUP_DEST" + finish_import "$dest" +} + +import_auto() { + local has_supernote=0 detected=0 + + if find_fujifilm_root >/dev/null; then + detected=$((detected + 1)) + fi + if find_supernote_root >/dev/null; then + has_supernote=1 + detected=$((detected + 1)) + fi + + case "$detected" in + 0) + log "No supported USB device found under $GVFS_ROOT." >&2 + log "Supported devices: Fujifilm cameras, Supernote Nomad." >&2 + return 1 + ;; + 1) + if [[ $has_supernote -eq 1 ]]; then + import_supernote "$@" + else + import_fujifilm "$@" + fi + ;; + *) + log "Multiple supported devices are connected." >&2 + log "Run one of these explicitly:" >&2 + log " ${0##*/} fujifilm" >&2 + log " ${0##*/} supernote" >&2 + return 2 + ;; + esac +} + +main() { + local mode=${1:-auto} + local dest=${2:-} + + case "$mode" in + -h|--help) + usage + return 0 + ;; + auto) + require_gio + import_auto "$dest" + ;; + fujifilm|fuji|camera) + require_gio + import_fujifilm "$dest" + ;; + supernote|nomad) + require_gio + import_supernote "$dest" + ;; + -* ) + log "Unknown option: $mode" >&2 + usage >&2 + return 2 + ;; + *) + require_gio + import_auto "$mode" + ;; + esac +} + +main "$@" |
