-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinit-system.sh
197 lines (153 loc) · 4.11 KB
/
init-system.sh
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
#!/bin/bash
#
# Copyright (c) 2007-2011, Adrian Thurston <[email protected]>
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
DSNPD_CONF=@sysconfdir@/dsnpd.conf
DATADIR=@datadir@
LOCALSTATEDIR=@localstatedir@
SYSCONFDIR=@sysconfdir@
PREFIX=@prefix@
DSNPD_USER=@DSNPD_USER@
function usage()
{
echo usage: ./new-site.sh instructions-file
exit 1;
}
# Write config file fragments to this file. It can then be copy-pasted to the
# right places. It will contain instructions.
OUTPUT=$1;
if [ -z "$OUTPUT" ]; then
usage;
exit 1;
fi
# Clear the output file.
rm -f $OUTPUT;
touch $OUTPUT;
chmod 600 $OUTPUT;
# Make passwords.
CFG_DB_PASS1=`head -c 8 < /dev/urandom | xxd -p`
CFG_DB_PASS2=`head -c 8 < /dev/urandom | xxd -p`
CFG_DB_PASS3=`head -c 8 < /dev/urandom | xxd -p`
# Port for the server.
CFG_PORT=7085
cat << EOF > $OUTPUT
SYSTEM INSTALL INSTRUCTIONS
===========================
EOF
cat << EOF >> $OUTPUT
STEP 1
======
Set permissions on various files and directories. This must be run as root.
-------- BEGIN SCRIPT -------
install -d @prefix@/var/log/dsnpd
install -d @prefix@/etc/dsnpd-ssl
chown root:root @sysconfdir@/dsnpd.conf
chown root:root @sysconfdir@/dsnpd-ssl
chmod 600 @sysconfdir@/dsnpd.conf
chmod 700 @sysconfdir@/dsnpd-ssl
chown root:root @prefix@/var/log/dsnpd
chmod 700 @prefix@/var/log/dsnpd
-------- END SCRIPT -------
EOF
cat << EOF >> $OUTPUT
STEP 2
======
Install a logrotate fragment.
@prefix@/var/log/dsnp/dsnpd.log
@prefix@/var/log/dsnp/dsnpk.log
@prefix@/var/log/dsnp/dsnpn.log
{
weekly
missingok
rotate 26
compress
delaycompress
notifempty
create 600 root root
sharedscripts
postrotate
if test -f @PID_DIR@/dsnpd.pid; then
kill -HUP "\`cat @PID_DIR@/dsnpd.pid\`"
fi
endscript
}
EOF
cat << EOF >> $OUTPUT
STEP 3
======
Install the init script from the share directory. The manner of installing this
will be system dependent.
EOF
#
# dsnpd.conf file.
#
cat << EOF >> $OUTPUT
STEP 4
======
Complete the following fragment by setting the notification script and add it
to $DSNPD_CONF
-------- BEGIN FRAGMENT --------
#
# Daemon
#
CFG_PORT = $CFG_PORT
CFG_DB_HOST = localhost
CFG_DB_USER = dsnpd
CFG_DB_DATABASE = dsnpd
CFG_DB_PASS = $CFG_DB_PASS1
#
# Key Agent.
#
CFG_KEYS_HOST = localhost
CFG_KEYS_USER = dsnpk
CFG_KEYS_DATABASE = dsnpk
CFG_KEYS_PASS = $CFG_DB_PASS2
#
# Notification Agent.
#
CFG_NOTIF_HOST = localhost
CFG_NOTIF_KEYS_USER = dsnpn
CFG_NOTIF_DATABASE = dsnpn
CFG_NOTIF_PASS = $CFG_DB_PASS3
-------- END FRAGMENT --------
EOF
#
# Database initialization
#
cat << EOF >> $OUTPUT
STEP 5
======
Initialize the database. This step will require the mysql root password. You
may wish to consider copying this fragment to a file and executing it to avoid
putting the database user and pass on your history.
-------- BEGIN SCRIPT -------
mysql -u root -p -B -N -e "
CREATE USER 'dsnpd'@'localhost' IDENTIFIED BY '$CFG_DB_PASS1';
CREATE DATABASE dsnpd;
GRANT ALL ON dsnpd.* TO 'dsnpd'@'localhost';
CREATE USER 'dsnpk'@'localhost' IDENTIFIED BY '$CFG_DB_PASS2';
CREATE DATABASE dsnpk;
GRANT ALL ON dsnpk.* TO 'dsnpk'@'localhost';
CREATE USER 'dsnpn'@'localhost' IDENTIFIED BY '$CFG_DB_PASS3';
CREATE DATABASE dsnpn;
GRANT ALL ON dsnpn.* TO 'dsnpn'@'localhost';
USE dsnpd;
SOURCE ${DATADIR}/dsnpd/dsnpd.sql;
USE dsnpk;
SOURCE ${DATADIR}/dsnpd/dsnpk.sql
USE dsnpn;
SOURCE ${DATADIR}/dsnpd/dsnpn.sql
"
-------- END SCRIPT -------
EOF