hyprdots

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

doas_askpass (954B)


      1 #!/usr/bin/expect --
      2 
      3 # askpass implementation for doas
      4 # example usage: DOAS_ASKPASS="dmenu -P -p password:" doas_askpass echo working
      5 
      6 # don't mind the man behind the curtain
      7 log_user 0
      8 
      9 # no command, then nothing to do
     10 if { $argc == 0 } { exit 0 }
     11 
     12 # treat all arguments as command input
     13 set cmd [lrange $argv 0 end];
     14 
     15 # read askpass from env or fallback to dmenu_pass ()
     16 if {[info exists ::env(DOAS_ASKPASS)]} {
     17 	set askpass "$::env(DOAS_ASKPASS)"
     18 } else {
     19 	set askpass "dmenu_pass password:"
     20 }
     21 
     22 # read password from user
     23 set pwd [exec {*}$askpass]
     24 
     25 # spawn doas operation
     26 spawn doas {*}$cmd
     27 
     28 # send password and execute command
     29 expect "doas*password:" {
     30 	send -- "$pwd\r"
     31 	expect \r
     32 	log_user 1
     33 	expect eof
     34 }
     35 
     36 # get the exit status of the spawned doas command
     37 set status [wait]
     38 
     39 # check exit code (4th element of wait result)
     40 set exit_code [lindex $status 3]
     41 
     42 # exit with 1 if doas failed, else 0
     43 if { $exit_code != 0 } {
     44 	exit 1
     45 } else {
     46 	exit 0
     47 }