From 7d44aed03d36f436d2b74dc2ad80889cf6c04a85 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Sat, 19 Nov 2016 21:40:39 +0000 Subject: [PATCH] Changing etherpad password --- src/freedombone-app-etherpad | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/freedombone-app-etherpad b/src/freedombone-app-etherpad index 87ec08e3..3383deae 100755 --- a/src/freedombone-app-etherpad +++ b/src/freedombone-app-etherpad @@ -54,7 +54,20 @@ etherpad_variables=(ETHERPAD_COMMIT MY_USERNAME) function change_password_etherpad { - ${PROJECT_NAME}-pass -u $1 -a dokuwiki -p "$2" + change_username="$1" + new_user_password="$2" + + read_config_param ETHERPAD_DOMAIN_NAME + + ${PROJECT_NAME}-pass -u $change_username -a etherpad -p "$new_user_password" + if grep "\"${change_username}\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then + user_line=$(cat /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json | grep "\"${change_username}\": {") + if [[ "$user_line" == *"\"is_admin\": true"* ]]; then + sed -i "s|\"${change_username}\": {.*|\"${change_username}\": { \"password\": \"${new_user_password}\", \"is_admin\": true }," /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json + else + sed -i "s|\"${change_username}\": {.*|\"${change_username}\": { \"password\": \"${new_user_password}\", \"is_admin\": false }" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json + fi + fi } function etherpad_create_database { @@ -144,10 +157,7 @@ function create_etherpad_settings { echo ' "disableIPlogging" : true,' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json echo ' "users": {' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - echo " \"${MY_USERNAME}\": {" >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - echo " \"password\": \"${ETHERPAD_ADMIN_PASSWORD}\"," >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - echo ' "is_admin": true' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json - echo ' }' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json + echo " \"${MY_USERNAME}\": { \"password\": \"${ETHERPAD_ADMIN_PASSWORD}\", \"is_admin\": true }" >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json echo ' },' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json echo ' "socketTransportProtocols" : ["xhr-polling", "jsonp-polling", "htmlfile"],' >> /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json @@ -192,10 +202,7 @@ function add_user_etherpad { ${PROJECT_NAME}-pass -u $new_username -a etherpad -p "$new_user_password" read_config_param ETHERPAD_DOMAIN_NAME if ! grep -q "\"${new_username}\": {" /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json; then - sed -i "/\"users\": {/a \"${new_username}\": { - \"password\": \"${new_user_password}\", - \"is_admin\": false - }," /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json + sed -i "/\"users\": {/a \"${new_username}\": { \"password\": \"${new_user_password}\", \"is_admin\": false }," /var/www/${ETHERPAD_DOMAIN_NAME}/htdocs/settings.json fi }