File: postinst

package info (click to toggle)
ntlmaps 0.9.9.0.1-11.5
  • links: PTS
  • area: main
  • in suites: buster, stretch
  • size: 520 kB
  • ctags: 222
  • sloc: python: 2,538; sh: 160; makefile: 3
file content (115 lines) | stat: -rw-r--r-- 3,764 bytes parent folder | download | duplicates (3)
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
#!/bin/sh -e

. /usr/share/debconf/confmodule

# write selected values into config file
CONFIG_FILE=/etc/ntlmaps/server.cfg

LISTENPORT_ENTRY=LISTEN_PORT
PARENTPROXY_ENTRY=PARENT_PROXY
PARENTPROXYPORT_ENTRY=PARENT_PROXY_PORT
NTDOMAIN_ENTRY=NT_DOMAIN
NTUSER_ENTRY=USER
NTPASSWD_ENTRY=PASSWORD


# copy configuration file template if necessary
if [ ! -e $CONFIG_FILE ] ; then
	cp /usr/share/ntlmaps/server.cfg /etc/ntlmaps/
	# the config file may contain passwords, so make it non-world-readable
	chmod 600 $CONFIG_FILE 
fi

LISTENPORT=5865
db_get ntlmaps/listen_port
LISTENPORT="$RET"
# insert the entry, if it is missing (which it ought not to be)
grep -Eq "^[[:blank:]]*$LISTENPORT_ENTRY:" $CONFIG_FILE || \
    echo "$LISTENPORT_ENTRY: $LISTENPORT" >> $CONFIG_FILE 

PARENTPROXY=your_parentproxy
db_get ntlmaps/parent_proxy
PARENTPROXY="$RET"
# insert the entry, if it is missing (which it ought not to be)
grep -Eq "^[[:blank:]]*$PARENTPROXY_ENTRY:" $CONFIG_FILE || \
    echo "$PARENTPROXY_ENTRY: $PARENTPROXY" >> $CONFIG_FILE 

PARENTPROXYPORT=8080
db_get ntlmaps/parent_proxy_port
PARENTPROXYPORT="$RET"
# insert the entry, if it is missing (which it ought not to be)
grep -Eq "^[[:blank:]]*$PARENTPROXYPORT_ENTRY:" $CONFIG_FILE || \
    echo "$PARENTPROXYPORT_ENTRY: $PARENTPROXYPORT" >> $CONFIG_FILE 

NTDOMAIN=your_domain
db_get ntlmaps/nt_domain
NTDOMAIN="$RET"
# insert the entry, if it is missing (which it ought not to be)
grep -Eq "^[[:blank:]]*$NTDOMAIN_ENTRY:" $CONFIG_FILE || \
    echo "$NTDOMAIN_ENTRY: $NTDOMAIN" >> $CONFIG_FILE 

NTUSER=username_to_use
db_get ntlmaps/username
NTUSER="$RET"
# insert the entry, if it is missing (which it ought not to be)
grep -Eq "^[[:blank:]]*$NTUSER_ENTRY:" $CONFIG_FILE || \
    echo "$NTUSER_ENTRY: $NTUSER" >> $CONFIG_FILE 

# copy config file here in order to preserve permissions when actually
# building the tmp file in the sed step
cp -a -f $CONFIG_FILE $CONFIG_FILE.tmp

# update to the new values
sed -e "
    s/^[[:blank:]]*$LISTENPORT_ENTRY:.*/$LISTENPORT_ENTRY: $LISTENPORT/
    s|^[[:blank:]]*$PARENTPROXY_ENTRY:.*|$PARENTPROXY_ENTRY: $PARENTPROXY|
    s/^[[:blank:]]*$PARENTPROXYPORT_ENTRY:.*/$PARENTPROXYPORT_ENTRY: $PARENTPROXYPORT/
    s/^[[:blank:]]*$NTDOMAIN_ENTRY:.*/$NTDOMAIN_ENTRY: $NTDOMAIN/
    s/^[[:blank:]]*$NTUSER_ENTRY:.*/$NTUSER_ENTRY: $NTUSER/
    " < $CONFIG_FILE > $CONFIG_FILE.tmp

mv -f $CONFIG_FILE.tmp $CONFIG_FILE


# to help improve security, treat the password separately.
# The administrator may have chosen not to set it using debconf,
# by leaving it blank.

NTPASSWD=your_nt_password
db_get ntlmaps/password
NTPASSWD="$RET"
# insert the entry, if it is missing (which it ought not to be)
grep -Eq "^[[:blank:]]*$NTPASSWD_ENTRY:" $CONFIG_FILE || \
    echo "$NTPASSWD_ENTRY: $NTPASSWD" >> $CONFIG_FILE 

# only process the password if it is not empty
if [ "$NTPASSWD" ]; then
    # remove the password from the deconf database
    db_set ntlmaps/password "password written to config file"

    # copy config file here in order to preserve permissions when actually
    # building the tmp file in the sed step
    cp -a -f $CONFIG_FILE $CONFIG_FILE.tmp
    
    # escape sed special characters
    #echo $NTPASSWD | sed -n 's|[\|\$\&\.\*\%\^\+\?]|\\&|g'
    NTPASSWD=$(echo $NTPASSWD | sed 's|[\[\(\)\|\$\&\.\*\%\^\+\?\/]|\\&|g')
    sed -e "s/^[[:blank:]]*$NTPASSWD_ENTRY:.*/$NTPASSWD_ENTRY: $NTPASSWD/" \
	< $CONFIG_FILE > $CONFIG_FILE.tmp

    mv -f $CONFIG_FILE.tmp $CONFIG_FILE
fi

# extra safety check: ensure passwords in config file cannot be read by anyone
chmod og-r $CONFIG_FILE


# must indicate we are done with debconf, or the script will hang when the
# server is started below (DEBHELPER section, via dh_installinit).
db_stop


#DEBHELPER#

exit 0