about summary refs log tree commit diff stats
path: root/hm/soispha/pkgs/scripts/apps/aumo.sh
diff options
context:
space:
mode:
Diffstat (limited to 'hm/soispha/pkgs/scripts/apps/aumo.sh')
-rwxr-xr-xhm/soispha/pkgs/scripts/apps/aumo.sh69
1 files changed, 20 insertions, 49 deletions
diff --git a/hm/soispha/pkgs/scripts/apps/aumo.sh b/hm/soispha/pkgs/scripts/apps/aumo.sh
index b5840fc3..7426115a 100755
--- a/hm/soispha/pkgs/scripts/apps/aumo.sh
+++ b/hm/soispha/pkgs/scripts/apps/aumo.sh
@@ -3,52 +3,23 @@
 # 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/
+unmounting() {
+    disk_name="$(find /dev/disk/by-label -type l -printf "%P|" | rofi -sep "|" -dmenu -p "Select disk to mount")"
+
+    udisksctl unmount --block-device "/dev/disk/by-label/$disk_name"
+}
+
+mounting() {
+    disk_name="$(find /dev/disk/by-label -type l -printf "%P|" | rofi -sep "|" -dmenu -p "Select disk to mount")"
+
+    udisksctl mount --block-device "/dev/disk/by-label/$disk_name"
+}
+
+case "$1" in
+"mount")
+    mounting
+    ;;
+"unmount" | "umount")
+    unmounting
+    ;;
+esac