-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·65 lines (57 loc) · 1.75 KB
/
install.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
#!/bin/bash
function prompt {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) echo "Aborted" ; return 1 ;;
esac
done
}
DISABLE_SECURITY=false;
if prompt "Would you like to disable security features?"; then
DISABLE_SECURITY=true;
fi
echo "Compiling the MySQL UDF"
CWD=$(pwd)
rm -rf "${CWD}/build"
mkdir "${CWD}/build"
if $DISABLE_SECURITY; then
cd "${CWD}/build" && cmake "${CWD}" -DSECURE_INSTALL=OFF && cmake --build "${CWD}/build" && cmake --install "${CWD}/build"
else
cd "${CWD}/build" && cmake "${CWD}" && cmake --build "${CWD}/build" && cmake --install "${CWD}/build"
fi
if test $? -ne 0; then
echo "ERROR: Compilation error"
exit 1
else
echo "MySQL UDF compiled successfully"
fi
if prompt "The home directory for the mysql user must be set in /etc/passwd. Would you like to set that now?"; then
printf "" > /etc/passwd.new
while read line; do
IFS=':' read -ra ADDR <<< "$line"
if [[ "${ADDR[0]}" = "mysql" ]]; then
echo "${ADDR[0]}:${ADDR[1]}:${ADDR[2]}:${ADDR[3]}:${ADDR[4]}:/home/mysql-scripts:${ADDR[6]}" >> /etc/passwd.new
else
echo "$line" >> /etc/passwd.new
fi
done < /etc/passwd
mkdir /home/mysql-scripts
echo 'cd "$HOME"' > /home/mysql-scripts/.bash_profile
chmod 0755 /home/mysql-scripts/.bash_profile
cp /etc/passwd /etc/passwd.old
mv /etc/passwd.new /etc/passwd
fi
echo -e "\nPlease provide your MySQL root password"
if $DISABLE_SECURITY; then
mysql -u root -p mysql < "${CWD}/lib_mysqludf_secure_shell_with_run.sql"
else
mysql -u root -p mysql < "${CWD}/lib_mysqludf_secure_shell.sql"
fi
if test $? -ne 0; then
echo "ERROR: unable to install the UDF"
exit 1
else
echo "MySQL UDF installed successfully"
fi