forked from yacy/yacy_search_server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reconfigureYACY.sh
executable file
·304 lines (274 loc) · 7.26 KB
/
reconfigureYACY.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
#!/usr/bin/env bash
# THIS SCRIPT CAN BE USED TO EDIT SOME BASIC SETTINGS OF YACY
#
# Copyright 2009 - 2014 by Marc Nause; [email protected]
#
# This is a part of YaCy, a peer-to-peer based web search engine.
# http://www.yacy.net
#
# LICENSE
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# DEFINING SOME CONSTANTS
#
DATADIR='DATA'
SETTINGSDIR='DATA/SETTINGS'
CONFIGFILE='DATA/SETTINGS/yacy.conf'
CONFIGTEMPLATE='defaults/yacy.init'
LOCKFILE='DATA/yacy.running'
JAVA="`which java`"
# THIS REGEX WILL ALSO RETURN EVERYTHING AFTER THE NUMBER WHICH IS OK HERE BECAUSE
# WE EITHER HAVE NUMBERS (port) OR A NUMBER PLUS A UNIT (memory settings)
NUMBERFILTER='s/^[^0-9]*\([0-9]*.*\)/\1/'
NOCHANGESTEXT='No changes have been performed.'
#
# INITIALIZING VARIABLES
#
STATUS='No actions have been performed yet.'
#
# DEFINING SOME FUNCTIONS WHICH WILL BE USED LATER
#
# CHANGES THE ADMIN SETTINGS
change_admin_settings()
{
change_admin_localhost
}
change_admin_localhost()
{
if read_parameter 'adminAccountForLocalhost'
then
if [ $REPLY == 'true' ]
then
CURRENTLOCALACCESS='allowed'
else
CURRENTLOCALACCESS='not allowed'
fi
else
CURRENTLOCALACCESS = 'unknown'
fi
echo
echo -n "Allow unrestricted admin access for all local users (y/n, currently $CURRENTLOCALACCESS)? "
read INPUT
case $INPUT in
y)
replace_parameter 'adminAccountForLocalhost' 'true'
STATUS = 'Admin access granted for all local users.'
;;
n)
replace_parameter 'adminAccountForLocalhost' 'false'
change_admin_password
;;
'')
STATUS="$NOCHANGESTEXT"
;;
*)
echo
echo 'Please enter y or n or just hit enter to abort.'
change_admin_localhost
;;
esac
}
# CHANGES THE ADMIN PASSWORD
change_admin_password()
{
echo -n 'Enter username (leave empty for standard username "admin"): '
read USERNAME
if [ "$USERNAME" == '' ]
then
USERNAME='admin';
fi
echo -n 'Enter new password (will not be displayed): '
read -s INPUT1
echo
echo -n 'Enter new password again (will not be displayed): '
read -s INPUT2
echo
if [ "$INPUT1" == "" ]
then
echo
echo 'Empty password is not allowed, please try again.'
change_admin_password
elif [ $INPUT1 != $INPUT2 ]
then
echo
echo 'Entries did not match, please try again.'
change_admin_password
else
replace_parameter 'adminAccount' "$USERNAME:$INPUT1"
fi
STATUS='Admin password has been changed.'
}
# CHANGES THE MEMORY SETTINGS
change_mem_settings()
{
if read_parameter 'javastart_Xmx' $NUMBERFILTER
then
CURRENTMEM="$REPLY"
else
CURRENTMEM='unknown'
fi
echo
echo -n "How much memory (in MB) do you want YaCy to be able to use (currently $CURRENTMEM)? "
read INPUT
case $INPUT in
*[^0-9]*)
echo
echo 'Please enter a number or just hit enter to abort.'
change_mem_settings
;;
[0-9]*)
replace_parameter 'javastart_Xmx' "Xmx$INPUT"'m'
replace_parameter 'javastart_Xms' "Xms$INPUT"'m'
STATUS="Memory settings have been changed. YaCy will be able to use $INPUT MB of RAM now."
;;
'')
STATUS="$NOCHANGESTEXT"
;;
esac
}
# CHANGES THE PORT SETTINGS. PROPERTY NAME IN FIRST PARAMETER, HUMAN READABLE NAME IN SECOND PARAMETER.
change_port_settings()
{
if read_parameter $1
then
CURRENTPORT="$REPLY"
else
CURRENTPORT='unknown'
fi
echo
echo -n "Which port do you want YaCy to use for $2 (currently $CURRENTPORT)? "
read INPUT
case $INPUT in
[0-9]*)
if [ "$INPUT" -ge 1024 ] && [ "$INPUT" -le 65535 ];
then
replace_parameter $1 $INPUT
STATUS="Port settings for $2 have been changed. YaCy listens to port $INPUT now."
else
echo
echo 'Please use choose a number between 1024 and 65535.'
change_port_settings $1 $2
fi
;;
'')
STATUS="$NOCHANGESTEXT"
;;
*)
echo
echo 'Please enter a number or just hit enter to abort.'
change_port_settings $1 $2
;;
esac
}
# CHECKS IF CONFIG FILE EXISTS, EXISTS IF IT DOESN'T
check_conf()
{
if [ ! -e "$CONFIGFILE" ]
then
echo 'ERROR:'
echo 'Config file does not exist. Please start YaCy at least once to create config file.'
exit 1
fi
}
# CHECKS IF A STANDARD JVM HAS BEEN SET, EXITS IF NOT
check_java()
{
if [ "$JAVA" == '' ]
then
echo 'ERROR:'
echo 'Java has not been detected. Please add a JRE to your classpath.'
exit 1
fi
}
# EXITS WITH WARNING IF LOCKFILE EXISTS
check_lock()
{
if [ -f "$LOCKFILE" ]
then
echo "WARNING:"
echo "$LOCKFILE exists which indicates that YaCy is still running."
echo "Please stop YaCy before running this script."
echo "If you are sure that YaCy is not running anymore,"
echo "delete $LOCKFILE and start this script again."
exit 1
fi
}
# EXITS SRIPT AND PRINTS GOODBYE MESSAGE
goodbye()
{
echo
echo "Goodbye!"
echo
exit 0
}
# PRINTS THE MENU
print_menu()
{
clear
echo "*** YaCy commandline configuration tool ***"
echo
echo "Make your choice:"
echo "[1] change memory settings"
echo "[2] change admin password"
echo "[3] change HTTP port"
echo "[4] change HTTPS port"
echo "[0] quit"
echo
echo "Status: $STATUS"
}
# READS THE VALUE OF A PARAMETER (FIRST ARGUMENT) FROM CONFIG FILE. PARAMETER CAN BE FILTERED
# IF A SECOND PARAMETER, WHICH IS A VALID sed OPERATION LIKE "s/xxx/yyy/", EXISTS.
read_parameter()
{
REPLY="`cat "$CONFIGFILE" | grep "^$1=" | sed "s/\(^$1 *= *\)\(.*\)$/\2/"`"
if [ "$2" != '' ]
then
REPLY="`echo "$REPLY" | sed $2`"
fi
}
# REPLACES THE VALUE OF A PARAMETER (FIRST ARGUMENT) WITH A NEW ONE (SECOND ARGUMENT)
replace_parameter()
{
$JAVA -classpath lib/yacycore.jar net.yacy.yacy -config "$1=$2" 2>/dev/null
}
#
# MAIN PROGRAM
#
check_lock
check_conf
print_menu
while read -s -n1 INPUT
do
case $INPUT in
0)
goodbye
;;
1)
change_mem_settings
;;
2)
change_admin_settings
;;
3)
change_port_settings 'port' 'HTTP'
;;
4)
change_port_settings 'port.ssl' 'HTTPS'
;;
esac
print_menu
done
#EOF