-
Notifications
You must be signed in to change notification settings - Fork 78
/
install.sh
executable file
·131 lines (117 loc) · 3.84 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
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
# This script will set all the config variables for you
# go to script dir
BASEDIR=$(dirname "$0")
cd "$BASEDIR" || exit 1
# Set some defaults
# config.php
readonly CONFIG_PHP_EX="config.example.php"
readonly CONFIG_PHP="config.php"
SYS_DB_NAME=""
SYS_DB_USER=""
SYS_DB_PSWD=""
SYS_DB_HOST="localhost"
SYS_DB_PORT="3306"
# variables.json
readonly VARIABLES_JSON_EX="core/json/variables.examples.json"
readonly VARIABLES_JSON="core/json/variables.json"
SITE_NAME="Worldopole"
CITY="Weuuurld"
MAP_CENTER_LAT="50.844441"
MAP_CENTER_LONG="4.363557"
GMAPS_KEY=""
TIMEZONE="Europe/Paris"
readinput() {
local prompt_text=$1
local default_text=$2
read -r -e -i "$default_text" -p "$prompt_text" input
echo "$input"
}
# MAIN
echo "Welcome to Worldopole installation"
if [ "$EUID" -ne 0 ]; then
echo
echo "Notice: Running script with other user than root might fail!"
fi
echo
echo "Please enter all the following values and press ENTER to confirm"
echo
# Loop until answer is yes
until [ "$answer" == 'y' ]; do
# Get input
echo "- MySQL Settings -"
SYS_DB_NAME=$(readinput "MySQL Database Name: " "$SYS_DB_NAME")
SYS_DB_USER=$(readinput "MySQL User: " "$SYS_DB_USER")
SYS_DB_PSWD=$(readinput "MySQL Password: " "$SYS_DB_PSWD")
SYS_DB_HOST=$(readinput "MySQL Host: " "$SYS_DB_HOST")
SYS_DB_PORT=$(readinput "MySQL Port: " "$SYS_DB_PORT")
echo
echo "- Site Settings -"
SITE_NAME=$(readinput "Site Name: " "$SITE_NAME")
CITY=$(readinput "City Name: " "$CITY")
MAP_CENTER_LAT=$(readinput "Map Center Latitude: " "$MAP_CENTER_LAT")
MAP_CENTER_LONG=$(readinput "Map Center Longitude: " "$MAP_CENTER_LONG")
GMAPS_KEY=$(readinput "GMaps API Key: " "$GMAPS_KEY")
TIMEZONE=$(readinput "Server Timezone (see http://php.net/manual/en/timezones.php): " "$TIMEZONE")
# Show input for verification
echo
echo "You entered the following data:"
echo
echo "- MySQL Settings -"
echo "MySQL Database Name: $SYS_DB_NAME"
echo "MySQL User: $SYS_DB_USER"
echo "MySQL Password: $SYS_DB_PSWD"
echo "MySQL Host: $SYS_DB_HOST"
echo "MySQL Port: $SYS_DB_PORT"
echo
echo "- Site Settings -"
echo "Site Name: $SITE_NAME"
echo "City Name: $CITY"
echo "Map Center Latitude: $MAP_CENTER_LAT"
echo "Map Center Longitude: $MAP_CENTER_LONG"
echo "GMaps API Key: $GMAPS_KEY"
echo "Server Timezone: $TIMEZONE"
echo
# yes or no
read -r -n 1 -p "Is everything correct [y/n] " answer
if [ "$answer" != 'y' ]; then
echo
echo "Do your edits:"
echo
fi
done
echo
echo
# Replace default values with the ones set above
echo "Writing $CONFIG_PHP ..."
sed -e "s/#SYS_DB_NAME#/$SYS_DB_NAME/" \
-e "s/#SYS_DB_USER#/$SYS_DB_USER/" \
-e "s/#SYS_DB_PSWD#/$SYS_DB_PSWD/" \
-e "s/#SYS_DB_HOST#/$SYS_DB_HOST/" \
-e "s/3306/$SYS_DB_PORT/" \
"$CONFIG_PHP_EX" > "$CONFIG_PHP"
# We have to escape the / from timezone
TIMEZONE=$(echo "$TIMEZONE" | sed 's/\//\\\//g')
echo "Writing $VARIABLES_JSON ..."
sed -e "s/\"Worldopole\"/\"$SITE_NAME\"/" \
-e "s/\"Weuuurld\"/\"$CITY\"/" \
-e "s/\"50.844441\"/\"$MAP_CENTER_LAT\"/" \
-e "s/\"4.363557\"/\"$MAP_CENTER_LONG\"/" \
-e "s/#GMAPS_KEY#/$GMAPS_KEY/" \
-e "s/\"Europe\/Paris\"/\"$TIMEZONE\"/" \
"$VARIABLES_JSON_EX" > "$VARIABLES_JSON"
# Rename htaccess
cp -v htaccess .htaccess
echo
echo "For even more settings have a look at $BASEDIR/$VARIABLES_JSON"
echo "Please make sure that your webserver user has read/write access to /core/json/ & /install/ folders"
echo
echo "Everything is set up. Catch 'Em All!"
echo
echo
echo "Optional: If you want to enable Dashboard add the following to your crontab"
echo ' Just copy it. Then paste it after executing "sudo crontab -e" and save the file'
echo "*/15 * * * * php $BASEDIR/core/cron/crontabs.include.php >/dev/null 2>&1"
echo
echo "Afterwards add the following to your $VARIABLES_JSON file inside the \"menu\" tag:"
echo '{ "type" : "link", "href" : "dashboard", "text" : "Dashboard", "icon" : "fa-area-chart" }'