From 17df35dc088c9b1b159c2b78d8330fa9cc9a672a Mon Sep 17 00:00:00 2001 From: filip <“filip.rabiega@gmail.com”> Date: Wed, 21 Jan 2026 23:42:15 +0100 Subject: reformat most scripts --- mounter | 114 ++++++++++++++++++++++++++++++++-------------------------------- 1 file changed, 57 insertions(+), 57 deletions(-) (limited to 'mounter') diff --git a/mounter b/mounter index af1d23b..121540b 100755 --- a/mounter +++ b/mounter @@ -8,7 +8,7 @@ IFS=' ' # Function for escaping cell-phone names. -escape(){ echo "$@" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g" ;} +escape() { echo "$@" | iconv -cf UTF-8 -t ASCII//TRANSLIT | tr -d '[:punct:]' | tr '[:upper:]' '[:lower:]' | tr ' ' '-' | sed "s/-\+/-/g;s/\(^-\|-\$\)//g"; } # Check for phones. phones="$(simple-mtpfs -l 2>/dev/null | sed "s/^/📱/")" @@ -17,7 +17,7 @@ mountedphones="$(grep "simple-mtpfs" /etc/mtab)" [ -n "$mountedphones" ] && phones="$(for phone in $phones; do for mounted in $mountedphones; do escphone="$(escape "$phone")" - [[ "$mounted" =~ "$escphone" ]] && break 1 + [[ $mounted =~ $escphone ]] && break 1 done && continue 1 echo "$phone" done)" @@ -29,12 +29,12 @@ allluks="$(echo "$lsblkoutput" | grep crypto_LUKS)" # Get a list of the LUKS drive UUIDs already decrypted. decrypted="$(find /dev/disk/by-id/dm-uuid-CRYPT-LUKS2-* | sed "s|.*LUKS2-||;s|-.*||")" # Functioning for formatting drives correctly for dmenu: -filter() { sed "s/ /:/g" | awk -F':' '$7==""{printf "%s%s (%s) %s\n",$1,$3,$5,$6}' ; } +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. + uuid="${uuid//-/}" # This is a bashism. [ -n "$decrypted" ] && for open in $decrypted; do [ "$uuid" = "$open" ] && break 1 done && continue 1 @@ -42,7 +42,7 @@ unopenedluks="$(for drive in $allluks; do done | filter)" # Get all normal, non-encrypted or decrypted partitions that are not mounted. -normalparts="$(echo "$lsblkoutput"| grep -v crypto_LUKS | grep 'part\|rom\|crypt' | sed "s/^/💾 /" | filter )" +normalparts="$(echo "$lsblkoutput" | grep -v crypto_LUKS | grep 'part\|rom\|crypt' | sed "s/^/💾 /" | filter)" # Add all to one variable. If no mountable drives found, exit. alldrives="$(echo "$phones @@ -58,61 +58,61 @@ test -n "$alldrives" chosen="$(echo "$alldrives" | dmenu -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 | dmenu -i -p "Mount this drive where?")" - test -n "$mp" - if [ ! -d "$mp" ]; then - mkdiryn=$(printf "No\\nYes" | dmenu -i -p "$mp does not exist. Create it?") - [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") - fi +getmount() { + mp="$(find /mnt /media /mount /home -maxdepth 1 -type d 2>/dev/null | dmenu -i -p "Mount this drive where?")" + test -n "$mp" + if [ ! -d "$mp" ]; then + mkdiryn=$(printf 'No\nYes' | dmenu -i -p "$mp does not exist. Create it?") + [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + fi } -attemptmount(){ - # Attempt to mount without a mountpoint, to see if drive is in fstab. - sudo -A mount "$chosen" || return 1 - notify-send "💾Drive Mounted." "$chosen mounted." - exit +attemptmount() { + # Attempt to mount without a mountpoint, to see if drive is in fstab. + sudo -A 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" | grep "$chosen")" - attemptmount || getmount - case "${parttype##* }" in - vfat) sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;; - btrfs) sudo -A mount "$chosen" "$mp" ;; - *) sudo -A 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 sudo cryptsetup open "$chosen" "usb$num" - # Check if now decrypted. - test -b "/dev/mapper/usb$num" - - attemptmount || getmount - sudo -A 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. - sudo -A simple-mtpfs -o allow_other -o fsname="simple-mtpfs-$(escape "$chosen")" --device "$number" "$mp" - notify-send "🤖 Android Mounted." "Android device mounted to $mp." - ;; +💾*) + chosen="${chosen%% *}" + chosen="${chosen:1}" # This is a bashism. + parttype="$(echo "$lsblkoutput" | grep "$chosen")" + attemptmount || getmount + case "${parttype##* }" in + vfat) sudo -A mount -t vfat "$chosen" "$mp" -o rw,umask=0000 ;; + btrfs) sudo -A mount "$chosen" "$mp" ;; + *) sudo -A 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 sudo cryptsetup open "$chosen" "usb$num" + # Check if now decrypted. + test -b "/dev/mapper/usb$num" + + attemptmount || getmount + sudo -A 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. + sudo -A simple-mtpfs -o allow_other -o fsname="simple-mtpfs-$(escape "$chosen")" --device "$number" "$mp" + notify-send "🤖 Android Mounted." "Android device mounted to $mp." + ;; esac -- cgit v1.2.3