-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_env.sh
executable file
·134 lines (111 loc) · 3.03 KB
/
setup_env.sh
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
#!/usr/bin/env bash
# oci_config_setup.sh
# This script sets up the OCI configuration interactively and creates an oci.env file.
display_choices(){
cat <<EOF
Choose one of the two free shapes
1. VM.Standard.A1.Flex
2. VM.Standard.E2.1.Micro
EOF
}
read -p "Type name of the instance: " INSTANCE_NAME
clear
while true; do
display_choices
read -p "Enter your choice (1 or 2): " SHAPE
case $SHAPE in
1)
SHAPE="VM.Standard.A1.Flex"
break
;;
2)
SHAPE="VM.Standard.E2.1.Micro"
break
;;
*)
clear
echo "Invalid choice. Please try again. (CTRL+C to quit)"
;;
esac
done
clear
while true; do
read -p "Use the script for your second free tier Micro Instance? (y/n): " BOOL_MICRO
BOOL_MICRO=$(echo "$BOOL_MICRO" | tr '[:upper:]' '[:lower:]')
case $BOOL_MICRO in
y)
BOOL_MICRO="True"
break
;;
n)
BOOL_MICRO="False"
break
;;
*)
clear
echo "Invalid choice. Please try again (CTRL+C to quit)"
;;
esac
done
clear
read -p "Enter the Subnet OCID (or press Enter to skip): " SUBNET_ID
clear
read -p "Enter the Image OCID (or press Enter to skip): " IMAGE_ID
clear
while true; do
read -p "Enable Gmail notification? (y/n): " BOOL_MAIL
BOOL_MAIL=$(echo "$BOOL_MAIL" | tr '[:upper:]' '[:lower:]')
case $BOOL_MAIL in
y)
BOOL_MAIL="True"
break
;;
n)
BOOL_MAIL="False"
break
;;
*)
clear
echo "Invalid choice. Please try again (CTRL+C to quit)"
;;
esac
done
clear
if [[ $BOOL_MAIL == "True" ]]; then
read -p "Enter your email: " EMAIL
clear
read -p "Enter email app password (16 characters without spaces): " EMAIL_PASS
clear
fi
read -p "Enter Discord webhook URL (or press Enter to skip): " DISCORD_WEBHOOK
clear
# Backup existing oci.env if it exists
if [ -f oci.env ]; then
mv oci.env oci.env.bak
echo "Existing oci.env file backed up as oci.env.bak"
fi
# Create the new oci.env file with the gathered configuration
cat <<EOF > oci.env
# OCI Configuration
OCI_CONFIG=$HOME/oracle-freetier-instance-creation/oci_config
OCT_FREE_AD=AD-1
DISPLAY_NAME=$INSTANCE_NAME
# The other free shape is AMD: VM.Standard.E2.1.Micro
OCI_COMPUTE_SHAPE=$SHAPE
SECOND_MICRO_INSTANCE=$BOOL_MICRO
REQUEST_WAIT_TIME_SECS=60
SSH_AUTHORIZED_KEYS_FILE=$HOME/oracle-freetier-instance-creation/id_rsa.pub
# SUBNET_ID to use ONLY in case running in local or a non E2.1.Micro instance
OCI_SUBNET_ID=$SUBNET_ID
OCI_IMAGE_ID=$IMAGE_ID
# The following will be ignored if OCI_IMAGE_ID is specified
OPERATING_SYSTEM=Canonical Ubuntu
OS_VERSION=22.04
# Gmail Notification
NOTIFY_EMAIL=$BOOL_MAIL
EMAIL=$EMAIL
EMAIL_PASSWORD=$EMAIL_PASS
# Discord Notification (optional)
DISCORD_WEBHOOK=$DISCORD_WEBHOOK
EOF
echo "OCI env configuration saved to oci.env"