summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorluccioman <luccioman@users.noreply.github.com>2018-11-28 21:44:49 +0100
committerluccioman <luccioman@users.noreply.github.com>2018-11-28 21:44:49 +0100
commit3061b58c8c36d94293d102ad1eb40f3afa1a2f3e (patch)
tree86e13e5898d7c3635c962a7d96deb1ab9c3aee8d /bin
parentede5cc0a2b076fcfa624fee90d5a6c1b33466f24 (diff)
Let setting admin password with script when YaCy server is not running
Still using the ConfigAccounts_p API when the server is running.
Diffstat (limited to 'bin')
-rwxr-xr-xbin/passwd.sh42
1 files changed, 33 insertions, 9 deletions
diff --git a/bin/passwd.sh b/bin/passwd.sh
index 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"
fi
if [ -z "$1" ]; then
@@ -28,7 +34,25 @@ if [ ${#YACY_ADMIN_PASSWORD} -le 2 ]; then
exit 1
fi
-(./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