aboutsummaryrefslogtreecommitdiff
path: root/debian/gnunet.postinst
blob: fe36500c07120320f178c2fb0c1259e68cf1be41 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#!/bin/bash

set -e

. /usr/share/debconf/confmodule

# This is taken from the package libnss-mdns and edited to do the same thing
# but for GNS insteand of mdns. try to insert gns entries to the "hosts" line
# in /etc/nsswitch.conf to automatically enable nss-gns support; do not change
# the configuration if the "hosts" line already references some gns lookups
insert_gns() {
  echo -n "Checking NSS setup..."
  # abort if /etc/nsswitch.conf does not exist
  if ! [ -e /etc/nsswitch.conf ]; then
    echo "Could not find /etc/nsswitch.conf."
    return 1
  fi
  perl -i -pe '
		sub insert {
			# this also splits on tab
			my @bits=split(" ", shift);
			# do not break configuration if the "hosts" line already references gns
			if (grep { $_ eq "gns"} @bits) {
				return join " ", @bits;
			}
			# change "dns" or "resolve", whichever comes first, into
			# "gns [NOTFOUND=return] dns"
			foreach my $bit (@bits) {
				if ($bit eq "dns") {
					$bit = "gns [NOTFOUND=return] $bit";
					last;
				}
			}
			return join " ", @bits;
		}
		s/^(hosts:\s+)(.*)/$1.insert($2)/e;
	' /etc/nsswitch.conf
  echo " done."
}

