-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunMe.sh
executable file
·138 lines (118 loc) · 3.74 KB
/
RunMe.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
135
136
137
138
#!/bin/bash
set -eu
############ SCRIPT CHECKSUM VERIFICATION START ####################
declare -A scripts_checksum=(
["scripts/ec2_public_ip_add.sh"]="scripts/ec2_public_ip_add.sh.checksum"
["scripts/ec2_public_ip_remove.sh"]="scripts/ec2_public_ip_remove.sh.checksum"
["scripts/ansible_dock_aws_kube.sh"]="scripts/ansible_dock_aws_kube.sh.checksum"
["scripts/config_ssh_modification.sh"]="scripts/config_ssh_modification.sh.checksum"
["scripts/infra_deployment.sh"]="scripts/infra_deployment.sh.checksum"
["scripts/echo_scripts.sh"]="scripts/echo_scripts.sh.checksum"
["scripts/cleanup.sh"]="scripts/cleanup.sh.checksum"
["scripts/templates.sh"]="scripts/templates.sh.checksum"
["scripts/jenkins_p1_main.sh"]="scripts/jenkins_p1_main.sh.checksum"
["scripts/jenkins_p2_PassGen.sh"]="scripts/jenkins_p2_PassGen.sh.checksum"
)
for script in "${!scripts_checksum[@]}"; do
checksum_generated=$(sha256sum $script | cut -d ' ' -f1)
#echo "generated $checksum_generated"
checksum_expected=$(cat ${scripts_checksum[$script]})
#echo "expected $checksum_expected"
if [ $checksum_generated != $checksum_expected ]; then
echo -e "######################################\nERROR: $script has been modified"
echo -e "Please verify that your $HOSTNAME is secure\n######################################\n"
echo -e "Note: To remove the security check\nYou can remove 'SCRIPT CHECKSUM VERIFICATION' section\nTo bypass check, yet it is not recommended."
exit 1
fi
done
echo -e "\n######################################\nSUCCESS: Scripts has not been modified\n######################################\n"
sleep 2
############ SCRIPT CHECKSUM VERIFICATION END ####################
source scripts/config_ssh_modification.sh
source scripts/infra_deployment.sh
source scripts/echo_scripts.sh
source scripts/cleanup.sh
source scripts/templates.sh
source scripts/jenkins_p1_main.sh
export CAPSTONE_PROJECT=$PWD
EXIT=0
while [ $EXIT -ne 1 ]
do
echo "Choose one of the options to run the capstone project: (q to quit)"
echo "1 - Prepare Credentials directory"
echo " -------- "
echo "2 - Run Terrafrom then Run Playbook Ansible"
echo " -------- "
echo "3 - Run Terrafrom Only"
echo "4 - Run Ansible Playbook Only"
echo " -------- "
echo "5 - SSH to the deployed EC2 instance (Will work Soon..)"
echo "6 - Push credentials to Jenkins"
echo " -------- "
echo "7 - Destroy Infrastructure (no-confirmation)"
echo "8 - Cleaup"
echo "q - Exit"
read num
case $num in
1)
mkdir -p creds
# Script: config_ssh_modification
create_config_file 2>/dev/null && chmod 600 creds/config
create_include_config_ssh
create_aws_creds;;
2)
# Script: infra_deployment
echo "Deploying Infrastructure..."
terraform_deploy
create_pem_file
echo "Preparing ssh config in 15s"
sleep 15
echo "pushing Ansible configuration to EC2..."
ansible_deploy
clear
# script: echo_scripts
echo_terraform_deploy
echo_ansible_ansible
break;;
3)
# Script: infra_deployment
terraform_deploy
# Script: config_ssh_modification
create_pem_file
clear
# script: echo_scripts
echo_terraform_deploy
break;;
4)
# Script: infra_deployment
ansible_deploy
# script: echo_scripts
echo_ansible_ansible
break;;
5)
;;
6)
jenkins_password
break;;
7)
# Script: infra_deployment
terraform_destroy
clear
# script: echo_scripts
echo_terraform_destroy
break;;
8)
remove_include_config_ssh
echo_remove_include_config_ssh
delete_creds_dir
echo_delete_creds_dir
break;;
q)
EXIT=1
echo "Exiting..."
sleep 3;;
*)
echo "You have chosen unidentified number, try again..."
esac
done
echo -e "\n **--Thank you for using the script--**"