generated from trywilco/Anythink-Market-Public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
WilcoApp
committed
Sep 22, 2024
1 parent
eadcffc
commit d4d748b
Showing
2 changed files
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#!/bin/bash | ||
|
||
echo "Wilco: Hi, Welcome to Wilco MongoDB Atlas Cluster Setup!" | ||
echo "We'll guide you through the process of setting up a MongoDB Atlas cluster." | ||
|
||
# Step 1: Register or authenticate the user | ||
echo "Wilco: Please register or authenticate using MongoDB Atlas." | ||
echo "Wilco: If you already have an account, please click login and paste your CLI Key." | ||
atlas auth register --noBrowser | ||
if [ $? -ne 0 ]; then | ||
echo "Wilco: Something went wrong with atlas command 'auth register', please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
# Step 2: Create a new organization and capture the Organization ID | ||
echo "Wilco: Creating a new organization named 'WilcoOrg'." | ||
org_output=$(atlas organizations create WilcoOrg) | ||
if [ $? -ne 0 ]; then | ||
echo "Wilco: Something went wrong with atlas command 'organizations create'. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
# Extract the Organization ID from the output using awk | ||
org_id=$(echo "$org_output" | awk -F"'" '/Organization / {print $2}') | ||
|
||
if [ -z "$org_id" ]; then | ||
echo "Wilco: Failed to create organization or capture the Organization ID. Exiting. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
echo "Wilco: A new Organization created with ID $org_id" | ||
|
||
# Step 3: Create a new project and capture the Project ID | ||
echo "Wilco: Creating a new project named 'WilcoMongo'." | ||
project_output=$(atlas projects create WilcoMongo --orgId $org_id) | ||
if [ $? -ne 0 ]; then | ||
echo "Wilco: Something went wrong with atlas command 'projects create'. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
# Extract the Project ID from the output using awk | ||
project_id=$(echo "$project_output" | awk -F"'" '/Project / {print $2}') | ||
|
||
if [ -z "$project_id" ]; then | ||
echo "Wilco: Failed to create project or capture the Project ID. Exiting. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
echo "Wilco: Project created with ID $project_id" | ||
|
||
# Step 4: Add access list entry | ||
echo "Wilco: Adding access list entry for IP address 0.0.0.0 so Wilco can connect to it!" | ||
atlas accessList create 0.0.0.0 --type ipAddress --projectId $project_id | ||
if [ $? -ne 0 ]; then | ||
echo "Wilco: Something went wrong with atlas command 'accessList create'. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
# Step 5: Create a cluster in the newly created project | ||
echo "Wilco: Creating a MongoDB cluster in the project 'WilcoMongo' for your Wilco application." | ||
atlas cluster create WilcoMongo --projectId $project_id --provider AWS --region US_EAST_1 --tier M0 --watch | ||
if [ $? -ne 0 ]; then | ||
echo "Wilco: Something went wrong with atlas command 'cluster create'. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
# Step 6: Create a database user | ||
echo "Wilco: Creating a database user 'WilcoDbUser' for your Wilco application." | ||
atlas dbusers create atlasAdmin --username WilcoDbUser --password Wilco12345678 --projectId $project_id | ||
if [ $? -ne 0 ]; then | ||
echo "Wilco: Something went wrong with atlas command 'dbusers create'. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
# Initialize variables to capture specific outputs | ||
matched_string="" | ||
full_connection_string="" | ||
cleaned_connection_string="" | ||
|
||
# Output the captured values with labels inside an ASCII square | ||
echo "┌─────────────────── Wilco MongoDB Details ────────────────────────────────────────────────────┐" | ||
echo "| Your Wilco MongoDB Atlas Cluster is being created. |" | ||
echo "| This may take a few minutes. Once done you'll see your details below |" | ||
echo "| Wilco DB User: WilcoDbUser |" | ||
echo "| Wilco DB Password: Wilco12345678 |" | ||
echo "| Your cluster name: WilcoMongo" | ||
sleep 5 | ||
full_connection_string=$(atlas clusters connectionStrings describe WilcoMongo --projectId $project_id | grep -A 1 "mongodb+srv" | tail -n 1) | ||
if [ $? -ne 0 ]; then | ||
echo "Wilco: Something went wrong with atlas command 'clusters connectionStrings describe'. Please contact Wilco support." | ||
exit 1 | ||
fi | ||
|
||
cleaned_connection_string=${full_connection_string#mongodb+srv://} | ||
|
||
connection_string="mongodb+srv://WilcoDbUser:Wilco12345678@$cleaned_connection_string" | ||
|
||
echo "| Your connection string: $connection_string |" | ||
echo "└─────────────────── Wilco MongoDB Details ────────────────────────────────────────────────────┘" |