-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
180 lines (141 loc) · 4.04 KB
/
install
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
#!/usr/bin/env bash
# If the color table file exists,
if [[ -f "${coltable}" ]]; then
# source it
source ${coltable}
# Otherwise,
else
# Set these values so the installer can still run in color
COL_NC='\e[0m' # No Color
COL_LIGHT_BLUE='\e[34;40m'
COL_LIGHT_GREEN='\e[1;32m'
COL_LIGHT_RED='\e[1;31m'
TICK="[${COL_LIGHT_GREEN}✓${COL_NC}]"
CROSS="[${COL_LIGHT_RED}✗${COL_NC}]"
INFO="[i]"
# shellcheck disable=SC2034
DONE="${COL_LIGHT_GREEN} done!${COL_NC}"
OVER="\\r\\033[K"
fi
accii_logo() {
echo -e ""
}
is_command() {
# Checks for existence of string passed in as only function argument.
# Exit value of 0 when exists, 1 if not exists. Value is the result
# of the `command` shell built-in call.
local check_command="$1"
command -v "${check_command}" >/dev/null 2>&1
}
add_repo() {
}
run_install_mariadb(){
apt-get -y install mariadb-server
}
config_mariadb(){
https://gist.githubusercontent.com/coderua/5592d95970038944d099/raw/98c2ffabc1fd9db73650acbf44ce7b349831f7b8/mysql_secure.sh
}
run_install_PDNS() {
apt-get -y install pdns-server pdns-backend-mysql
}
edit_config_PDNS() {
}
create_passwd(){
}
mysql_secure(){
# Usage:
# Setup mysql root password: mysql_secure 'your_new_root_password'
# Change mysql root password: mysql_secure 'your_old_root_password' 'your_new_root_password'"
#
PURGE_EXPECT_WHEN_DONE=0
if [ -n "${1}" -a -z "${2}" ]; then
# Setup root password
CURRENT_MYSQL_PASSWORD=''
NEW_MYSQL_PASSWORD="${1}"
elif [ -n "${1}" -a -n "${2}" ]; then
# Change existens root password
CURRENT_MYSQL_PASSWORD="${1}"
NEW_MYSQL_PASSWORD="${2}"
else
echo "Usage:"
echo " Setup mysql root password: ${0} 'your_new_root_password'"
echo " Change mysql root password: ${0} 'your_old_root_password' 'your_new_root_password'"
fi
if [ $(dpkg-query -W -f='${Status}' expect 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
echo "Can't find expect. Trying install it..."
apt -y install expect
fi
SECURE_MYSQL=$(expect -c "
set timeout 3
spawn mysql_secure_installation
expect \"Enter current password for root (enter for none):\"
send \"$CURRENT_MYSQL_PASSWORD\r\"
expect \"root password?\"
send \"y\r\"
expect \"New password:\"
send \"$NEW_MYSQL_PASSWORD\r\"
expect \"Re-enter new password:\"
send \"$NEW_MYSQL_PASSWORD\r\"
expect \"Remove anonymous users?\"
send \"y\r\"
expect \"Disallow root login remotely?\"
send \"y\r\"
expect \"Remove test database and access to it?\"
send \"y\r\"
expect \"Reload privilege tables now?\"
send \"y\r\"
expect eof
")
echo "${SECURE_MYSQL}"
if [ "${PURGE_EXPECT_WHEN_DONE}" -eq 1 ]; then
apt -y purge expect
fi
}
rw_check() {
epoch=$(date +%s)
touch /etc/rwcheck-$epoch
if [[ -f /etc/rwcheck-$epoch ]]; then
printf "%b %b Read/Write Access Confirmed\\n" "${OVER}" "${TICK}"
rm /etc/rwcheck-$epoch
else
printf "%b %b Read Only Access\\n" "${OVER}" "${CROSS}"
fi
}
root_check(){
# Must be root to install
local str="Root user check"
printf "\\n"
if [[ "${EUID}" -eq 0 ]]; then
printf " %b %s\\n" "${TICK}" "${str}"
else
printf " %b %s\\n" "${CROSS}" "${str}"
printf " %b %bScript called with non-root privileges%b\\n" "${INFO}" "${COL_LIGHT_RED}" "${COL_NC}"
printf " The unifi-pimd requires elevated privileges to install and run\\n"
printf " %b Sudo utility check" "${INFO}"
if is_command sudo ; then
printf "%b %b Sudo utility check\\n" "${OVER}" "${TICK}"
# Download the install script and run it with admin rights
exec curl -sSL https://raw.githubusercontent.com/bcsanford/PDNSwGUI/master/install | sudo bash "$@"
exit $?
else
printf "%b %b Sudo utility check\\n" "${OVER}" "${CROSS}"
printf " %b Sudo is needed to install and configure unifi-pimd\\n\\n" "${INFO}"
printf " %b %bPlease re-run this installer as root${COL_NC}\\n" "${INFO}" "${COL_LIGHT_RED}"
exit 1
fi
fi
}
main() {
accii_logo
printf "%b %b PDNSwGUI Version: 0.0.1\\n" "${OVER}" "${INFO}"
rw_check
root_check
#add_repo
run_install_mariadb
mysql_secure
run_install_PDNS
#service pimd stop
#edit_config
#service pimd start
}
main "$@"