about summary refs log tree commit diff stats
path: root/home-manager/packages/scripts/apps/aumo
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xhome-manager/packages/scripts/apps/aumo53
1 files changed, 53 insertions, 0 deletions
diff --git a/home-manager/packages/scripts/apps/aumo b/home-manager/packages/scripts/apps/aumo
new file mode 100755
index 00000000..863dcf32
--- /dev/null
+++ b/home-manager/packages/scripts/apps/aumo
@@ -0,0 +1,53 @@
+#!/bin/sh
+# shellcheck disable=SC2046,2086
+
+# shellcheck source=/dev/null
+. ~/.local/lib/shell/lib
+
+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/