]>
Commit | Line | Data |
---|---|---|
79d4a356 | 1 | # NOTE: |
8d4a98e1 | 2 | # our .zprofile can be expensive, so we keep track of what has been run |
b31a3fb1 | 3 | # already, and only set up what is necessary. this also allows us to re-source |
4 | # the file to reinitialize specific parts when desired. | |
79d4a356 | 5 | # |
b31a3fb1 | 6 | # in order to ensure future interactive environments are set up as early as |
7 | # possible, we source this file from .zshenv for non-login shells, under some | |
8 | # specific conditions outlined there. | |
9 | # | |
10 | # this file respects non-interactive sessions and will not intentionally emit | |
11 | # output. | |
79d4a356 | 12 | |
6d54344e | 13 | ### cleanup |
14 | # XXX: only call after relevant vars have been set up, defined early so that | |
15 | # below code can utilize it after they do so | |
16 | function _sev_zcleanup { | |
17 | ## gpg forwarding | |
18 | if [[ -d $_sev_gpg_forward_dir && ( -z $1 || $1 == 'gpg-forward' ) ]] { | |
19 | # clean up forward dirs if its session is dead or we ask for it | |
a8dee69a | 20 | find $_sev_gpg_forward_dir -mindepth 1 -maxdepth 1 -type d | |
6d54344e | 21 | while {read -r x} { |
22 | # NOTE: the only way we can get here is if we have not been | |
23 | # forwarded before, if the user asks for it, or during | |
24 | # logout. if our own pid already has a dir, it is most likely | |
25 | # stale, the user wants it removed, or something is very | |
26 | # broken—in all 3 of these cases the best choice is remove it. | |
27 | p=$(basename $x) | |
28 | if {[[ -v _sev_gpg_forward_clean || $$ == $p ]] || | |
8d4a98e1 | 29 | ! kill -0 $p 2>/dev/null} { |
6d54344e | 30 | find $x -mindepth 1 -maxdepth 1 | while {read -r y} { |
31 | # XXX: real dirs will stop unlink, consider it a feature | |
32 | unlink $y | |
33 | } | |
34 | # don't force in case something important is still there | |
35 | rmdir $x | |
36 | } | |
37 | } | |
38 | # reset GNUPGHOME if we removed our own dir | |
4581a6bf | 39 | if [[ $GNUPGHOME =~ '/.ssh_forward/\d+/*$' && ! -e $GNUPGHOME ]] |
40 | GNUPGHOME=${GNUPGHOME%$MATCH} | |
6d54344e | 41 | } |
42 | ||
43 | ## tmp | |
44 | # NOTE: _sev_tmp is not unset so session dirs will not be recreated | |
45 | # NOTE: XDG dirs that use our tmp are not unset here, they are in zlogout | |
46 | if [[ -d $_sev_tmp && ( -z $1 || $1 == 'tmp' ) ]] { | |
47 | # clean up tmp dirs if its session is dead or we ask for it | |
a8dee69a | 48 | find $_sev_tmp -mindepth 1 -maxdepth 1 -name '.session.*' -type d | |
6d54344e | 49 | while {read -r x} { |
50 | # NOTE: same rationale as above | |
51 | p=${$(basename $x)#.session.} | |
52 | if {[[ -v _sev_tmp_clean || $$ == $p ]] || | |
8d4a98e1 | 53 | ! kill -0 $p 2>/dev/null} { |
6d54344e | 54 | rm -rf $x |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | unset x p y | |
60 | } | |
61 | ||
8d4a98e1 | 62 | ### xdg local dir |
63 | # NOTE: need this for tmp, so confirm it exists. | |
64 | # XXX: perms are not specified for XDG dirs except runtime, but I think 760 | |
65 | # makes the most sense. shouldn't break anything since no one else should | |
66 | # be poking around in our dir. | |
b31a3fb1 | 67 | [[ -e ~/.local ]] || mkdir -m760 ~/.local |
8d4a98e1 | 68 | |
6d54344e | 69 | ### tmp |
70 | # NOTE: specs say that POSIX tmp and XDG runtime directories should exist | |
71 | # until the last session is logged out (POSIX can exist for longer). | |
72 | # since we can't reliably keep track of sessions in a cross-platform | |
73 | # manner, the current implementation should use a separate directory per | |
74 | # toplevel session (i.e. SHLVL=1). this should placate most applications, | |
b31a3fb1 | 75 | # though it is not expressly spec compliant. this may also cause problems |
76 | # with disowned applications that still try to use the directories after | |
77 | # the toplevel shell has already logged out and the dirs removed, but the | |
78 | # chances of that are slim. | |
6d54344e | 79 | if [[ ! -v _sev_tmp ]] { |
b31a3fb1 | 80 | # create personal TMPDIR under system tmp |
81 | t=${TMPDIR:-${TEMPDIR:-${TEMP:-${TMP:-/tmp}}}}/.home-$LOGNAME | |
8d4a98e1 | 82 | [[ -e $t ]] || mkdir -m700 $t 2>/dev/null |
b31a3fb1 | 83 | _sev_tmp=~/.local/tmp |
833b2af3 | 84 | if [[ ! -d $t ]] { |
b31a3fb1 | 85 | # fallback TMPDIR to bare local directory or existing softlink |
833b2af3 | 86 | [[ -o interactive ]] && |
b31a3fb1 | 87 | print -P "%F{orange}*** Can't create tmp dir $t, using $_sev_tmp%f" |
88 | [[ -h $_sev_tmp && ! -d _sev_tmp ]] && unlink $_sev_tmp 2>/dev/null | |
89 | [[ ! -e $_sev_tmp ]] && mkdir -m700 $_sev_tmp 2>/dev/null | |
8d4a98e1 | 90 | if [[ ! -d $_sev_tmp ]] { |
b31a3fb1 | 91 | _sev_tmp=${$(mktemp 2>/dev/null):/tmp} |
8d4a98e1 | 92 | [[ -o interactive ]] && |
b31a3fb1 | 93 | print -P "%F{red}!!! Can't create tmp dir, using $_sev_tmp%f" |
8d4a98e1 | 94 | } |
b31a3fb1 | 95 | } elif [[ -f $_sev_tmp || ( -d $_sev_tmp && ! -h $_sev_tmp ) ]] { |
96 | # file or non-softlink directory is on our local dir | |
8d4a98e1 | 97 | [[ -o interactive ]] && |
b31a3fb1 | 98 | print -P "%F{orange}*** $_sev_tmp exists, can't link to tmp dir $t, ignoring it%f" |
8d4a98e1 | 99 | _sev_tmp=$t |
100 | } else { | |
b31a3fb1 | 101 | # link local dir to tmp dir |
102 | if [[ -h $_sev_tmp && $_sev_tmp:P != $t:P ]] { | |
103 | [[ -o interactive ]] && | |
104 | print -P "%F{orange}*** $_sev_tmp links to ${_sev_tmp:P} and not ${t:P}, unlinking it%f" | |
105 | # XXX: race condition for existing sessions still using this dir | |
106 | unlink $_sev_tmp 2>/dev/null | |
107 | } | |
8d4a98e1 | 108 | ln -s $t $_sev_tmp 2>/dev/null |
109 | } | |
110 | if [[ -v _sev_tmp ]] { | |
111 | # ensure dir is clean | |
112 | _sev_zcleanup tmp | |
113 | # finally create our subdir for this session | |
114 | t=$_sev_tmp/.session.$$ | |
115 | if ! mkdir -m700 $t 2>/dev/null; then | |
116 | [[ -o interactive ]] && | |
b31a3fb1 | 117 | print -P "%F{red}!!! Can't create session tmp subdir $t, using $_sev_tmp%f" |
8d4a98e1 | 118 | t=$_sev_tmp |
119 | fi | |
b31a3fb1 | 120 | export _sev_tmp TMPDIR=$t TEMPDIR=$t TEMP=$t TMP=$t |
833b2af3 | 121 | } |
b31a3fb1 | 122 | unset t |
833b2af3 | 123 | } |
124 | ||
125 | ### xdg | |
79d4a356 | 126 | if [[ ! -v _sev_setup_xdg ]] { |
8d4a98e1 | 127 | ## merge with any existing dirs and remove duplicates using unique arrays |
128 | # NOTE: we are accepting whatever value might be set for CONFIG and DATA; | |
129 | # if it wasn't set, we just use default and leave it unset | |
833b2af3 | 130 | # NOTE: include and then remove CONFIG_HOME and DATA_HOME to ensure they |
131 | # are not present in the array if it was added before we got to it | |
b31a3fb1 | 132 | |
133 | # source user dirs before other vars; technically it is against spec to | |
134 | # include any of the below dirs there, but you never know what crazy shit | |
135 | # people will do. I rather handle them sanely with our own code than let | |
136 | # them override after the fact. | |
137 | [[ -e $XDG_CONFIG_HOME/user-dirs.dirs ]] && | |
138 | emulate sh -c "source $XDG_CONFIG_HOME/user-dirs.dirs" | |
139 | ||
d23b28eb | 140 | typeset -UT XDG_DATA_DIRS xdg_data_dirs |
8d4a98e1 | 141 | if [[ -v XDG_DATA_HOME ]] { |
142 | export XDG_DATA_HOME | |
143 | } elif [[ ! -e ~/.local/share ]] { | |
144 | mkdir -m760 ~/.local/share | |
145 | } | |
146 | xdg_data_dirs=($XDG_DATA_HOME /{opt,usr/local,usr/pkg,usr}/share | |
79d4a356 | 147 | "${XDG_DATA_DIRS:+${xdg_data_dirs[@]}}") |
8d4a98e1 | 148 | # XXX: if colons are not escaped, could remove unintended part of string |
b31a3fb1 | 149 | # TODO: remove empty element via array not scalar |
8d4a98e1 | 150 | export XDG_DATA_DIRS=${XDG_DATA_DIRS#$XDG_DATA_HOME:} |
d23b28eb | 151 | |
8d4a98e1 | 152 | typeset -UT XDG_CONFIG_DIRS xdg_config_dirs |
153 | if [[ -v XDG_CONFIG_HOME ]] { | |
154 | export XDG_CONFIG_HOME | |
155 | } elif [[ ! -e ~/.config ]] { | |
156 | mkdir -m760 ~/.config | |
157 | } | |
158 | # I am of the belief .local should follow FHS /usr/local... | |
159 | [[ -e ~/.local/etc ]] || ln -s ~/.config ~/.local/etc | |
160 | xdg_config_dirs=($XDG_CONFIG_HOME ${XDG_CONFIG_DIRS:+"$xdg_config_dirs[@]"} | |
161 | {/opt,/usr/local,/usr/pkg,}/etc/xdg) | |
162 | # XXX: if colons are not escaped, could remove unintended part of string | |
b31a3fb1 | 163 | # TODO: remove empty element via array not scalar |
8d4a98e1 | 164 | export XDG_CONFIG_DIRS=${XDG_CONFIG_DIRS#$XDG_CONFIG_HOME:} |
6d54344e | 165 | |
8d4a98e1 | 166 | if [[ -v XDG_STATE_HOME ]] { |
167 | export XDG_STATE_HOME | |
168 | } elif [[ ! -e ~/.local/state ]] { | |
169 | mkdir -m760 ~/.local/state | |
170 | } | |
d23b28eb | 171 | |
72de94eb | 172 | if [[ -v XDG_CACHE_HOME ]] { |
173 | export XDG_CACHE_HOME | |
174 | } else { | |
8d4a98e1 | 175 | if [[ -v _sev_tmp ]] { |
176 | export XDG_CACHE_HOME=$_sev_tmp/.xdg.cache | |
177 | [[ -e $XDG_CACHE_HOME ]] || mkdir -m700 $XDG_CACHE_HOME | |
178 | } elif [[ ! -e ~/.cache ]] { | |
179 | mkdir -m700 ~/.cache | |
180 | } | |
181 | } | |
182 | ||
e69caf64 | 183 | if [[ -v XDG_RUNTIME_DIR ]] { |
184 | export XDG_RUNTIME_DIR | |
b31a3fb1 | 185 | } elif [[ -v TMPDIR ]] { |
e69caf64 | 186 | # make runtime dir in our session-specific tmpdir |
187 | export XDG_RUNTIME_DIR=$TMPDIR/.xdg.runtime | |
188 | # same as in tmpdir creation, ensure dir doesn't exist | |
189 | if [[ -h $XDG_RUNTIME_DIR ]] { | |
190 | unlink $XDG_RUNTIME_DIR 2>/dev/null | |
191 | } elif [[ -e $XDG_RUNTIME_DIR ]] { | |
192 | rm -rf $XDG_RUNTIME_DIR 2>/dev/null | |
193 | } | |
194 | mkdir -m700 $XDG_RUNTIME_DIR 2>/dev/null | |
6d54344e | 195 | } |
d23b28eb | 196 | |
79d4a356 | 197 | export _sev_setup_xdg= |
d569f3f7 | 198 | } |
79d4a356 | 199 | |
6d54344e | 200 | ### dbus |
201 | if [[ ! -v DBUS_SESSION_BUS_ADDRESS && -v commands[dbus-launch] ]] { | |
202 | eval $(dbus-launch) | |
203 | export DBUS_SESSION_BUS_ADDRESS DBUS_SESSION_BUS_PID | |
204 | } | |
205 | ||
206 | ### gpg home | |
207 | if [[ ! -v GNUPGHOME ]] { | |
8d4a98e1 | 208 | export GNUPGHOME=${XDG_CONFIG_HOME:-~/.config}/gnupg |
b31a3fb1 | 209 | # move existing gnupg dir to our new home |
210 | if [[ -d ~/.gnupg && ! -d $GNUPGHOME ]] { | |
211 | mv ~/.gnupg $GNUPGHOME | |
6d54344e | 212 | } |
213 | } | |
214 | ||
215 | ### gpg agent + forwarding | |
b31a3fb1 | 216 | # NOTE: while ssh manages its auth sock in-protocol when ForwardSsh is enabled, |
217 | # GPG must be forwarded manually over Unix socket. to support this, we | |
218 | # forward the restricted gpg-agent extra socket to the remote host with a | |
219 | # RemoteForward rule in ~/.ssh/config that uses the _GNUPG_SOCK_* vars. | |
220 | # | |
221 | # to avoid conflicts with other ssh sessions where the same user is | |
222 | # connecting to the same host from different machines, gpg should utilize | |
223 | # its own forwarded socket for each session. previously, you could | |
224 | # provide a path to the agent socket in GPG_AGENT_INFO, but that was | |
225 | # deprecated in GPG v2.1; instead, we must replace the socket in gpg's | |
226 | # socket dir. | |
227 | # | |
228 | # gnupg commits fb88f37–aab8a0b moved sockets from GNUPGHOME by default | |
229 | # to directories under /run. aab8a0b in particular solidifies the | |
230 | # functionality shift to utilize systemd-logind's user runtime | |
231 | # directories. if the dir isn't found, gpg will fall back to the homedir. | |
232 | # since previous functionality allowed multiple homedirs with multiple | |
233 | # sockets, a provision was added where changing GNUPGHOME will also | |
234 | # change the socket dir to a hashed dir under the usual runtime dir. | |
235 | # | |
236 | # utilizing this information, we can conclude: | |
237 | # - on systems with user runtime dirs, changing GNUPGHOME will also | |
238 | # give us a unique socket dir under the user runtime dir; | |
239 | # - on other systems, the socket dir follows GNUPGHOME. | |
240 | # therefore, the safest way to ensure unique sockets while not having to | |
241 | # write specific logic for both scenarios is to simply change GNUPGHOME. | |
242 | # the easiest way to do this is to create a new dir and link the contents | |
243 | # of GNUPGHOME to the new home. we can then replace the agent sockets | |
244 | # there with the forwarded one. | |
245 | # | |
79d4a356 | 246 | # NOTE: since Unix sockets are not supported under Windows, this will not work |
833b2af3 | 247 | # under msys, cygwin, mingw, etc., but may work under wsl2. |
b31a3fb1 | 248 | # |
79d4a356 | 249 | # HACK: without SendEnv, which is disabled by default in most sshd configs, |
b31a3fb1 | 250 | # there is no foolproof way to prevent race conditions via socket |
251 | # filename collisions or to pass the desired forward path to the remote | |
252 | # host environment. we just have to guess the path we choose is good on | |
253 | # the desination, and assume the newest matching socket is the correct | |
254 | # one after connecting. in theory, we could occlude the ssh binary on | |
255 | # PATH with an alias or script that would allow us to communicate with | |
256 | # the remote host before opening a shell, so that we can have the host | |
79d4a356 | 257 | # communicate back to the client where it wants a socket created or ask |
258 | # the host if the path the client wants to use is writable. however, this | |
8d4a98e1 | 259 | # would open up too many edge cases where it wouldn't work or be too |
260 | # clunky (e.g. asking for password twice) to make it worth it. | |
6d54344e | 261 | function _gpg_socketpath { |
262 | # dirs are percent-encoded: https://stackoverflow.com/a/64312099 | |
263 | echo ${1//(#b)%([[:xdigit:]](#c2))/${(#):-0x$match[1]}} | |
264 | } | |
265 | if [[ ! -v _sev_setup_gpg_forward && -v commands[gpg] ]] { | |
b31a3fb1 | 266 | # XXX: assuming /tmp exists and is writable on destination |
6d54344e | 267 | export _GNUPG_SOCK_DEST_BASE=/tmp/.gpg-agent-forward |
268 | export _GNUPG_SOCK_DEST_EXT=$(date +%s).$RANDOM | |
269 | export _GNUPG_SOCK_DEST=$_GNUPG_SOCK_DEST_BASE.$_GNUPG_SOCK_DEST_EXT | |
b31a3fb1 | 270 | export _sev_gpg_forward_dir=$XDG_RUNTIME_DIR/gnupg/.ssh_forward |
6d54344e | 271 | _sev_zcleanup gpg-forward |
79d4a356 | 272 | |
6d54344e | 273 | # find our forwarded socket |
274 | s=($_GNUPG_SOCK_DEST_BASE*(N=oc[1])) | |
275 | if [[ -n $s && -v SSH_CLIENT ]] { | |
276 | # create new forward dir | |
277 | export _sev_setup_gpg_forward= | |
278 | h=$_sev_gpg_forward_dir/$$ | |
279 | mkdir -pm700 $h | |
b31a3fb1 | 280 | for x (gpg{,-agent}.conf sshcontrol random_seed |
d9cf4c48 | 281 | pubring.kbx{,~} trustdb.gpg private-keys-v1.d crls.d) { |
6d54344e | 282 | ln -s ${GNUPGHOME:-~/.gnupg}/$x $h |
79d4a356 | 283 | } |
6d54344e | 284 | export GNUPGHOME=$h |
285 | unset h | |
286 | for x in $(gpgconf --list-dirs | grep 'agent-.*-\?socket:'); do | |
287 | x=$(_gpg_socketpath ${x/#agent-*socket:}) | |
b31a3fb1 | 288 | if [[ ! -v primary ]] { |
6d54344e | 289 | # move forwarded socket to first valid agent socket path |
290 | # XXX: if tmp is on different filesystem this may not work | |
291 | mv $s $x | |
b31a3fb1 | 292 | primary=$x |
6d54344e | 293 | } else { |
294 | # make links to forwarded socket for any others | |
b31a3fb1 | 295 | ln -s $primary $x |
6d54344e | 296 | } |
297 | done | |
b31a3fb1 | 298 | unset x primary |
6d54344e | 299 | } |
300 | unset s | |
79d4a356 | 301 | |
6d54344e | 302 | # what we will forward if we start a new ssh connection |
303 | # NOTE: do this after setting up GNUPGHOME to pick up new socket path; | |
304 | # if already connected over SSH, extra should be the remote one | |
305 | export _GNUPG_SOCK_SRC=$(_gpg_socketpath \ | |
306 | $(gpgconf --list-dirs agent-extra-socket)) | |
307 | } elif [[ ! -v _sev_setup_gpg_forward ]] { | |
308 | # required for RemoteForward to not error out if the vars are unset | |
309 | [[ ! -v _GNUPG_SOCK_SRC ]] && export _GNUPG_SOCK_SRC=/nonexistent | |
310 | [[ ! -v _GNUPG_SOCK_DEST ]] && export _GNUPG_SOCK_DEST=/nonexistent | |
311 | } | |
79d4a356 | 312 | |
6d54344e | 313 | ### gpg agent |
8d4a98e1 | 314 | if [[ -v commands[gpg-connect-agent] && |
315 | ( ! -v _sev_setup_gpgagent || -v _sev_refresh_gpgagent ) ]] { | |
6d54344e | 316 | # avoid printing if we have already set up tty before |
317 | [[ ! -v _sev_setup_gpgagent && -o interactive ]] && p=true || p=false | |
318 | if {$p} { | |
319 | print -nP '%F{blue}>>>%f GPG: ' | |
320 | if [[ -v _sev_setup_gpg_forward ]] { | |
d42865fe | 321 | print -nP '%F{yellow}Forwarded agent ' |
322 | } else { | |
323 | print -nP '%F{green}Agent ' | |
324 | } | |
79d4a356 | 325 | } |
6d54344e | 326 | gpg-connect-agent /bye >/dev/null 2>&1 |
327 | if [[ $? -ne 0 ]] { | |
d42865fe | 328 | $p && print -P '%F{red}communication error' |
6d54344e | 329 | } else { |
d42865fe | 330 | if [[ ! -v _sev_setup_gpg_forward ]] { |
331 | if [[ ${+GPG_TTY} -eq 0 && -o interactive ]] | |
332 | export GPG_TTY=$(tty) | |
333 | if [[ ( -v DISPLAY || -v WAYLAND_DISPLAY ) && | |
334 | ${PINENTRY_USER_DATA/USE_TTY=0} == $PINENTRY_USER_DATA ]] | |
335 | export PINENTRY_USER_DATA=USE_TTY=$(( | |
336 | ${+DISPLAY} + ${+WAYLAND_DISPLAY} == 0)) | |
337 | # XXX: don't know if gpg-agent supports comments after directives | |
338 | # XXX: path could have # | |
54a85d6c | 339 | # XXX: we are assuming this is our pinentry from .local/bin |
b31a3fb1 | 340 | sed -Ei 's#^([[:space:]]*pinentry-program[[:space:]]).*$#\1'$HOME'/.local/bin/pinentry#' \ |
54a85d6c | 341 | ${GNUPGHOME:-~/.gnupg}/gpg-agent.conf 2>/dev/null |
d42865fe | 342 | # XXX: could check for changes before doing this to save perf |
343 | gpg-connect-agent RELOADAGENT UPDATESTARTUPTTY /bye >/dev/null 2>&1 | |
344 | if {$p} { | |
345 | gpg-connect-agent /subst /serverpid \ | |
346 | "/echo pid \${get serverpid} on $GPG_TTY" /bye 2>/dev/null | |
347 | print -nP '%f' | |
348 | } | |
349 | } elif {$p} { | |
350 | print -P '%f' | |
351 | } | |
6d54344e | 352 | export _sev_setup_gpgagent= |
79d4a356 | 353 | } |
8d4a98e1 | 354 | unset p _sev_refresh_gpgagent |
6d54344e | 355 | } |
79d4a356 | 356 | |
6d54344e | 357 | ### ssh agent |
358 | if [[ ! -v _sev_setup_ssh ]] { | |
79d4a356 | 359 | # NOTE: preferred order of agents to check: okcagent, gnupg, openssh |
360 | # first block takes care of okcagent and openssh, second gnupg | |
6d54344e | 361 | # XXX: doesn't actually check if ssh is enabled in gpg |
79d4a356 | 362 | [[ -o interactive ]] && print -nP '%F{blue}>>>%f SSH: %F{green}' |
363 | if [[ ! -v SSH_AUTH_SOCK && ( -v commands[okc-ssh-agent] || | |
364 | ( -v commands[ssh-agent] && ! -v commands[gpg] ) ) ]] { | |
365 | okc=${commands[okc-ssh-agent]:+okc-} | |
e6e7ad69 | 366 | e=$_sev_tmp/${okc}ssh-agent-exports |
79d4a356 | 367 | typeset sock= |
368 | typeset -i pid= | |
6d54344e | 369 | if [[ -f $e ]] { |
370 | IFS=$'\0' read -r sock pid <$e | |
79d4a356 | 371 | } |
372 | if [[ -S $sock && $pid > 0 ]] && kill -0 $pid; then | |
373 | [[ -o interactive ]] && print -P "Reusing agent PID $pid%f" | |
374 | export SSH_AUTH_SOCK=$sock | |
375 | export SSH_AGENT_PID=$pid | |
376 | else | |
79d4a356 | 377 | # TODO: ensure ssh-agent path looks legit to avoid unsafe eval? |
378 | # XXX: doesn't appear to be any other way to handle redirection. | |
379 | # because eval needs to write to current scope environment | |
380 | # subshells can't be used to capture output and print. | |
e6e7ad69 | 381 | c='TMPDIR=$_sev_tmp ${okc}ssh-agent' |
79d4a356 | 382 | if [[ -o interactive ]] { |
e6e7ad69 | 383 | eval $(eval $=c) |
79d4a356 | 384 | print -nP '%f' |
385 | } else { | |
e6e7ad69 | 386 | eval $(eval $=c) >/dev/null 2>&1 |
79d4a356 | 387 | } |
6d54344e | 388 | echo -n $SSH_AUTH_SOCK$'\0'$SSH_AGENT_PID >!$e |
e6e7ad69 | 389 | unset c |
79d4a356 | 390 | fi |
e6e7ad69 | 391 | unset okc e sock pid |
79d4a356 | 392 | } elif [[ ! -v SSH_AUTH_SOCK && -v commands[gpg] ]] { |
6d54344e | 393 | # since gpg should have been started above, just export and notify |
79d4a356 | 394 | if [[ -o interactive ]] { |
6d54344e | 395 | if [[ -v _sev_setup_gpg_forward ]] { |
396 | echo 'Forwarded GPG agent' | |
79d4a356 | 397 | } else { |
398 | gpg-connect-agent /subst /serverpid \ | |
6d54344e | 399 | '/echo GPG agent pid ${get serverpid}' /bye |
79d4a356 | 400 | } |
401 | print -nP '%f' | |
402 | } | |
6d54344e | 403 | export SSH_AUTH_SOCK=$(_gpg_socketpath \ |
79d4a356 | 404 | $(gpgconf --list-dirs agent-ssh-socket)) |
405 | } elif [[ -v SSH_AUTH_SOCK ]] { | |
406 | [[ -o interactive ]] && print -P 'Preconfigured agent%f' | |
407 | } else { | |
408 | [[ -o interactive ]] && print -P '%F{red}No agent available%f' | |
409 | } | |
410 | ||
6d54344e | 411 | export _sev_setup_ssh= |
79d4a356 | 412 | } |
6d54344e | 413 | unfunction _gpg_socketpath |
79d4a356 | 414 | |
6d54344e | 415 | ### perl local lib |
416 | [[ -v commands[perl] && -d $XDG_DATA_HOME/perl5/lib/perl5 && | |
417 | ! -v PERL_LOCAL_LIB_ROOT ]] && | |
418 | eval $(perl -I$XDG_DATA_HOME/perl5/lib/perl5 \ | |
833b2af3 | 419 | -Mlocal::lib=$XDG_DATA_HOME/perl5 2>/dev/null) |
79d4a356 | 420 | |
833b2af3 | 421 | ### load site-specific |
4ced48ed | 422 | load-site-dotfile zprofile |