Skip to content

Commit 0f775db

Browse files
Create setup.sh
Signed-off-by: Fabiana Campanari <fabicampanari@gmail.com>
1 parent 7676038 commit 0f775db

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

setup.sh

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
# Flag definition
3+
4+
org_id=""
5+
location="eastus"
6+
include_groups=false
7+
resource_group_name=""
8+
9+
print_usage() {
10+
echo "This setup script will install the Open Edu Analytics base architecture and the example Contoso package with test data sets."
11+
echo ""
12+
echo "Invoke this script like this: "
13+
echo " setup.sh -o <org_id>"
14+
echo "where org_id is a suffix representing your organization (eg, CISD3). This value must be 12 characters or less (consider using an abbreviation) and must contain only letters and/or numbers."
15+
echo ""
16+
echo "By default, the Azure resources will be provisioned in the East US location."
17+
echo "If you want to have the resources provisioned in an alternate location, invoke the script like this: "
18+
echo " setup.sh -o <org_id> -l <location>"
19+
echo "where org_id is a suffix for your organization (eg, CISD3), and location is the abbreviation of the desired location (eg, eastus, westus, northeurope)."
20+
echo ""
21+
echo "By default, the Azure resource group will be provisioned as rg-oea-<org_id>."
22+
echo "If you want to have the resource group provisioned with an alternate name, invoke the script like this: "
23+
echo " setup.sh -o <org_id> -r <resource_group_name>"
24+
echo "where org_id is a suffix for your organization (eg, CISD3), and resource_group_name is the name of the resource group that follows your internal naming convention."
25+
echo ""
26+
echo "If you have Global Admin rights for the tenant associated with your Azure subscription, and you want to have the script setup security groups to facilitate the management of role based access control, you can invoke the script like this:"
27+
echo "You can opt to create a set of resources (eg, for a test env) without setting up the security groups like this:"
28+
echo " setup.sh -o <org_id> -i"
29+
echo "where org_id is a suffix for your organization (eg, CISD3), and -i specifies that security groups should be created."
30+
exit 1
31+
}
32+
33+
datetime=$(date "+%Y%m%d_%H%M%S")
34+
logfile="oea_setup_${datetime}.log"
35+
exec 3>&1 1>>${logfile} 2>&1
36+
37+
# The assumption here is that this script is in the base path of the OpenEduAnalytics project.
38+
oea_path=$(dirname $(realpath $0))
39+
40+
# Set Flags
41+
while getopts ":o:l:ir:" flag; do
42+
case "${flag}" in
43+
o)
44+
echo "argument -o called with value ${OPTARG}"
45+
org_id=${OPTARG}
46+
;;
47+
l)
48+
echo "argument -l called with value ${OPTARG}"
49+
location=${OPTARG}
50+
;;
51+
i)
52+
echo "flag -i is enabled"
53+
include_groups=true
54+
;;
55+
r)
56+
echo "argument -r called with value ${OPTARG}"
57+
resource_group_name=${OPTARG}
58+
;;
59+
:)
60+
echo "Error: argument -${OPTARG} requires a value"
61+
echo ""
62+
print_usage
63+
;;
64+
*)
65+
echo "Error: argument -${OPTARG} is not valid"
66+
echo ""
67+
print_usage
68+
;;
69+
esac
70+
done
71+
72+
# If org_id was not passed as an input argument, then display usage instructions and exit script
73+
if test -z "$org_id"
74+
then
75+
print_usage
76+
fi
77+
78+
source $oea_path/framework/infrastructure/bash/set_names.sh $org_id $resource_group_name
79+
80+
subscription_id=$(az account show --query id -o tsv)
81+
82+
# Verify that the specified org_id is not too long and doesn't have invalid characters.
83+
# The length is constrained by the fact that the synapse workspace name must be <= 24 characters, and our naming convention requires that it start with "syn-oea-".
84+
if [[ ${#org_id} -gt 16 || ! $org_id =~ ^[a-zA-Z0-9]+$ ]]; then
85+
echo "Invalid suffix: $org_id"
86+
echo "Invalid suffix: $org_id" 1>&3
87+
echo "The chosen suffix must be less than 12 characters, and must contain only letters and numbers."
88+
echo "The chosen suffix must be less than 12 characters, and must contain only letters and numbers." 1>&3
89+
exit 1
90+
fi
91+
92+
# Verify that the user has the Owner role assignment
93+
roles=$(az role assignment list --subscription $subscription_id --query [].roleDefinitionName -o tsv)
94+
if [[ ! " ${roles[@]} " =~ "Owner" ]]; then
95+
echo "You do not have the role assignment of Owner on this subscription."
96+
echo "You do not have the role assignment of Owner on this subscription." 1>&3
97+
echo "For more info, click here -> https://github.com/microsoft/OpenEduAnalytics/wiki/Setup-Tips#error-must-have-role-assignment-of-owner-on-subscription"
98+
echo "For more info, click here -> https://github.com/microsoft/OpenEduAnalytics/wiki/Setup-Tips#error-must-have-role-assignment-of-owner-on-subscription" 1>&3
99+
exit 1
100+
fi
101+
102+
echo "--> Setting up OEA (logging detailed setup messages to $logfile)"
103+
echo "--> Setting up OEA (logging detailed setup messages to $logfile)" 1>&3
104+
105+
# setup the base architecture
106+
echo "--> Setting up the OEA base architecture."
107+
echo "--> Setting up the OEA base architecture." 1>&3
108+
$oea_path/framework/infrastructure/bash/setup_base_architecture.sh $org_id $location $include_groups $subscription_id $oea_path $logfile
109+
# exit out if setup_base_architecture failed
110+
if [[ $? != 0 ]]; then
111+
exit 1
112+
fi
113+
114+
# install the OEA framework assets
115+
$oea_path/framework/setup.sh $OEA_SYNAPSE $OEA_STORAGE_ACCOUNT $OEA_KEYVAULT
116+
117+
workspace_url=$(az synapse workspace show --name $OEA_SYNAPSE --resource-group $OEA_RESOURCE_GROUP | jq -r '.connectivityEndpoints | .web')
118+
echo "--> OEA setup is complete. Click on this url to work with your new Synapse workspace (via Synapse Studio): $workspace_url"
119+
echo "--> OEA setup is complete. Click on this url to work with your new Synapse workspace (via Synapse Studio): $workspace_url" 1>&3
120+
121+
echo $' Once in Synapse Studio, click on Develop, select the notebook called 1_read_me, and follow the directions shown there.'
122+
echo $' Once in Synapse Studio, click on Develop, select the notebook called 1_read_me, and follow the directions shown there.' 1>&3

0 commit comments

Comments
 (0)