From cca570b885af867f9fa75f9e9e189d82d355ea48 Mon Sep 17 00:00:00 2001 From: Suresh Arora Date: Thu, 23 May 2024 18:04:32 +0000 Subject: [PATCH] update superadmin script --- .../update-local-admin/mongo_commands.js | 16 ++++------------ .../update-local-admin/update_local_admin.sh | 19 ++----------------- 2 files changed, 6 insertions(+), 29 deletions(-) diff --git a/rair-infra/commands/update-local-admin/mongo_commands.js b/rair-infra/commands/update-local-admin/mongo_commands.js index 9391c49f7..d423750da 100644 --- a/rair-infra/commands/update-local-admin/mongo_commands.js +++ b/rair-infra/commands/update-local-admin/mongo_commands.js @@ -8,19 +8,11 @@ db.auth("admin","admin") db = db.getSiblingDB('rair-db') -//Locates the user and sets adminNFT -db.User.updateOne( - { "publicAddress" : PUBLIC_ADDRESS }, - { $set: { "adminNFT" : ADMIN_NFT } } +//Set SuperAdmin +db.ServerSetting.updateMany({}, + { $push: { "superAdmins" : PUBLIC_ADDRESS } } ) -//Finds the user and prints the new value in adminNFT -//This is for verification -user = db.User.findOne({ publicAddress : PUBLIC_ADDRESS}) -admin_NFT = user.adminNFT.toString() -print("\nChanging adminNFT to", admin_NFT) - - print("\nExiting Mongo Shell...") db.logout() -quit() \ No newline at end of file +quit() diff --git a/rair-infra/commands/update-local-admin/update_local_admin.sh b/rair-infra/commands/update-local-admin/update_local_admin.sh index 364627077..778171312 100755 --- a/rair-infra/commands/update-local-admin/update_local_admin.sh +++ b/rair-infra/commands/update-local-admin/update_local_admin.sh @@ -11,7 +11,6 @@ set -e PUBLIC_ADDRESS=null -ADMIN_NFT=null printf '\n|%s %s %s|\n' \ @@ -28,20 +27,9 @@ PUBLIC_ADDRESS=$(echo "$INPUT" | tr '[:upper:]' '[:lower:]') printf "%s\n\n" "Setting Public Address to: $PUBLIC_ADDRESS" -#Get AdminNFT -printf '\n%s\n\n' \ -\ -"Enter developer adminNFT address" - -read INPUT -(( ${#INPUT} >= 42 )) && printf "\nAccepted - " || { printf "\nInvalid address. Exiting...\n\n"; exit; } -ADMIN_NFT=$(echo "$INPUT" | tr '[:upper:]' '[:lower:]') -printf "%s\n\n" "Setting AdminNFT to: $PUBLIC_ADDRESS" - #Verification printf "\n%s" "Public Address = $PUBLIC_ADDRESS" -printf "\n%s\n" "AdminNFT Address = $ADMIN_NFT" printf '\n\n%s\n\n' \ \ @@ -49,7 +37,7 @@ printf '\n\n%s\n\n' \ read INPUT case $INPUT in - y|Y ) printf "\n[!] Starting adminNFT update...\n";; + y|Y ) printf "\n[!] Starting SuperAdmin update...\n";; * ) exit;; esac @@ -58,7 +46,6 @@ esac #when we substitite the values in the file. Especially in the off chance that #the script fails before completion. This can be better handled in the future. docker exec -it mongo sh -c "echo $PUBLIC_ADDRESS | cat > /tmp/PUBLIC_ADDRESS" -docker exec -it mongo sh -c "echo $ADMIN_NFT | cat > /tmp/ADMIN_NFT" ####### #MONGO# @@ -71,11 +58,10 @@ docker cp mongo_commands.js mongo:/tmp/mongo_commands.js #Now we force the variable substitution inside the mongo container docker exec -it mongo sh -c 'sed -i '' 's/VAR_PUBLIC_ADDRESS/'$(cat /tmp/PUBLIC_ADDRESS)'/g' /tmp/mongo_commands.js' -docker exec -it mongo sh -c 'sed -i '' 's/VAR_ADMIN_NFT/'$(cat /tmp/ADMIN_NFT)'/g' /tmp/mongo_commands.js' #And Initialize the mongo shell with our script printf "%s\n\n" "[!] Initializing Mongo Shell..." -docker exec -it mongo sh -c "mongo /tmp/mongo_commands.js" +docker exec -it mongo sh -c "mongosh /tmp/mongo_commands.js" ######### @@ -87,7 +73,6 @@ docker exec -it mongo sh -c "mongo /tmp/mongo_commands.js" printf "\n[!] Cleaning up...\n" docker exec mongo rm -rf /tmp/mongo_commands.js docker exec mongo rm -rf /tmp/PUBLIC_ADDRESS -docker exec mongo rm -rf /tmp/ADMIN_NFT printf "[!] Exiting script\n\n"