diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2023-08-07 11:57:06 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2023-08-11 11:59:02 +0200 |
commit | edbd8b5849e7da1ddceb49368b431d4862408efd (patch) | |
tree | d57f7cf98d1195cb9c20ea593519ff702379209c /pinentry-rofi.sh | |
parent | 70e88c3da9dc1f473d426f5a44e4c4b6b4936e04 (diff) | |
download | pinentry-rofi-edbd8b5849e7da1ddceb49368b431d4862408efd.tar.gz |
fix: refactor splitting line into a function.
Diffstat (limited to 'pinentry-rofi.sh')
-rwxr-xr-x | pinentry-rofi.sh | 62 |
1 files changed, 23 insertions, 39 deletions
diff --git a/pinentry-rofi.sh b/pinentry-rofi.sh index 0eb3e44..1bfae50 100755 --- a/pinentry-rofi.sh +++ b/pinentry-rofi.sh @@ -38,13 +38,22 @@ log_debug() { echo "$@" >> /tmp/pinentry-log.txt } -rofi_cmd="rofi -dmenu -input /dev/null -password" - assuan_send() { log_debug "assuan_send: $*" echo "$@" } +split_line() { + rmfirst=${2:-0} + read -ra out_arr <<< "$1" + if [ "$rmfirst" -ne 1 ] ; then + unset "out_arr[0]" + fi + echo "${out_arr[@]}" +} + +rofi_cmd="rofi -dmenu -input /dev/null -password" + assuan_send "OK Please go ahead" win_title="Prompt for password" @@ -53,34 +62,6 @@ win_mesg="" keyinfo="" -# gpg-agent[676]: DBG: chan_9 -> OK Pleased to meet you, process 3073 -# gpg-agent[676]: DBG: chan_9 <- RESET -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION ttyname=/dev/pts/0 -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION ttytype=xterm-256color -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION display=:0 -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION putenv=WAYLAND_DISPLAY=wayland-1 -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION putenv=XDG_SESSION_TYPE=wayland -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION putenv=DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION lc-ctype=en_US.UTF-8 -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION lc-messages=cs_CZ.utf8 -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- GETINFO version -# gpg-agent[676]: DBG: chan_9 -> D 2.3.8 -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION allow-pinentry-notify -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- OPTION agent-awareness=2.1.0 -# gpg-agent[676]: DBG: chan_9 -> OK -# gpg-agent[676]: DBG: chan_9 <- KEYINFO 8EA96F4B4BD616DA44A2E297F31C0448A74B9D33 - while : ; do read -r line log_debug "line=$line" @@ -100,8 +81,9 @@ while : ; do # https://www.gnupg.org/documentation/manuals/gnupg/Agent-GETINFO.html # version or pid of this script? # gpg-agent --version works but it must be filtered - IFS=" " read -ra line_arr <<< "$line" - subcommand=${line_arr[1]} + IFS=" " line_arr=("$(split_line "$line")") + log_debug "line_arr: ${line_arr[*]}" + subcommand=${line_arr[0]} log_debug "subcommand=${subcommand}" if [[ "$subcommand" == "version" ]] ; then assuan_send "D ${VERSION}" @@ -127,8 +109,8 @@ while : ; do assuan_send "${keyinfo}" assuan_send "OK" elif [[ "$line" =~ ^SETKEYINFO ]] ; then - IFS=" " read -ra line_arr <<< "$line" - unset "line_arr[0]" && line_arr=("${line_arr[@]}") + IFS=" " line_arr=("$(split_line "$line")") + log_debug "line_arr: ${line_arr[*]}" if [[ "${line_arr[0]}" =~ ^--clear ]] ; then keyinfo="" else @@ -147,19 +129,21 @@ while : ; do elif [[ "$line" =~ ^SETDESC ]] ; then #SETDESC Please enter the passphrase for the ssh key%0A ke:yf:in:ge:rp:ri:nt # rofi << "-mesg" << $1.gsub("<", "<").gsub(/%([0-9A-Fa-f]{2})/) { $1.to_i(16).chr } - IFS=" " read -ra line_arr <<< "$line" - unset "line_arr[0]" && line_arr=("${line_arr[@]}") + IFS=" " line_arr=("$(split_line "$line")") + log_debug "line_arr: ${line_arr[*]}" win_mesg="${line_arr[*]}" assuan_send "OK" elif [[ "$line" =~ ^SETPROMPT ]] ; then #SETPROMPT Passphrase: - IFS=" " read -ra line_arr <<< "$line" - win_prompt="${line_arr[1]}" + IFS=" " line_arr=("$(split_line "$line")") + log_debug "line_arr: ${line_arr[*]}" + win_prompt="${line_arr[0]}" assuan_send "OK" elif [[ "$line" =~ ^GETPIN ]] ; then passw=None sys_env="$(systemctl --user show-environment | tr -s " \t\n" " ")" - IFS=" " read -ra sys_env_arr <<< "$sys_env" + IFS=" " line_arr=("$(split_line "$line" 1)") + log_debug "line_arr: ${line_arr[*]}" for env_line in "${sys_env_arr[@]}" ; do log_debug "env_line=${env_line}" # GPIN_VALID=re.compile(r) |