From cf8d9f002634011fe74bbaa681c4bd8efb085e04 Mon Sep 17 00:00:00 2001 From: Adrian Amaglio Date: Fri, 18 Feb 2022 00:08:41 +0100 Subject: [PATCH] nice mount system --- interractive_mount | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 interractive_mount diff --git a/interractive_mount b/interractive_mount new file mode 100755 index 0000000..4e44f7c --- /dev/null +++ b/interractive_mount @@ -0,0 +1,82 @@ +#!/bin/sh + +function usage () { + echo "Usage:" + echo "$0 " +} + +# If no display found, full text interface. use dmenu and dunstify else. +if [ -z "$DISPLAY" ] ; then + interface=text + function notify () { + echo "$1\n$2" + } + function ask () { + echo "Text interface not implemented. use X :(" >/dev/stderr + exit 1 + #TODO + i=0 + while read l ; do + echo "$i) $l" + ((i++)) + done + echo -n "Your choice: " + read choice + if [ "$choice" -le "$i" ] && [ "$choice" -ge 0 ] ; then + echo $i + fi + } +else + interface=x + function notify () { + dunstify "$1" "$2" + } + function ask () { + dmenu + } +fi + + +if [ "$1" = "mount" ] ; then + action=mount +elif [ "$1" = umount ] || [ "$1" = unmount ] ; then + action=umount +else + usage + exit 1 +fi + +mounted="" +umounted="" +mounted_nb=0 +umounted_nb=0 + +# List mounted and unmounted disks +while read disk size mountpoint ; do + # Filters. Add yours + [[ "$disk" = /dev/sda* ]] && continue + [ "$disk" = /dev/mapper/cryptroot ] && continue + + # Selection + if [ -z "$mountpoint" ] ; then + umounted="$umounted$disk $size\n" + ((umounted_nb++)) + else + mounted="$mounted$disk $size $mountpoint\n" + ((mounted_nb++)) + fi +done <<< $(lsblk -prno NAME,SIZE,MOUNTPOINTS) + +# Prompt user for disk action +if [ "$action" = "mount" ] ; then + read disk size <<< $(echo -en $umounted | dmenu -i -l "$umounted_nb" -p 'Mount: ') + if [ -b "$disk" ] ; then + notify "Mounting $disk" "$(udisksctl mount -b "$disk" 2>&1)" + fi +elif [ "$action" = "umount" ] ; then + read disk size mountpoint <<< $(echo -en $mounted | dmenu -i -l "$mounted_nb" -p 'Unmount: ') + if [ -b "$disk" ] ; then + notify "Unmounting $disk" "$(udisksctl unmount -b "$disk" 2>&1)" + fi +fi +