-
Notifications
You must be signed in to change notification settings - Fork 3
/
_installhelpers.sh
150 lines (119 loc) · 3.61 KB
/
_installhelpers.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
#!/bin/bash
function abort {
echo Aborted.
exit 1
}
function separator {
echo " "
echo "------------------------------------------------"
echo " "
}
function setTimeZone {
mapfile -t TIME_ZONES < <( timedatectl list-timezones )
TIME_ZONE=$(whiptail --title "$whiptitle" --backtitle "$backtitle" --menu "Select a timezone for your server or Cancel to skip." 30 80 20 "${TIME_ZONES[@]}" 3>&1 1>&2 2>&3)
if [ ! "$TIME_ZONE" = "" ]; then
separator
echo "Setting timezone to $TIME_ZONE"
echo "$TIME_ZONE" | sudo tee /etc/timezone
fi
}
function getWebRoot {
WEB_ROOT=$(whiptail --title "$whiptitle" --backtitle "$backtitle" --inputbox "What is the full path to your web root (ex. /web)" 10 80 "/web" 3>&1 1>&2 2>&3)
if [ ! $? = 0 ]; then
confirmCancel
getWebRoot
elif [ "$WEB_ROOT" = "" ]; then
getWebRoot
fi
export WEB_ROOT
}
function getHostName {
HOST_NAME=$(whiptail --title "$whiptitle" --backtitle "$backtitle" --inputbox "What is the default server hostname?" 10 80 "$HOSTNAME" 3>&1 1>&2 2>&3)
if [ ! $? = 0 ]; then
confirmCancel
getHostName
elif [ "$HOST_NAME" = "" ]; then
getHostName
fi
export HOST_NAME
}
function getWhiteList {
WHITELIST_IP=$(whiptail --title "$whiptitle" --backtitle "$backtitle" --inputbox "Enter an IP address you'd like to whitelist for Admin (optional)" 10 80 "" 3>&1 1>&2 2>&3)
if [ ! $? = 0 ]; then
confirmCancel
getWhiteLlist
fi
export WHITELIST_IP
}
function getAdminPassword {
ADMIN_PASSWORD=$(whiptail --title "$whiptitle" --backtitle "$backtitle" --passwordbox "Admin Password (Leave blank for a randomly generated password)" 10 80 3>&1 1>&2 2>&3)
if [ ! $? = 0 ]; then
confirmCancel
getAdminPassword
fi
if [ "$ADMIN_PASSWORD" = "" ]; then
RANDPASS="Random"
ADMIN_PASSWORD=$(tr -cd '[:alnum:]' < /dev/urandom | fold -w20 | head -n1)
else
RANDPASS="User Defined"
fi
export ADMIN_PASSWORD
}
CF_ENGINE="lucee"
function getCFEngine {
# RE for determining validity of cfengine
engineCheck="^(lucee|adobe)@?([0-9]|\.|\-)*$"
shopt -s nocasematch;
CF_ENGINE=$(whiptail --title "$whiptitle" --backtitle "$backtitle" --inputbox "Which CF engine should be used?" 10 80 "$CF_ENGINE" 3>&1 1>&2 2>&3)
if [ ! $? = 0 ]; then
confirmCancel
getCFEngine
elif ! [[ "$CF_ENGINE" =~ $engineCheck ]]; then
getCFEngine
fi
export CF_ENGINE
}
function getRewritesEnabled {
if( whiptail --title "$whiptitle" --backtitle "$backtitle" --yesno "Do you want to enable commandbox URL rewrites?" 10 40 )
then
REWRITES_ENABLED="true"
else
REWRITES_ENABLED="false"
fi
export REWRITES_ENABLED
}
function getCertBotSetup {
if( whiptail --title "$whiptitle" --backtitle "$backtitle" --yesno "Do you want to setup a certificate with certbot?" 10 40 )
then
CERTBOT="Yes"
else
CERTBOT="No"
fi
export CERTBOT
}
function confirmInputs {
if(! whiptail --title "$whiptitle" --backtitle "$backtitle" --yesno "Is this information correct?\n\nWEBROOT..........: $WEB_ROOT \nHOSTNAME.........: $HOST_NAME \nCF ENGINE........: $CF_ENGINE \nWHITELIST........: $WHITELIST_IP \nREWRITES.........: $REWRITES_ENABLED \nPASSWORD.........: $RANDPASS \nSETUP CERT:......: $CERTBOT" 14 60 )
then
getUserInputs
fi
}
function confirmCancel {
if ( whiptail --title "$whiptitle" --backtitle "$backtitle" --yesno "Are you sure you want to cancel?" 10 40 )
then
abort
fi
}
function getSetupComplete {
whiptail --title "$whiptitle" --backtitle "$backtitle" --msgbox "All done! \n\nOpen http://$HOSTNAME to test it out." 10 40
}
function getUserInputs {
setTimeZone
getWebRoot
getHostName
getCFEngine
getWhiteList
getRewritesEnabled
getAdminPassword
getCertBotSetup
confirmInputs
}