-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
193 lines (160 loc) · 6.63 KB
/
Copy pathsetup.sh
File metadata and controls
193 lines (160 loc) · 6.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
#!/bin/bash
#####################################################################
# Script to clone a list of GitHub repositories into a target directory
#
# Usage:
# 1. Modify the 'repos' array with the desired GitHub repositories
# 2. Run the script: ./setup.sh
# 3. Enter the target directory path when prompted
#
# The script will create the target directory if it doesn't exist,
# and clone each repository from the list into the target directory.
#
# Note: This script assumes you have Git installed and configured.
#####################################################################
# Regular Colors
GREEN="\033[1;32m" # Green
YELLOW="\033[1;33m" # Yellow
BLUE="\033[1;34m" # Blue
RED="\033[1;31m" # Red
NC="\033[0m" # No Color
# List of GitHub repositories
REPOSITORIES=(
"git@github.com:Magiscribe/Magiscribe-API.git"
"git@github.com:Magiscribe/Magiscribe-Client.git"
# Infrastructure repository is optional, comment if unneeded
"git@github.com:Magiscribe/Magiscribe-Infrastructure.git"
)
##################################################################### PRE-REQUISITES #####################################################################
echo -e "${BLUE}Checking prerequisites...${NC}"
# Check if AWS CLI is installed
if ! command -v aws &> /dev/null; then
echo -e "${RED}AWS CLI is not installed. Please install it before proceeding.${NC}"
exit 1
fi
# Check if Node.js is and Corepack are installed
if ! command -v node &> /dev/null; then
echo -e "${RED}Node.js is not installed. Please install it before proceeding.${NC}"
exit 1
fi
if ! command -v corepack &> /dev/null; then
echo -e "${YELLOW}Corepack is not installed. Installing it now...${NC}"
npm install -g corepack
echo -e "${GREEN}Corepack installed successfully${NC}"
fi
# Enable PNPM
if ! command -v pnpm &> /dev/null; then
echo -e "${YELLOW}PNPM is not installed. Installing it now...${NC}"
corepack enable pnpm
corepack use pnpm@latest
echo -e "${GREEN}PNPM installed successfully${NC}"
fi
echo -e "${GREEN}All prerequisites are met${NC}"
##################################################################### CLONE REPOSITORIES #####################################################################
# Prompt the user for the target directory
echo -e "${YELLOW}Enter the target directory path (default: ./Magiscribe):${NC}"
read target_dir
# Use the default target directory if none is provided
target_dir=${target_dir:-"./Magiscribe"}
# Create the target directory if it doesn't exist
mkdir -p "$target_dir"
cd "$target_dir"
# Clone each repository into the target directory
for repo in "${REPOSITORIES[@]}"; do
echo -e "${BLUE}Cloning $repo...${NC}"
if git clone $repo; then
echo -e "${GREEN}Successfully cloned $repo${NC}"
echo -e "${BLUE}Setting up $repo...${NC}"
directory=$(echo $repo | cut -d'/' -f2 | cut -d'.' -f1)
cd $directory
npm run setup
cd ..
echo -e "${GREEN}Successfully set up $repo${NC}"
else
echo -e "${RED}Failed to clone $repo${NC}"
echo -e "${RED}Exiting...${NC}"
exit 1
fi
done
echo -e "${GREEN}All repositories cloned successfully!${NC}"
##################################################################### AWS CONFIG #####################################################################
# Create a ~/.aws/config file, if it doesn't exist
if [ ! -f ~/.aws/config ]; then
mkdir -p ~/.aws
touch ~/.aws/config
fi
# Check if the config file already contains the desired content
if ! grep -q "sso_start_url = https://magiscribe.awsapps.com/start/#" ~/.aws/config; then
echo -e "${YELLOW}Do you want to add AWS credentials to the ~/.aws/config file? (y/n)${NC}"
read add_aws
if [ "$add_aws" == "y" ]; then
# Prompt for AWS account IDs
echo -e "${YELLOW}Enter the AWS Production Account ID:${NC}"
read prod_account_id
if [ -z "$prod_account_id" ]; then
echo -e "${RED}Production Account ID is required. Exiting AWS configuration.${NC}"
add_aws="n"
else
echo -e "${YELLOW}Enter the AWS Development Account ID:${NC}"
read dev_account_id
if [ -z "$dev_account_id" ]; then
echo -e "${RED}Development Account ID is required. Exiting AWS configuration.${NC}"
add_aws="n"
else
# Prompt for SSO role name with default
echo -e "${YELLOW}Enter the AWS SSO Role Name (default: PowerUserAccess):${NC}"
read sso_role
# Set default if empty
sso_role=${sso_role:-"PowerUserAccess"}
# Prompt for AWS region with default
echo -e "${YELLOW}Enter the AWS Region (default: us-east-1):${NC}"
read aws_region
# Set default if empty
aws_region=${aws_region:-"us-east-1"}
echo -e "${GREEN}Adding AWS credentials to the ~/.aws/config file...${NC}"
cat <<EOF >> ~/.aws/config
[sso-session magiscribe]
sso_start_url = https://magiscribe.awsapps.com/start/#
sso_region = $aws_region
sso_registration_scopes = sso:account:access
[profile magiscribe-prod]
sso_session = magiscribe
sso_account_id = $prod_account_id
sso_role_name = $sso_role
region = $aws_region
output = json
[profile magiscribe-dev]
sso_session = magiscribe
sso_account_id = $dev_account_id
sso_role_name = $sso_role
region = $aws_region
output = json
EOF
echo -e "${GREEN}AWS credentials added to the ~/.aws/config file${NC}"
fi
fi
fi
else
echo -e "${GREEN}AWS credentials already partially configured in the ~/.aws/config file${NC}"
echo -e "${YELLOW}Please ensure the correct AWS credentials are configured${NC}"
fi
##################################################################### VS CODE WORKSPACE #####################################################################
# Creates a new VS Code workspace file
echo -e "${BLUE}Creating VS Code workspace file...${NC}"
echo "{
\"folders\": [ " > Magiscribe.code-workspace
for repo in "${REPOSITORIES[@]}"; do
repo_name=$(echo $repo | cut -d'/' -f2 | cut -d'.' -f1)
echo " {
\"path\": \"./$repo_name\"
}," >> Magiscribe.code-workspace
done
echo " ]
}" >> Magiscribe.code-workspace
echo -e "${GREEN}VS Code workspace file created${NC}"
# Open the target directory in VS Code
echo -e "${YELLOW}Do you want to open the target directory in VS Code? (y/n)${NC}"
read open_vscode
if [ "$open_vscode" == "y" ]; then
code -n "Magiscribe.code-workspace"
fi