/
menu.sh
executable file
·229 lines (221 loc) · 7.99 KB
/
menu.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
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
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/bin/bash
##########################################################
#
# Info and Config Menu for zPlanner Appliance
#
##########################################################
while true
do
# get network information (get each time in case it changes)
interface=$(cat /etc/network/interfaces | grep -i "iface" | grep -vi "lo" | awk '{print $2}')
iptype=$(cat /etc/network/interfaces | grep -vi "lo" | grep -i "inet" | awk '{print $NF}')
ipinfo=$(ifconfig $interface | awk '/inet addr/' | sed "s/^[ \t]*//")
ipgw=$(ip route | grep -i "default" | awk '{ print $3 }')
# start menu output
clear
echo "=================================================="
echo "= zPlanner Info and Config menu v4.0.2 ="
echo "=================================================="
echo "Current Network Config:"
echo " Interface Name: $interface"
echo " Static \ DHCP: $iptype"
echo " Details: $ipinfo"
echo " Default Gateway: $ipgw"
echo "=================================================="
echo -e "Select an action from the menu below\n"
echo "1.) Update zPlanner 2.) Configure Network Settings"
echo "3.) Config Hypervisor Info 4.) Test Hypervisor Connectivity"
echo "5.) Generate VM List 6.) Start Scheduled Jobs"
echo "7.) Config Auto Login 8.) Delete Scheduled Jobs"
echo "9.) Bash Shell 0.) Quit"
read choice
case "$choice" in
1) # Update zPlanner Scripts from Github
clear
echo "Updating zPlanner from github"
(cd /home/zerto/zplanner/ && git reset --hard HEAD && git pull http://www.github.com/zerto-ta-public/zplanner/)
echo "Running Update Helper Script"
(/bin/bash /home/zerto/zplanner/updates.sh)
;;
2) # Config Network Settings
clear
echo "====================="
echo "Network Config Wizard"
echo -e "=====================\n"
echo "Configure appliance with DHCP or STATIC IP? (S=Static, D=DHCP)"
read cronvminfo
case "$cronvminfo" in
"S" | "s") # update /etc/network/interface with static config
echo "Enter IP address (xxx.xxx.xxx.xxx):"
read nicip
echo "Enter Subnet Mask (xxx.xxx.xxx.xxx):"
read nicmask
echo "Enter Default Gateway (xxx.xxx.xxx.xxx):"
read nicgw
echo "Enter DNS Servers (Seperate by space):"
read nicdns
echo "Does everything look correct? (Y/N)"
read confirm
case "$confirm" in
"Y" | "y")
awk -f /home/zerto/zplanner/modules/changeInterface.awk /etc/network/interfaces device="$interface" mode=static address="$nicip" netmask="$nicmask" dns="$nicdns" gateway="$nicgw" | sudo tee /etc/network/interfaces
sudo /etc/init.d/networking restart
;;
*)
break
;;
esac
;;
"D" | "d") # update /etc/network/interface with dhcp config
awk -f /home/zerto/zplanner/modules/changeInterface.awk /etc/network/interfaces device=enp0s17 mode=dhcp | sudo tee /etc/network/interfaces
sudo /etc/init.d/networking restart
;;
*) echo "invalid option try again";;
esac
;;
3) # Config Customer Information
clear
echo "========================"
echo "Hypervizor Config Wizard"
echo -e "========================\n"
/usr/bin/pwsh /home/zerto/zplanner/workers/vm-setenv.ps1
;;
4) # Test Hypervisor connectivity
clear
echo "==============================="
echo "Testing Hypervizor Connectivity"
echo -e "===============================\n"
/usr/bin/pwsh /home/zerto/zplanner/workers/vm-testenv.ps1
echo "If an error occured please run Hypervisor Configuration Wizard"
;;
5) # Config Customer Information
clear
echo "========================"
echo "Generating List of VMs"
echo -e "========================\n"
/usr/bin/pwsh /home/zerto/zplanner/workers/vm-getvms.ps1
;;
6) # Schedule Cron Jobs
clear
echo "====================="
echo "Job Scheduling Wizard"
echo -e "=====================\n"
echo "Generating Crontab configuration..."
#Add Line to gather CPU and Memory information
line="@daily /usr/bin/pwsh /home/zerto/zplanner/workers/vm-vminfo.ps1"
(crontab -u zerto -l; echo "$line" ) | crontab -u zerto -
#Add cron for gathering statistics every 5 minutes
echo "5" > /home/zerto/include/interval.txt
line="*/5 * * * * /usr/bin/pwsh /home/zerto/zplanner/workers/vm-getio.ps1"
(crontab -u zerto -l; echo "$line" ) | crontab -u zerto -
#Add Log cleanup to run once per day
line="@daily /usr/bin/find /home/zerto/logs -mtime +7 -type f -delete"
(crontab -u zerto -l; echo "$line" ) | crontab -u zerto -
crontab -l
;;
7) # Config Auto Login
enacfgfile=/etc/systemd/system/getty@tty1.service.d/override.conf
discfgfile=/etc/systemd/system/getty@tty1.service.d/override.conf.disabled
# see if override.conf is in place
if [ -f "$enacfgfile" ]
then
echo "Enabled"
login="Enabled"
nigol="Disabled"
else
echo "Disabled"
login="Disabled"
nigol="Enabled"
fi
echo "Current Autologin status: $login"
echo "Would you like to change this? (Y/N):"
read autologin
case "$autologin" in
"y" | "Y") # switch autologin status
echo "Reconfiguring Auto Login from $login to $nigol"
if [ "$login" == "Enabled" ]
then
sudo mv $enacfgfile $discfgfile
echo "Disabling Auto Login Completed"
else
sudo mv $discfgfile $enacfgfile
echo "Enabling Auto Login Completed"
fi
;;
*) # do nothing
echo "Nothing to do..."
;;
esac
;;
8) # Kill all exisint CronJobs
clear
echo "=============================="
echo "Existing Cron jobs "
echo "=============================="
crontab -l
echo "=========== WARNING =========="
echo "Remove all existing Cron Jobs? (Y/N)"
read crondel
case "$crondel" in
"y" | "Y") # delete crontab
crontab -r
#Add Log cleanup to run once per day
line="@daily /usr/bin/find /home/zerto/logs -mtime +7 -type f -delete"
(crontab -u zerto -l; echo "$line" ) | crontab -u zerto -
#Add auto update to run once per day
line="@daily /bin/bash /home/zerto/zplanner/modules/nightlyupdate.sh"
(crontab -u zerto -l; echo "$line" ) | crontab -u zerto -
;;
*) # do nothing
;;
esac
;;
9) # enter bash shell prompt
clear
/bin/bash
;;
0) # exit the menu script
exit
;;
A) # Advanced Menu
while true
do
clear
echo "=============================="
echo "Advanced Menu "
echo "=============================="
echo -e "Select an action from the menu below\n"
echo "1.) Manually Run VMInfo Script"
echo "2.) Dump SQL DB to Zerto FTP"
echo "3.) Reserved"
echo "4.) Reserved"
echo "0.) Back to Main Menu"
read adv
case "$adv" in
1) # Manually run VMInfo Script
/usr/bin/pwsh /home/zerto/zplanner/workers/vm-vminfo.ps1
;;
2) # Dump SQL DB to Zerto FTP
echo "==================================="
echo "Dumping database to file"
#do some db dump stuff here
;;
3) # reserved
break
;;
4) # reserved
break
;;
0) # go back to main menu
break
;;
*) echo "invalid option try again";;
esac
done
;;
*) echo "invalid option try again";;
esac
echo "Press any key to Continue..."
read input
done
done