df276659f6cf683d4206d308cc05de26ef4bcb1c
[distro-setup] / filesystem / etc / profile.d / environment.sh
1 #!/bin/sh
2 if [ -f $HOME/path-add-function ]; then
3 . $HOME/path-add-function
4 path-add /usr/sbin /usr/local/sbin /sbin /a/exe /a/opt/bin
5 path-add --end $HOME/.cabal/bin
6 path-add --end /snap/bin
7
8
9 for p in $HOME/.gem/ruby/*/bin; do
10 path-add --ifexists --end $p
11 done
12
13 if [ -r /etc/alternatives/java_sdk ]; then
14 export JAVA_HOME=/etc/alternatives/java_sdk
15 path-add /etc/alternatives/java_sdk
16 fi
17
18 export GUIX_PROFILE=/root/.config/guix/current
19 if [ -f $GUIX_PROFILE/etc/profile ]; then
20 . $GUIX_PROFILE/etc/profile
21 fi
22 path-add $HOME/.guix-profile/bin
23 export GUIX_LOCPATH=$HOME/.guix-profile/lib/locale
24
25 fi
26
27
28 export EDITOR="emacsclient"
29 # this makes emacsclient file/-c start a server instance if none is running,
30 # instead of some alternate editor logic
31 export ALTERNATE_EDITOR=""
32
33 export PITHOSFLY_SAVE_DIR=/a/pandora_rips4
34
35 # makes subsequent syscalls to localtime use cached timezone,
36 # so basically restart the comp if you change time zones,
37 # and avoid a few syscalls, which makes a tiny tiny perf difference.
38 # I also set this in
39 # /a/c/filesystem/etc/systemd/system.conf.d/tz.conf
40 # https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
41 export TZ=:/etc/localtime
42
43 # ubuntu starts gpg agent automatically with /etc/X11/Xsession.d/90gpg-agent.
44 # fedora doesn't, which left me to figure this out, and google was no help.
45 # fedora documentation is often quite bad :(
46 # This is mostly copied from that file.
47 # Main difference is that we eval the result of starting gpg-agent,
48 # while that file executes it through xsession specific var.
49 # Also make sourcing the pidfile make more sense.
50 # End result should be the same afaik.
51 # for gpg-agent to work when calling gpg from the command line,
52 # we need an environment variable that is setup via the eval.
53 # which is why we do this upon login, so it can propogate
54 # It is also written to the file $HOME/.gnupg/gpg-agent-info-$(hostname)
55 # I'm not aware if that is ever used, but just fyi.
56 # I also added the bit about xmessaging the stderr,
57 # because I'd like to know if the command fails
58 if [ -f /etc/fedora-release ]; then
59 : ${GNUPGHOME=$HOME/.gnupg}
60
61 GPGAGENT=/usr/bin/gpg-agent
62 PID_FILE="$GNUPGHOME/gpg-agent-info-$(hostname)"
63
64 if ! $GPGAGENT 2>/dev/null; then
65 temp="$(mktemp)"
66 eval "$($GPGAGENT --homedir /p/do-not-delete --daemon --sh --write-env-file=$PID_FILE 2>$temp)"
67 temperr="$(cat "$temp")"
68 [ -n "$temperr" ] && xmessage "gpg-agent stderr: $temperr"
69 elif [ -r "$PID_FILE" ]; then
70 . "$PID_FILE"
71 export GPG_AGENT_INFO
72 fi
73 fi
74
75 # and broken again. see /usr/lib/systemd/user-environment-generators/90gpg-agent
76 export GPG_AGENT_INFO=$XDG_RUNTIME_DIR/gnupg/S.gpg-agent:0:1
77
78 # and now trisquel9 + mate + i3 has broken ssh agent. I've had to fix
79 # ssh or gpg agent like 10 times in different distros, and once again, i
80 # randomly figured out this hack because there is no documentation. ssh
81 # agent is started by a systemd service, which runs a wrapper script,
82 # which adds env vars with some dbus thing. This is too much of a pita
83 # to make work in ash/posix. I could just export the agent relevant
84 # vars, but it seems like its better to just get whatever is missing,
85 # but not override existing things because theres stuff like PWD. This
86 # doesn't set SSH_AGENT_PID, but apparently its not needed anymore.
87 # Note: what a huge pita to write this in posix shell.
88 if test "$EUID" && [ "$EUID" != 0 ]; then
89 _sysenv=$(mktemp)
90 _sysenvnames=$(mktemp)
91 _unsetnames=$(mktemp)
92 if systemctl --user show-environment >$_sysenv 2>/dev/null; then
93 grep -o '^[^=]*' $_sysenv | sort > $_sysenvnames
94 env -0 | grep -zo '^[^=]*' | xargs -0 printf "%s\n" | sort | \
95 comm --nocheck-order -13 - $_sysenvnames >$_unsetnames
96 while read -r unsetname; do
97 while read -r sysenv; do
98 case "$sysenv" in
99 "$unsetname"*) eval export "$sysenv" ;;
100 esac
101 done < $_sysenv
102 done < $_unsetnames
103 rm -f $_tmpf
104 fi
105 fi
106 # and it seems that if we log into mate, it screws up the systemd env var anyways.
107 for _file in $(pgrep -a '^ssh-agent$' | sed -r 's/.*-a *([^ ]+).*/\1/'); do
108 if test -O "$_file"; then
109 export SSH_AUTH_SOCK="$_file"
110 break
111 fi
112 done
113
114
115 # background:
116 # ubuntu has 002 for non-system users, debian has 022. 002 makes groups
117 # be rw instead of r.
118 #
119 # I think the actual setting is somewhere in the pam settings, I haven't
120 # bothered to figure that out.
121 #
122 # ubuntu is more user friendly when using multiple users. However,
123 # it also makes it so if you create a file as a regular user then move
124 # it to become a system file, it's got slightly wrong permissions, and
125 # sometimes thing break. Also, copying files between ubuntu and debian
126 # makes things inconsistent. So stick with 022 umask always.
127 #
128 # One security concern is where some unixes put every user in a same
129 # group, so if you copy files there with exact perms, that is probably
130 # not what you want. I don't use a system like that, so I don't
131 # care.
132 umask 022
133 # this is how we could test for non-system user
134
135 #if test "$(id -u)" -ge 1000; then : fi