diff options
| author | --global <ik.boikov.public@protonmail.com> | 2021-05-01 18:15:53 +0200 |
|---|---|---|
| committer | --global <ik.boikov.public@protonmail.com> | 2021-05-01 18:15:53 +0200 |
| commit | 4a50c594a4dafd1baac41b13a3d5971cd38d118d (patch) | |
| tree | 7552433b6afca2ed251c8557d307c808458288f0 /scripts | |
| parent | 71e8d978c54e276977c7379cba13e54539dbbe1e (diff) | |
Merged dmount and dumount to dmnt. sxiv gif autoplay
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/.local/bin/dmnt | 83 | ||||
| -rwxr-xr-x | scripts/.local/bin/dmount | 69 | ||||
| -rwxr-xr-x | scripts/.local/bin/dumount | 45 |
3 files changed, 83 insertions, 114 deletions
diff --git a/scripts/.local/bin/dmnt b/scripts/.local/bin/dmnt new file mode 100755 index 0000000..2d8ecd6 --- /dev/null +++ b/scripts/.local/bin/dmnt @@ -0,0 +1,83 @@ +#!/bin/sh + +getmount() { \ + [ -z "$chosen" ] && exit 1 + # shellcheck disable=SC2086 + mp="$(find $1 2>/dev/null | dmenu -l 30 -i -p "Type in mount point.")" || exit 1 + [ "$mp" = "" ] && exit 1 + if [ ! -d "$mp" ]; then + mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi + } + +mountusb() { \ + sudo -A mount "$1" 2>/dev/null && notify-send "USB mounting" "$1 mounted." && exit 0 + alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}') + getmount "/mnt -maxdepth 1 -type d $alreadymounted" + partitiontype="$(lsblk -no "fstype" "$1")" + case "$partitiontype" in + "vfat") sudo -A mount -t vfat "$1" "$mp" -o rw,umask=0000;; + "exfat") sudo -A mount "$1" "$mp" -o uid="$(id -u)",gid="$(id -g)";; + *) sudo -A mount "$1" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; + esac + notify-send "USB mounting" "$1 mounted to $mp." +} + +mountandroid() { \ + getmount "/mnt -maxdepth 1 -type d" + jmtpfs -device="$1" "$mp" + #echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 + #jmtpfs -device="$1" "$mp" + notify-send "Android mounting" "Android device mounted to $mp." +} + +unmountdev() { + result=$(sudo -A umount "$1" 2>&1) + if [ -z "$result" ]; then + notify-send "Unmount device" "$1 unmounted" + else + notify-send -u critical -t 4000 "Unmount device" "$result" + fi +} + +selectusb() { \ + chosen=$(lsblk -lpo "vendor,model,name,label,size,mountpoint" | dmenu -l 30 | xargs | cut -d' ' -f 1) + # if mounted + if [ ! -z "$(grep $chosen "/etc/mtab")" ] ; then + choice=$(echo "No\nYes" | dmenu -l 2 -p "Partition is mounted. Unmount?") + case $choice in + Yes) unmountdev $chosen ;; + No) exit ;; + esac + else + mountusb $chosen + fi +} + +selectandroid() { \ + unmounted=$(jmtpfs -l | sed -e '1,2d') + mounted=$(grep "jmtpfs" "/etc/mtab") + + list="Mounted:\n" + if [ ! -z "$mounted" ]; then + list="$list$mounted" + fi + list="$list\nUnmounted:\n" + if [ ! -z "$unmounted" ]; then + list="$list$unmounted" + fi + + chosen=$(echo "$list" "$mounted" | dmenu -i -l 30) + echo "CHOSEN" $chosen + case $chosen in + *jmtpfs*) unmountdev $(echo $chosen | cut -d' ' -f 2) ;; + *) mountandroid $(echo $chosen | awk '{print $1 $2}' | cut -d, -f1-2) ;; + esac +} + +choice="$(printf "USB\\nAndroid" | dmenu -i -p "(Un-)mount a USB drive or Android device?")" || exit 1 +case $choice in + USB) selectusb ;; + Android) selectandroid ;; +esac diff --git a/scripts/.local/bin/dmount b/scripts/.local/bin/dmount deleted file mode 100755 index 8ce369d..0000000 --- a/scripts/.local/bin/dmount +++ /dev/null @@ -1,69 +0,0 @@ -#!/bin/sh - -# Gives a dmenu prompt to mount unmounted drives and Android phones. If -# they're in /etc/fstab, they'll be mounted automatically. Otherwise, you'll -# be prompted to give a mountpoint from already existsing directories. If you -# input a novel directory, it will prompt you to create that directory. - -getmount() { \ - [ -z "$chosen" ] && exit 1 - # shellcheck disable=SC2086 - mp="$(find $1 2>/dev/null | dmenu -l 30 -i -p "Type in mount point.")" || exit 1 - [ "$mp" = "" ] && exit 1 - if [ ! -d "$mp" ]; then - mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") || exit 1 - [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") - fi - } - -mountusb() { \ - devhint=$(lsblk -rpo "name,model" | grep dev | awk '$2!=""{printf "%s (%s)\n",$1,$2}') - chosen="$(echo "$usbdrives\n\nDevices (do not select these):\n$devhint" | dmenu -l 30 -i -p "Mount which drive?")" || exit 1 - chosen="$(echo "$chosen" | awk '{print $1}')" - sudo -A mount "$chosen" 2>/dev/null && notify-send "💻 USB mounting" "$chosen mounted." && exit 0 - alreadymounted=$(lsblk -nrpo "name,type,mountpoint" | awk '$3!~/\/boot|\/home$|SWAP/&&length($3)>1{printf "-not ( -path *%s -prune ) ",$3}') - getmount "/mnt -maxdepth 2 -type d $alreadymounted" - partitiontype="$(lsblk -no "fstype" "$chosen")" - case "$partitiontype" in - "vfat") sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000;; - "exfat") sudo -A mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)";; - *) sudo -A mount "$chosen" "$mp"; user="$(whoami)"; ug="$(groups | awk '{print $1}')"; sudo -A chown "$user":"$ug" "$mp";; - esac - notify-send "💻 USB mounting" "$chosen mounted to $mp." - } - -mountandroid() { \ - chosen="$(echo "$anddrives" | dmenu -l 30 -i -p "Which Android device?")" || exit 1 - chosen="$(echo "$chosen" | awk '{print $1 $2}' | cut -d, -f1-2)" - echo $chosen - getmount "/mnt -maxdepth 2 -type d" - jmtpfs -device="$chosen" "$mp" - echo "OK" | dmenu -i -p "Tap Allow on your phone if it asks for permission and then press enter" || exit 1 - jmtpfs -device="$chosen" "$mp" - notify-send "🤖 Android Mounting" "Android device mounted to $mp." - } - -asktype() { \ - choice="$(printf "USB\\nAndroid" | dmenu -i -p "Mount a USB drive or Android device?")" || exit 1 - case $choice in - USB) mountusb ;; - Android) mountandroid ;; - esac - } - -anddrives=$(jmtpfs -l 2>/dev/null) -usbdrives="$(lsblk -rpo "name,type,size,mountpoint" | grep 'part\|rom' | awk '$4==""{printf "%s (%s)\n",$1,$3}')" - -if [ -z "$usbdrives" ]; then - [ -z "$anddrives" ] && echo "No USB drive or Android device detected" && exit - echo "Android device(s) detected." - mountandroid -else - if [ -z "$anddrives" ]; then - echo "USB drive(s) detected." - mountusb - else - echo "Mountable USB drive(s) and Android device(s) detected." - asktype - fi -fi diff --git a/scripts/.local/bin/dumount b/scripts/.local/bin/dumount deleted file mode 100755 index ff28fe0..0000000 --- a/scripts/.local/bin/dumount +++ /dev/null @@ -1,45 +0,0 @@ - -#!/bin/sh - -# A dmenu prompt to unmount drives. -# Provides you with mounted partitions, select one to unmount. -# Drives mounted at /, /boot and /home will not be options to unmount. - -unmountusb() { - [ -z "$drives" ] && exit - chosen="$(echo "$drives" | dmenu -i -p "Unmount which drive?")" || exit 1 - chosen="$(echo "$chosen" | awk '{print $1}')" - [ -z "$chosen" ] && exit - sudo -A umount "$chosen" && notify-send "💻 USB unmounting" "$chosen unmounted." - } - -unmountandroid() { \ - chosen="$(awk '/simple-mtpfs/ {print $2}' /etc/mtab | dmenu -i -p "Unmount which device?")" || exit 1 - [ -z "$chosen" ] && exit - sudo -A umount -l "$chosen" && notify-send "🤖 Android unmounting" "$chosen unmounted." - } - -asktype() { \ - choice="$(printf "USB\\nAndroid" | dmenu -i -p "Unmount a USB drive or Android device?")" || exit 1 - case "$choice" in - USB) unmountusb ;; - Android) unmountandroid ;; - esac - } - -drives=$(lsblk -nrpo "name,type,size,mountpoint" | awk '$4!~/\/boot|\/home$|SWAP/&&length($4)>1{printf "%s (%s)\n",$4,$3}') - -if ! grep simple-mtpfs /etc/mtab; then - [ -z "$drives" ] && echo "No drives to unmount." && exit - echo "Unmountable USB drive detected." - unmountusb -else - if [ -z "$drives" ] - then - echo "Unmountable Android device detected." - unmountandroid - else - echo "Unmountable USB drive(s) and Android device(s) detected." - asktype - fi -fi |