case "${1}" in
configure)
  db_version 2.0

  _USERNAME="gnunet"
  _GROUPNAME="gnunet"

  db_get gnunet-systempeer/autostart
  _AUTOSTART="${RET}" # boolean

  db_get gnunet-dns/libnsswitch
  _LIBNSSWITCH="${RET}" # boolean

  db_get gnunet-user/proxy
  _PROXY="${RET}" # boolean

  db_stop

  # Read default values
  GNUNET_HOME="/var/lib/gnunet"

  # Creating gnunet group if needed
  if ! getent group ${_GROUPNAME} >/dev/null; then
    echo -n "Creating new GNUnet group ${_GROUPNAME}:"
    addgroup --quiet --system ${_GROUPNAME}
    echo " done."
  fi

  # Creating gnunet user if needed
  if ! getent passwd ${_USERNAME} >/dev/null; then
    echo -n "Creating new GNUnet user ${_USERNAME}:"
    adduser --quiet --system --ingroup ${_GROUPNAME} --home ${GNUNET_HOME} ${_USERNAME}
    echo " done."
  fi

  # Add a special secured group
  GNUNETDNS_GROUP="gnunetdns"

  # Creating gnunetdns group if needed
  if ! getent group ${GNUNETDNS_GROUP} >/dev/null; then
    echo -n "Creating new secured GNUnet group ${GNUNETDNS_GROUP}:"
    addgroup --quiet --system ${GNUNETDNS_GROUP}
    echo " done."
  fi

  # Copy the libnss_gns files to the libnss directory
  if ${_LIBNSSWITCH}; then
    echo "Editing /etc/nsswitch.conf to use GNS before DNS"
    # $2 equals the currently installed version if it exists
    if [ -z "$2" ]; then
      # first install: setup the recommended configuration (unless
      # nsswitch.conf already contains mdns entries)
      insert_gns
      if [ "$?" -gt 0 ]; then
        echo "nsswitch does not exist on this system"
      fi
    fi
    echo " done."
  fi

  #	# Change the proxy settings for Firefox and Chromium if desired
  #		if ${_PROXY}
  #        then
  #		    mkdir -p /etc/X11/xinit/xinitrc.d/
  #cat > "/etc/X11/xinit/xinitrc.d/80-gnunet-user-services" << "EOF"
  ##!/bin/bash
  #systemctl --user daemon-reload
  #systemctl --user start gnunet-user
  #systemctl --user enable gnunet-user
  #user=$(whoami)
  #gnunet_proxy=$(gnunet-config -c /etc/skel/.config/gnunet.conf -s gns-proxy | grep 'IMMEDIATE_START = YES')
  #
  ## Enable GNS proxy for new users informed by /etc/skel.
  #if [ "$gnunet_proxy" ]; then
  #
  #        # Calculate user specific port
  #        port=$((8000+$(id -u $user)))
  #
  #        gnunet-config -c $HOME/.config/gnunet.conf \
  #                --section=gns-proxy \
  #                --option=OPTIONS \
  #                --value="-p $port"
  #
  #        # Firefox
  #        defaultprofile=$(ls $HOME/.mozilla/firefox/*.default)
  #        if [ ! "$defaultprofile" ];then
  #                timeout 3s firefox --headless # dirty: create profile if not existent
  #        fi
  #        for ffprofile in $HOME/.mozilla/firefox/*.*/; do
  #                js=$ffprofile/user.js
  #                if [ -f "$js" ]; then
  #                        sed -i '/Preferences for using the GNU Name System/d' "$js"
  #                        sed -i '/network.proxy.socks/d' "$js"
  #                        sed -i '/network.proxy.socks_port/d' "$js"
  #                        sed -i '/network.proxy.socks_remote_dns/d' "$js"
  #                        sed -i '/network.proxy.type/d' "$js"
  #                fi
  #                echo "// Preferences for using the GNU Name System" >> "$js"
  #                echo "user_pref(\"network.proxy.socks\", \"localhost\");" >> "$js"
  #                echo "user_pref(\"network.proxy.socks_port\", $port);" >> "$js"
  #                echo "user_pref(\"network.proxy.socks_remote_dns\", true);" >> "$js"
  #                echo "user_pref(\"network.proxy.type\", 1);" >> "$js"
  #        done
  #
  #        # Chromium
  #        profile="$HOME/.profile"
  #        if [ -f "$profile" ]; then
  #                sed -i '/CHROMIUM_USER_FLAGS/d' "$profile"
  #        fi
  #        echo "export CHROMIUM_USER_FLAGS=--proxy-server=socks5://localhost:$port" \
  #                >> "$profile"
  #fi
  #
  ## Create/Renew GNS certificate authority (CA) per user.
  #gnunet-gns-proxy-setup-ca
  #EOF
  #                fi

  # Update files and directories permissions.
  # Assuming default values, this *should* not be changed.
  echo -n "Updating files and directories permissions:"
  # Secure access to the data directory
  chmod 0700 "${GNUNET_HOME}" || true
  # Restrict access on setuid binaries
  for file in /usr/bin/gnunet-helper-exit \
    /usr/bin/gnunet-helper-nat-client \
    /usr/bin/gnunet-helper-nat-server \
    /usr/bin/gnunet-helper-transport-bluetooth \
    /usr/bin/gnunet-helper-transport-wlan \
    /usr/bin/gnunet-helper-vpn; do
    # only do something when no setting exists
    if ! dpkg-statoverride --list $file >/dev/null 2>&1 && [ -e $file ]; then
      chown root:${_GROUPNAME} $file
      chmod 4750 $file
    fi
  done
  if ! dpkg-statoverride --list /usr/bin/gnunet-helper-dns >/dev/null 2>&1 &&
    [ -e /usr/bin/gnunet-helper-dns ]; then
    chown root:${GNUNETDNS_GROUP} /usr/bin/gnunet-helper-dns
    chmod 4750 /usr/bin/gnunet-helper-dns
  fi
  if ! dpkg-statoverride --list /usr/bin/gnunet-service-dns >/dev/null 2>&1 &&
    [ -e /usr/bin/gnunet-service-dns ]; then
    chown ${_USERNAME}:${GNUNETDNS_GROUP} /usr/bin/gnunet-service-dns
    chmod 2750 /usr/bin/gnunet-service-dns
  fi
  echo " done."

  echo "All done."

  ;;

abort-upgrade | abort-remove | abort-deconfigure) ;;

\
  \
  *)
  echo "postinst called with unknown argument \`${1}'" >&2
  exit 1
  ;;
esac

#DEBHELPER#

exit 0