]> gitweb.hhaalo.de Git - simple-backup.git/commitdiff
add search for devices
authorBastian Dehn <hhaalo@arcor.de>
Sun, 25 May 2025 06:14:22 +0000 (08:14 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 25 May 2025 06:14:22 +0000 (08:14 +0200)
backupmount [new file with mode: 0755]

diff --git a/backupmount b/backupmount
new file mode 100755 (executable)
index 0000000..fd82f5f
--- /dev/null
@@ -0,0 +1,69 @@
+#!/bin/bash
+
+errlog()
+{
+       local lastexit=$?
+       local msg="$1"
+
+       echo "❌ ERROR: $msg"
+       echo "🛑 EXIT $lastexit"
+       return $lastexit
+}
+
+infolog()
+{
+       local msg="$1"
+
+       echo "â„šī¸  INFO: $msg"
+}
+
+mount()
+{
+       local medias=$(cat config.yaml \
+               | yq --raw-output '.media | keys[]')
+
+       [ -n "$medias" ] && [ "$medias" != "null" ] \
+               || errlog "config.yaml missing media section" \
+               || return $?
+
+       local media=
+       local device=
+       for media in $medias; do
+               device=$(cat config.yaml \
+                       | yq --raw-output ".media.\"$media\".device")
+               [ "$device" != "null" ] \
+                       || errlog "missing path for $media" \
+                       || return $?
+               [ -b "$device" ] \
+                       || infolog "block device $device not found"
+       done
+}
+
+main()
+{
+       local cmd="$1"
+
+       echo "⭐ START: backupmount"
+
+       command -v yq > /dev/null \
+               || errlog "command yq not found" \
+               || return $?
+       [ -n "$cmd" ] \
+               || errlog "missing command" \
+               || return $?
+       [ -f "config.yaml" ] \
+               || errlog "file config.yaml not exists" \
+               || return $?
+
+       if [ "$cmd" == "mount" ]; then
+               mount || return $?
+       elif [ "$cmd" == "umount" ]; then
+               echo "umount"
+       else
+               errlog "unknown command" || return $?
+       fi
+
+       echo "✅ SUCCESS: backupmount"
+}
+
+main $*