Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
Let setting admin password with script when YaCy server is not running
luccioman3061b58c8c36
diff --git a/bin/passwd.sh b/bin/passwd.shindex 39640bc05..eb8408b33 100755--- a/bin/passwd.sh+++ b/bin/passwd.sh@@ -5,12 +5,18 @@ cd "`dirname $0`"echo "Setting new YaCy administrator password..."-# take the administrator user name from the config file-YACY_ADMIN_USER_NAME=$(grep ^adminAccountUserName= "$YACY_DATA_PATH/SETTINGS/yacy.conf" | cut -d= -f2 | tr -d '\r\n')+YACY_CONF_FILE="$YACY_DATA_PATH/SETTINGS/yacy.conf"-if [ -z "$YACY_ADMIN_USER_NAME" ]; then- # administrator user name should not be empty : by the way, in that case use the same default value as in YaCy application- YACY_ADMIN_USER_NAME="admin"+# take the administrator user name and realm from the config file+YACY_ADMIN_USER_NAME=$(grep ^adminAccountUserName= "$YACY_CONF_FILE" | cut -d= -f2 | tr -d '\r\n')+YACY_ADMIN_REALM=$(grep "^adminRealm=" "$YACY_CONF_FILE" | cut -d= -f2 | tr -d '\r\n')++# admin user name and realm should not be empty : by the way, in that case use the same default values as in YaCy application+if [ -z "$YACY_ADMIN_USER_NAME" ]; then+ YACY_ADMIN_USER_NAME="admin"+fi+if [ -z "$YACY_ADMIN_REALM" ]; then+ YACY_ADMIN_REALM="YaCy"fiif [ -z "$1" ]; then@@ -28,7 +34,25 @@ if [ ${#YACY_ADMIN_PASSWORD} -le 2 ]; thenexit 1fi-(./protectedPostApiCall.sh "ConfigAccounts_p.html" "setAdmin=&adminuser=$YACY_ADMIN_USER_NAME&adminpw1=$YACY_ADMIN_PASSWORD&adminpw2=$YACY_ADMIN_PASSWORD&access=" && \-echo "Password successfully changed for User Name '$YACY_ADMIN_USER_NAME'.") || \-(echo "Password setting failed." && \-exit 1)\ No newline at end of file+if [ -f "$YACY_DATA_PATH/yacy.running" ]; then+ echo "YaCy server appears to be running. Calling the ConfigAccounts_p API..."+ # When the server is running we can not directly modify the yacy.conf file so we use the ConfigAccounts_p API.+ # Otherwise the new password provided here could be overwritten by the server when it saves its in-memory configuration to the yacy.conf file+ (./protectedPostApiCall.sh "ConfigAccounts_p.html" "setAdmin=&adminuser=$YACY_ADMIN_USER_NAME&adminpw1=$YACY_ADMIN_PASSWORD&adminpw2=$YACY_ADMIN_PASSWORD&access=" && \+ echo "Password successfully changed for User Name '$YACY_ADMIN_USER_NAME'.") || \+ (echo "Password setting failed." && exit 1)+else+ echo "YaCy server appears to be shutdown. Modifying the configuration file at $YACY_CONF_FILE..."+ B64MD5=$(java -cp "$YACY_APP_PATH/lib/yacycore.jar" net.yacy.cora.order.Digest -strfhex "$YACY_ADMIN_USER_NAME:$YACY_ADMIN_REALM:$YACY_ADMIN_PASSWORD" | head -n 1)+ if [ -z "$B64MD5" ]; then+ echo "Password setting failed."+ exit 1+ fi+ echo "B64MD5 $B64MD5"+ PASSWORD_HASH="MD5:$B64MD5"++ (sed "/adminAccountBase64MD5=/c\adminAccountBase64MD5=$PASSWORD_HASH" "$YACY_CONF_FILE" > "$YACY_CONF_FILE".tmp && \+ mv "$YACY_CONF_FILE".tmp "$YACY_CONF_FILE" && \+ echo "Password successfully changed for User Name '$YACY_ADMIN_USER_NAME'.") || \+ (echo "Password setting failed." && exit 1)+fi\ No newline at end of file