about summary refs log tree commit diff stats
path: root/hm/soispha/pkgs/scripts/apps/aumo.sh
diff options
context:
space:
mode:
authorSoispha <soispha@vhack.eu>2024-02-20 16:35:15 +0100
committerSoispha <soispha@vhack.eu>2024-02-20 16:35:15 +0100
commitcc09b607330385d6d81b9c47cf64a2442432e93f (patch)
treedc7e4503a3341b8936576c6339a70df4adaa2512 /hm/soispha/pkgs/scripts/apps/aumo.sh
parentrefactor(hm/conf/zsh/config): Rework old config scripts (diff)
downloadnixos-config-cc09b607330385d6d81b9c47cf64a2442432e93f.zip
refactor(treewide): Add a `.sh` extension to shell scripts
Diffstat (limited to 'hm/soispha/pkgs/scripts/apps/aumo.sh')
-rwxr-xr-xhm/soispha/pkgs/scripts/apps/aumo.sh54
1 files changed, 54 insertions, 0 deletions
diff --git a/hm/soispha/pkgs/scripts/apps/aumo.sh b/hm/soispha/pkgs/scripts/apps/aumo.sh
new file mode 100755
index 00000000..b5840fc3
--- /dev/null
+++ b/hm/soispha/pkgs/scripts/apps/aumo.sh
@@ -0,0 +1,54 @@
+#! /usr/bin/env dash
+
+# shellcheck source=/dev/null
+SHELL_LIBRARY_VERSION="2.0.13" . %SHELL_LIBRARY_PATH
+
+# TODO: rewrite this
+
+if [ "$1" = "-u" ];then udisksctl unmount -b "$(cat "$HOME/.cache/aumo/mnt_disk")"; exit 0; fi
+all_available_disks=$(mktemp)
+awk '{print $4}' /proc/partitions | sed '1 s|.*||' > "$all_available_disks"
+
+mounted_disk=$(mktemp)
+awk '{print $1}' /proc/mounts > "$mounted_disk"
+
+unmounted_disks=$(mktemp)
+
+for i in $(cat $all_available_disks);do
+    if ! grep -qw "/dev/$i" $mounted_disk && ! ls /sys/block/$i/*/partition > /dev/null 2> /dev/null;then echo $i >> $unmounted_disks;fi
+done
+
+
+u=1
+disk=-1
+while [ $disk -lt 0 ] || [ $disk -gt $(wc -l $unmounted_disks | awk '{print $1}') ];do
+
+    [ "$1" = "-v" ] &&  for i in $(cat $unmounted_disks);do
+                            sudo fdisk -l "/dev/$i"
+                        done
+
+    for i in $(cat $unmounted_disks);do
+        printf "%4s) %s\n" "$u" "$i"
+        u=$(( u + 1 ))
+    done
+
+    printf "%4s) Exit\n" "0"
+    printf "Input number: "
+    read -r disk
+
+    [ $disk -lt 0 ] || [ $disk -gt $(wc -l $unmounted_disks | awk '{print $1}') ] && printf "Wrong number. Please retry\n"
+    [ $disk -eq 0 ] && exit 0
+done
+
+mnt_disk="/dev/$(awk -v n=$disk 'NR==n' $unmounted_disks)"
+
+if ! [ "$1" = "-v" ] && [ -n "$1" ];then sudo mount "$mnt_disk" "$1" && exit 0;fi
+[ -n "$2" ] && sudo mount "$mnt_disk" "$1" && exit 0
+if mount | grep -q ~/mnt ;then dien "Something is mounted at ~/mnt";else udisksctl mount -b "$mnt_disk";fi
+
+[ -e $HOME/.cache/aumo/mnt_disk ] || mkdir -p $HOME/.cache/aumo
+echo $mnt_disk >> $HOME/.cache/aumo/mnt_disk
+rm $all_available_disks
+rm $mounted_disk
+rm $unmounted_disks
+[ -d /tmp/LIB_FILE_TEMP_DIR/ ] && rm -r /tmp/LIB_FILE_TEMP_DIR/