commit 94cf9e3ad0d0173ee316a9dd4b3df7973c30febb
parent ca84ac74f92184466a2cc85a769574959ab86bbc
Author: awy <awy@awy.one>
Date: Sat, 26 Jul 2025 18:21:28 +0300
mounter
Diffstat:
2 files changed, 62 insertions(+), 62 deletions(-)
diff --git a/.local/bin/mounter b/.local/bin/mounter
@@ -10,15 +10,15 @@ phones="$(simple-mtpfs -l 2>/dev/null | sed "s/^/📱/")"
mountedphones="$(rg "simple-mtpfs" /etc/mtab)"
# If there are already mounted phones, remove them from the list of mountables.
[ -n "$mountedphones" ] && phones="$(for phone in $phones; do
- for mounted in $mountedphones; do
- escphone="$(escape "$phone")"
- [[ "$mounted" =~ "$escphone" ]] && break 1
- done && continue 1
- echo "$phone"
+ for mounted in $mountedphones; do
+ escphone="$(escape "$phone")"
+ [[ "$mounted" =~ "$escphone" ]] && break 1
+ done && continue 1
+ echo "$phone"
done)"
# Check for drives.
-lsblkoutput="$(doas_askpass lsblk -rpo "uuid,name,type,size,label,mountpoint,fstype")"
+lsblkoutput="$(doas lsblk -rpo "uuid,name,type,size,label,mountpoint,fstype")"
# Get all LUKS drives
allluks="$(echo "$lsblkoutput" | rg crypto_LUKS)"
# Get a list of the LUKS drive UUIDs already decrypted.
@@ -28,12 +28,12 @@ filter() { sed "s/ /:/g" | awk -F':' '$7==""{printf "%s%s (%s) %s\n",$1,$3,$5,$6
# Get only LUKS drives that are not decrypted.
unopenedluks="$(for drive in $allluks; do
- uuid="${drive%% *}"
- uuid="${uuid//-}" # This is a bashism.
- [ -n "$decrypted" ] && for open in $decrypted; do
- [ "$uuid" = "$open" ] && break 1
- done && continue 1
- echo "🔒 $drive"
+ uuid="${drive%% *}"
+ uuid="${uuid//-}" # This is a bashism.
+ [ -n "$decrypted" ] && for open in $decrypted; do
+ [ "$uuid" = "$open" ] && break 1
+ done && continue 1
+ echo "🔒 $drive"
done | filter)"
# Get all normal, non-encrypted or decrypted partitions that are not mounted.
@@ -54,61 +54,61 @@ chosen="$(echo "$alldrives" | mew -p "Mount which drive?" -i)"
# Function for prompting user for a mountpoint.
getmount(){
- mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | mew -i -p "Mount this drive where?")"
- test -n "$mp"
- if [ ! -d "$mp" ]; then
- mkdiryn=$(printf "No\\nYes" | mew -i -p "$mp does not exist. Create it?")
- [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || doas_askpass mkdir -p "$mp")
- fi
+ mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | mew -i -p "Mount this drive where?")"
+ test -n "$mp"
+ if [ ! -d "$mp" ]; then
+ mkdiryn=$(printf "No\\nYes" | mew -i -p "$mp does not exist. Create it?")
+ [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || doas_askpass mkdir -p "$mp")
+ fi
}
attemptmount(){
- # Attempt to mount without a mountpoint, to see if drive is in fstab.
- doas_askpass mount "$chosen" || return 1
- notify-send "💾Drive Mounted." "$chosen mounted."
- exit
+ # Attempt to mount without a mountpoint, to see if drive is in fstab.
+ doas mount "$chosen" || return 1
+ notify-send "💾Drive Mounted." "$chosen mounted."
+ exit
}
case "$chosen" in
- 💾*)
- chosen="${chosen%% *}"
- chosen="${chosen:1}" # This is a bashism.
- parttype="$(echo "$lsblkoutput" | rg "$chosen" | awk '{print $NF}' | tr -d '[:space:]\r\n')"
- attemptmount || getmount
- case "${parttype##* }" in
- vfat) doas_askpass mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;;
- btrfs) doas_askpass mount "$chosen" "$mp" ;;
- ntfs) doas_askpass mount -t ntfs3 "$chosen" "$mp" ;;
- *) doas_askpass mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" ;;
- esac
- notify-send "💾Drive Mounted." "$chosen mounted to $mp."
+ 💾*)
+ chosen="${chosen%% *}"
+ chosen="${chosen:1}" # This is a bashism.
+ parttype="$(echo "$lsblkoutput" | rg "$chosen" | awk '{print $NF}' | tr -d '[:space:]\r\n')"
+ attemptmount || getmount
+ case "${parttype##* }" in
+ vfat) doas mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;;
+ btrfs) doas mount "$chosen" "$mp" ;;
+ ntfs) doas mount -t ntfs3 "$chosen" "$mp" ;;
+ *) doas mount "$chosen" "$mp" -o uid="$(id -u)",gid="$(id -g)" ;;
+ esac
+ notify-send "💾Drive Mounted." "$chosen mounted to $mp."
+ ;;
+
+ 🔒*)
+ chosen="${chosen%% *}"
+ chosen="${chosen:1}" # This is a bashism.
+ # Number the drive.
+ while true; do
+ [ -f "/dev/mapper/usb$num" ] || break
+ num="$(printf "%02d" "$((num +1))")"
+ done
+
+ # Decrypt in a terminal window
+ ${TERMINAL:-st} -n floatterm -g 60x1 -e doas cryptsetup open "$chosen" "usb$num"
+ # Check if now decrypted.
+ test -b "/dev/mapper/usb$num"
+
+ attemptmount || getmount
+ doas mount "/dev/mapper/usb$num" "$mp" -o uid="$(id -u)",gid="$(id -g)"
+ notify-send "🔓Decrypted drive Mounted." "$chosen decrypted and mounted to $mp."
;;
- 🔒*)
- chosen="${chosen%% *}"
- chosen="${chosen:1}" # This is a bashism.
- # Number the drive.
- while true; do
- [ -f "/dev/mapper/usb$num" ] || break
- num="$(printf "%02d" "$((num +1))")"
- done
-
- # Decrypt in a terminal window
- ${TERMINAL:-st} -n floatterm -g 60x1 -e doas cryptsetup open "$chosen" "usb$num"
- # Check if now decrypted.
- test -b "/dev/mapper/usb$num"
-
- attemptmount || getmount
- doas_askpass mount "/dev/mapper/usb$num" "$mp" -o uid="$(id -u)",gid="$(id -g)"
- notify-send "🔓Decrypted drive Mounted." "$chosen decrypted and mounted to $mp."
- ;;
-
- 📱*)
- notify-send "❗Note" "Remember to allow file access on your phone now."
- getmount
- number="${chosen%%:*}"
- number="${chosen:1}" # This is a bashism.
- doas_askpass simple-mtpfs -o allow_other -o fsname="simple-mtpfs-$(escape "$chosen")" --device "$number" "$mp"
- notify-send "🤖 Android Mounted." "Android device mounted to $mp."
- ;;
+ 📱*)
+ notify-send "❗Note" "Remember to allow file access on your phone now."
+ getmount
+ number="${chosen%%:*}"
+ number="${chosen:1}" # This is a bashism.
+ doas_askpass simple-mtpfs -o allow_other -o fsname="simple-mtpfs-$(escape "$chosen")" --device "$number" "$mp"
+ notify-send "🤖 Android Mounted." "Android device mounted to $mp."
+ ;;
esac
diff --git a/.local/bin/unmounter b/.local/bin/unmounter
@@ -14,7 +14,7 @@ chosen="$(echo "$allunmountable" | mew -i -p "Unmount which drive?")"
chosen="${chosen%% *}"
test -n "$chosen"
-doas_askpass umount -l "/${chosen#*/}"
+doas umount -l "/${chosen#*/}"
notify-send "Device unmounted." "$chosen has been unmounted."
# Close the chosen drive if decrypted.