Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update superadmin script #42

Merged
merged 1 commit into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions rair-infra/commands/update-local-admin/mongo_commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
quit()
19 changes: 2 additions & 17 deletions rair-infra/commands/update-local-admin/update_local_admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
set -e

PUBLIC_ADDRESS=null
ADMIN_NFT=null


printf '\n|%s %s %s|\n' \
Expand All @@ -28,28 +27,17 @@ 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' \
\
"Is this information correct? [y/N]?"

read INPUT
case $INPUT in
y|Y ) printf "\n[!] Starting adminNFT update...\n";;
y|Y ) printf "\n[!] Starting SuperAdmin update...\n";;
* ) exit;;
esac

Expand All @@ -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#
Expand All @@ -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"


#########
Expand All @@ -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"