aboutsummaryrefslogtreecommitdiff
path: root/.local/bin/doas_askpass
diff options
context:
space:
mode:
authorawy <awy@awy.one>2025-07-29 03:42:18 +0300
committerawy <awy@awy.one>2025-07-29 03:42:18 +0300
commitef6dff4cce15186a66ba34cdd7bd39958ebf7f58 (patch)
treefcfa61164ca6e79c900b5d11f6afc6b46aaccb84 /.local/bin/doas_askpass
downloadhyprdots-ef6dff4cce15186a66ba34cdd7bd39958ebf7f58.tar.gz
first commit
Diffstat (limited to '.local/bin/doas_askpass')
-rwxr-xr-x.local/bin/doas_askpass47
1 files changed, 47 insertions, 0 deletions
diff --git a/.local/bin/doas_askpass b/.local/bin/doas_askpass
new file mode 100755
index 0000000..f5d61ef
--- /dev/null
+++ b/.local/bin/doas_askpass
@@ -0,0 +1,47 @@
+#!/usr/bin/expect --
+
+# askpass implementation for doas
+# example usage: DOAS_ASKPASS="mew -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
+}