diff options
author | xrs <xrs@mail36.net> | 2020-01-16 17:11:58 +0100 |
---|---|---|
committer | xrs <xrs@mail36.net> | 2020-01-16 17:11:58 +0100 |
commit | ec78709681261eaddedbed6484dd95849f180f92 (patch) | |
tree | 15614d8fa324e1239ec200a9e89ffd7a7233a017 /contrib/packages/alpine/gnunet/gnunet-gns-proxy.initd | |
parent | 9b33cb121ded68247bc7a9388bf41e46063cd812 (diff) | |
download | gnunet-ec78709681261eaddedbed6484dd95849f180f92.tar.gz gnunet-ec78709681261eaddedbed6484dd95849f180f92.zip |
add new versions of alpine packages (not yet in alpine repo)
Diffstat (limited to 'contrib/packages/alpine/gnunet/gnunet-gns-proxy.initd')
-rw-r--r-- | contrib/packages/alpine/gnunet/gnunet-gns-proxy.initd | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/contrib/packages/alpine/gnunet/gnunet-gns-proxy.initd b/contrib/packages/alpine/gnunet/gnunet-gns-proxy.initd new file mode 100644 index 000000000..3c5a22ee2 --- /dev/null +++ b/contrib/packages/alpine/gnunet/gnunet-gns-proxy.initd | |||
@@ -0,0 +1,107 @@ | |||
1 | #!/sbin/openrc-run | ||
2 | # Contributor: xrs <xrs@mail36.net> | ||
3 | # Maintainer: xrs <xrs@mail36.net> | ||
4 | |||
5 | name="gnunet-gns-proxy" | ||
6 | description="GNUnet GNS proxy for name resolution in Firefox/Chromium" | ||
7 | command_background="yes" | ||
8 | pidfile="/run/${SVCNAME}.pid" | ||
9 | users=`awk -F ':' '$3>=1000 && $3<2000 {print $1}' /etc/passwd` | ||
10 | |||
11 | depend() { | ||
12 | need gnunet-user-services | ||
13 | } | ||
14 | |||
15 | start() { | ||
16 | # Enable GNS proxy for existant users. | ||
17 | for user in $users; do | ||
18 | # Create/Renew GNS certificate authority (CA) per user. | ||
19 | su $user -c "gnunet-gns-proxy-setup-ca" | ||
20 | |||
21 | # Customize gnunet.conf | ||
22 | port=$((8000+$(id -u $user))) | ||
23 | gnunet-config -c /home/$user/.config/gnunet.conf \ | ||
24 | --rewrite \ | ||
25 | --section=gns-proxy \ | ||
26 | --option=IMMEDIATE_START \ | ||
27 | --value=YES | ||
28 | gnunet-config -c /home/$user/.config/gnunet.conf \ | ||
29 | --rewrite \ | ||
30 | --section=gns-proxy \ | ||
31 | --option=OPTIONS \ | ||
32 | --value="-p $port" | ||
33 | |||
34 | # Start gns-proxy | ||
35 | if test -z "`ps|grep $user|grep gnunet-gns-proxy`" > /dev/null 2>&1 | ||
36 | then | ||
37 | su $user -c "gnunet-arm \ | ||
38 | -c /home/$user/.config/gnunet.conf -i gns-proxy" | ||
39 | fi | ||
40 | |||
41 | # Firefox | ||
42 | if [ ! -d /home/$user/.mozilla/firefox/*.default ];then | ||
43 | timeout 3s firefox --headless # dirty: create profile if not existent | ||
44 | fi | ||
45 | for ffprofile in /home/$user/.mozilla/firefox/*.*/; do | ||
46 | js=$ffprofile/user.js | ||
47 | if [ -f $js ]; then | ||
48 | sed -i '/Preferences for using the GNU Name System/d' $js | ||
49 | sed -i '/network.proxy.socks/d' $js | ||
50 | sed -i '/network.proxy.socks_port/d' $js | ||
51 | sed -i '/network.proxy.socks_remote_dns/d' $js | ||
52 | sed -i '/network.proxy.type/d' $js | ||
53 | fi | ||
54 | echo "// Preferences for using the GNU Name System" >> $js | ||
55 | echo "user_pref(\"network.proxy.socks\", \"localhost\");" >> $js | ||
56 | echo "user_pref(\"network.proxy.socks_port\", $port);" >> $js | ||
57 | echo "user_pref(\"network.proxy.socks_remote_dns\", true);" >> $js | ||
58 | echo "user_pref(\"network.proxy.type\", 1);" >> $js | ||
59 | done | ||
60 | |||
61 | # Chromium | ||
62 | profile=/home/$user/.profile | ||
63 | if [ -f $profile ]; then | ||
64 | sed -i '/CHROMIUM_USER_FLAGS/d' $profile | ||
65 | fi | ||
66 | echo "export CHROMIUM_USER_FLAGS=--proxy-server=socks5://localhost:$port" \ | ||
67 | >> $profile | ||
68 | done | ||
69 | } | ||
70 | |||
71 | stop() { | ||
72 | for user in $users; do | ||
73 | # Stop gns-proxy | ||
74 | if test "`ps|grep $user|grep gnunet-gns-proxy`" > /dev/null 2>&1 | ||
75 | then | ||
76 | su $user -c "gnunet-arm \ | ||
77 | -c /home/$user/.config/gnunet.conf -k gns-proxy" | ||
78 | fi | ||
79 | |||
80 | # Disable gns-proxy in config | ||
81 | gnunet-config -c /home/$user/.config/gnunet.conf \ | ||
82 | --rewrite \ | ||
83 | --section=gns-proxy \ | ||
84 | --option=IMMEDIATE_START \ | ||
85 | --value=NO | ||
86 | |||
87 | # Reset proxy preferences | ||
88 | for ffprofile in /home/$user/.mozilla/firefox/*.*/; do | ||
89 | for file in user.js prefs.js; do | ||
90 | js=$ffprofile/$file | ||
91 | if [ -f $js ]; then | ||
92 | sed -i '/Preferences for using the GNU Name System/d' $js | ||
93 | sed -i '/network.proxy.socks/d' $js | ||
94 | sed -i '/network.proxy.socks_port/d' $js | ||
95 | sed -i '/network.proxy.socks_remote_dns/d' $js | ||
96 | sed -i '/network.proxy.type/d' $js | ||
97 | fi | ||
98 | done | ||
99 | done | ||
100 | |||
101 | # Chromium | ||
102 | profile=/home/$user/.profile | ||
103 | if [ -f $profile ]; then | ||
104 | sed -i '/CHROMIUM_USER_FLAGS/d' $profile | ||
105 | fi | ||
106 | done | ||
107 | } | ||