-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.sh
executable file
·121 lines (80 loc) · 2.99 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
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
#!/bin/bash -x
# my-geo-ip -- The my-geo-ip package provides geo-ip services to
# applications via a MySQL database.
#
# Copyright (C) 2016-2019 Isaac Lewis
### Install my-geo-ip.
## Setup environment variables and error handling.
$bash_set_cmd
# Set the shell options.
shopt -s extglob
# Load all required environment variables.
source env.sh
# Set any traps.
source trap.sh
##
# Set the type of action being performed.
geo_ip_act="Install"
# Remove any previous installations.
quiet id "geo-ip" && echo "Removing any previous installations" && ./uninstall.sh
## Setup the geo-ip system user.
# Create the geo-ip system user.
useradd --user-group --create-home --shell /bin/bash --system "geo-ip"
# Add the geo-ip user to the MySQL group (for access to
# /var/lib/mysql-files).
usermod -a -G mysql geo-ip
# Create the downloads directory.
mkdir -p "$geo_ip_home/downloads"
# Copy the required files to the user's home dir.
cp -r !(makefile||*install.sh||*~) "$geo_ip_home"
# Create an empty log file.
touch "$geo_ip_home/log.txt"
# Make sure all files in geo-ip's home dir are owned by geo-ip.
chown -R geo-ip:geo-ip /home/geo-ip
##
## Install the necessary MySQL directories.
mkdir -p $mysql_my_geo_ip_dir
mkdir -p $mysql_data_dir
# Create the directory that my-geo-ip will use to load SQL files. The
# directory must be listed in the value of the MySQL variable
# 'secure_file_priv' (see 'global-env.h' for more details).
mkdir -p $mysql_geo_ip_load_dir
cp "lib-admin.sql" $mysql_geo_ip_load_dir
# Allow users in the mysql group to write to the load dir and deny all
# other users access.
chmod -R u=+rwx,g=+rwx,o=-rwx $mysql_load_dir
# Make sure mysql owns all files in the $mysql_my_geo_ip_dir.
chown -R mysql:mysql $mysql_my_geo_ip_dir
##
## Configure MySQL.
# Generate the MySQL passwords.
source build-passwords.sh
# Generate the MySQL config for the system user root. When debugging,
# make sure that all shell environment variables have been loaded
# before running the following commands.
envsubst < templates/root.my.cnf.tp > "/root/.my.cnf"
# Generate the MySQL config for the system user geo-ip.
envsubst < templates/geo-ip.my.cnf.tp > "$geo_ip_home/.my.cnf"
chown geo-ip /home/geo-ip/.my.cnf
# Include this for 'mysql_start'.
source lib-mysql-helpers.sh
# Initialize MySQL; this doesn't start a MySQL server that listens for
# connections.
mysqld --initialize-insecure
##
## Install the geo-ip database.
# Start the MySQL server and listen for connections.
mysql_start
# Create the empty geo-ip database.
eval "envsubst < templates/create-database.sql.tp | mysql --table --password=\"\""
# Create users for the geo-ip database.
eval "envsubst < templates/create-users.sql.tp | mysql --table --password=\"\""
# Update the geo-ip database.
source update.sh
# Perform a basic test.
echo "CALL geo_ip.info('012.034.056.078')\G" | mysql --table
# Create a crontab to keep the database current.
envsubst < templates/crontab.tp | crontab -u "geo-ip" '-'
# Shutdown the MySQL server.
mysql_stop
##