diff options
| author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-07-19 14:46:46 +0200 | 
|---|---|---|
| committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2023-07-19 14:46:46 +0200 | 
| commit | 7533d26a043df25183a78eba5cce5ca5c3d0cbe6 (patch) | |
| tree | 7c64f06ccf49d511f2919cd2bb83e6dce313bef7 /bin/common/aumount | |
| parent | 4b20907a634a47e578d97df24cd7b632c1c06786 (diff) | |
added eject option to aumount
Diffstat (limited to 'bin/common/aumount')
| -rwxr-xr-x | bin/common/aumount | 24 | 
1 files changed, 20 insertions, 4 deletions
diff --git a/bin/common/aumount b/bin/common/aumount index f7f1ecb..19b33e0 100755 --- a/bin/common/aumount +++ b/bin/common/aumount @@ -19,11 +19,16 @@ read_char ()  	die ""  } +get_dev () +{ +	grep "^$1\." "$tmp" | cut -f 2- -d ' ' +} +  # mount the device with $1 as the choice  mount ()  { -	dev="$(grep "^$1\." "$tmp" | cut -f 2- -d ' ')" -	test -z "$dev" && exit +	dev="$(get_dev "$1")" +	test -z "$dev" && exit 1  	die "Mounting /dev/$dev on /media/$dev"  	mkdir -p /media/$dev @@ -34,7 +39,6 @@ mount ()  # umount the device with $1 as the choice  umount ()  { -	printf "$1" | grep -q "[0-9]" || exit 1  	mountpoint="$(sed -n "${1}p" "$tmp" |  		awk '{print $3}')"  	test -z "$mountpoint" && exit 1 @@ -44,6 +48,16 @@ umount ()  		return 1  } +ejekt () +{ +	dev="$(get_dev "$1" | sed 's/.$//')" +	test -z "$dev" && exit 1 + +	die "Ejecting /dev/$dev" +	$sudo eject /dev/$dev > /dev/null 2>&1 || +		return 1 +} +  # print lsblk, use $1 to print only devices with mountpoints or without  pr_lsblk ()  { @@ -70,17 +84,19 @@ cleanup ()  trap cleanup EXIT INT -die "m(ount) u(mount) ?" +die "m(ount) u(mount) (e)ject ?"  choice="$(read_char)"  case $choice in  	"m") i=2; cmd=mount ;;  	"u") i=1; cmd=umount ;; +	"e") i=2; cmd=ejekt ;;  	*) exit 1 ;;  esac  pr_lsblk $i  choice="$(read_char)" +printf "$choice" | grep -q "[0-9]" || exit 1  $cmd $choice &&  	die "Successful." ||  	die "Failed."  | 
