swaydots

my dotfiles
git clone https://git.awy.one/swaydots.git
Log | Files | Refs | README | LICENSE

commit acb8860512eb433b090410048049b68a80437d4f
parent 8a75d03bdeecb79304ff71272ba4b98b37d93bb2
Author: awy <awy@awy.one>
Date:   Tue, 13 May 2025 16:25:07 +0300

doas and rm ntfs3g dependency since ntfs has builtin support

Diffstat:
M.config/shell/profile | 2+-
A.local/bin/doas_askpass | 47+++++++++++++++++++++++++++++++++++++++++++++++
M.local/bin/mounter | 15++++++++-------
M.local/bin/statusbar/sb-nettraf | 1-
M.local/bin/unmounter | 4++--
Mdependencies.txt | 4++--
6 files changed, 60 insertions(+), 13 deletions(-)

diff --git a/.config/shell/profile b/.config/shell/profile @@ -58,7 +58,7 @@ export PASSWORD_STORE_CLIP_TIME=5 # Other program settings: export DICS="/usr/share/stardict/dic/" -export SUDO_ASKPASS="$HOME/.local/bin/dmenupass" +export DOAS_ASKPASS="$HOME/.local/bin/dmenupass" export LESS="R" export LESS_TERMCAP_mb="$(printf '%b' '')" export LESS_TERMCAP_md="$(printf '%b' '')" diff --git a/.local/bin/doas_askpass b/.local/bin/doas_askpass @@ -0,0 +1,47 @@ +#!/usr/bin/expect -- + +# askpass implementation for doas +# example usage: DOAS_ASKPASS="dmenu -P -p password:" doas_askpass echo working + +# don't mind the man behind the curtain +log_user 0 + +# no command, then nothing to do +if { $argc == 0 } { exit 0 } + +# treat all arguments as command input +set cmd [lrange $argv 0 end]; + +# read askpass from env or fallback to dmenu_pass () +if {[info exists ::env(DOAS_ASKPASS)]} { + set askpass "$::env(DOAS_ASKPASS)" +} else { + set askpass "dmenu_pass password:" +} + +# read password from user +set pwd [exec {*}$askpass] + +# spawn doas operation +spawn doas {*}$cmd + +# send password and execute command +expect "doas*password:" { + send -- "$pwd\r" + expect \r + log_user 1 + expect eof +} + +# get the exit status of the spawned doas command +set status [wait] + +# check exit code (4th element of wait result) +set exit_code [lindex $status 3] + +# exit with 1 if doas failed, else 0 +if { $exit_code != 0 } { + exit 1 +} else { + exit 0 +} diff --git a/.local/bin/mounter b/.local/bin/mounter @@ -64,13 +64,13 @@ getmount(){ test -n "$mp" if [ ! -d "$mp" ]; then mkdiryn=$(printf "No\\nYes" | wmenu -i -p "$mp does not exist. Create it?") - [ "$mkdiryn" = "Yes" ] && (mkdir -p "$mp" || sudo -A mkdir -p "$mp") + [ "$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. - sudo -A mount "$chosen" || return 1 + doas_askpass mount "$chosen" || return 1 notify-send "💾Drive Mounted." "$chosen mounted." exit } @@ -82,9 +82,10 @@ case "$chosen" in 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)" ;; + 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." ;; @@ -104,7 +105,7 @@ case "$chosen" in test -b "/dev/mapper/usb$num" attemptmount || getmount - sudo -A mount "/dev/mapper/usb$num" "$mp" -o uid="$(id -u)",gid="$(id -g)" + 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." ;; @@ -113,7 +114,7 @@ case "$chosen" in 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" + 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/statusbar/sb-nettraf b/.local/bin/statusbar/sb-nettraf @@ -5,7 +5,6 @@ # second, gives network traffic per second. case $BLOCK_BUTTON in - 1) setsid -f "$TERMINAL" -e sudo -A bandwhich ;; 3) notify-send "🌐 Network traffic module" "🔻: Traffic received 🔺: Traffic transmitted" ;; 8) setsid -f "$TERMINAL" -e "$EDITOR" "$0" ;; diff --git a/.local/bin/unmounter b/.local/bin/unmounter @@ -17,12 +17,12 @@ chosen="$(echo "$allunmountable" | wmenu -i -p "Unmount which drive?")" chosen="${chosen%% *}" test -n "$chosen" -sudo -A umount -l "/${chosen#*/}" +doas_askpass umount -l "/${chosen#*/}" notify-send "Device unmounted." "$chosen has been unmounted." # Close the chosen drive if decrypted. cryptid="$(echo "$lsblkoutput" | grep "/${chosen#*/}$")" cryptid="${cryptid%% *}" test -b /dev/mapper/"${cryptid##*/}" -sudo -A cryptsetup close "$cryptid" +doas_askpass cryptsetup close "$cryptid" notify-send "🔒Device dencryption closed." "Drive is now securely locked again." diff --git a/dependencies.txt b/dependencies.txt @@ -94,5 +94,5 @@ xorg-xrandr # dark style for qt5 apps python-qdarkstyle -# mounter script ntfs disks -ntfs-3g +# doas askpass +expect