-
Notifications
You must be signed in to change notification settings - Fork 60
/
install.sh
executable file
·167 lines (151 loc) · 4.81 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
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
#!/bin/sh
# Hauk automatic installation script for Linux servers
# Copyright (C) 2019 Marius Lindvall under the Apache 2.0 License
# Source code available freely at https://github.com/bilde2910/Hauk
hauk_help() {
echo -e "\033[1m\033[94mHauk automatic installer\033[0m"
echo ""
echo -e "\033[1mUsage:\033[0m"
echo -e "./install.sh \033[90m[\033[0moptions\033[90m] \033[0mweb_root"
echo ""
echo -e "\033[1mDescription:\033[0m"
echo "Installs Hauk to the specified web root directory, e.g. /var/www/html"
echo ""
echo -e "\033[1mOptions:\033[0m"
echo -e "\033[91m-c\t\033[0mInstall config file to $config"
echo -e "\033[91m-f\t\033[0mOverwrite without asking"
exit 1
}
# Centralized configuration
if [ "$(uname -s)" = "FreeBSD" ]; then
confdir=/usr/local/etc/hauk
config=/usr/local/etc/hauk/config.php
else
confdir=/etc/hauk
config=/etc/hauk/config.php
fi
useconf=0
# Print help if no arguments given
if [ "$#" -eq 0 ]; then
hauk_help
fi
# Get the installation path (last argument)
for webroot; do true; done
# If a flag is the last argument, no path is given, so print help and exit
if [ "$webroot" = "-f" ] || [ "$webroot" = "-c" ]; then
hauk_help
fi
hauk_config() {
if [ -f "$config" ]; then
if [ "$1" != "-f" ] && [ "$2" != "-f" ]; then
read -p "Config file already exists! Overwrite? [y/N]: " repl
case "$repl" in
[Yy]*)
rm "$config" >/dev/null 2>&1
if [ -f "$config" ]; then
echo "You do not have permissions to install the configuration file in"
echo "${confdir}. Please run this script as root."
exit 5
fi
;;
esac
else
rm "$config" >/dev/null 2>&1
if [ -f "$config" ]; then
echo "You do not have permissions to install the configuration file in"
echo "${confdir}. Please run this script as root."
exit 5
fi
fi
fi
if ! [ -f "$config" ]; then
if ! [ -d "$confdir" ]; then
mkdir -p "$confdir" >/dev/null 2>&1
fi
cp backend-php/include/config-sample.php "$config" >/dev/null 2>&1
fi
if ! [ -f "$config" ]; then
echo "You do not have permissions to install the configuration file in"
echo "/etc/hauk. Please run this script as root."
exit 5
fi
useconf=1
}
if ! [ -d "$webroot" ]; then
if [ "$1" != "-f" ] && [ "$2" != "-f" ]; then
read -p "Target directory does not exist. Create it? [Y/n]: " empty
case "$empty" in
[Nn]*)
echo "Aborting..."
exit 2
;;
*)
mkdir -p "$webroot" >/dev/null 2>&1
;;
esac
else
mkdir -p "$webroot" >/dev/null 2>&1
fi
fi
if ! [ -d "$webroot" ] || ! [ -w "$webroot" ]; then
echo "You do not have sufficient permissions to install Hauk to this"
echo "directory. Please make sure you have write permission to the"
echo "installation directory and try again."
exit 3
fi
if [ "$(ls -A "$webroot")" ]; then
if [ "$1" != "-f" ] && [ "$2" != "-f" ]; then
echo "WARNING! Target directory is not empty. If you proceed with the"
echo "installation, all files in the directory will be deleted."
read -p "Delete files and continue install? [y/N]: " empty
case "$empty" in
[Yy]*)
rm -rf "$webroot"
mkdir "$webroot"
;;
*)
echo "Aborting..."
exit 4
;;
esac
else
rm -rf "$webroot"
mkdir "$webroot"
fi
fi
if [ "$1" != "-c" ] && [ "$2" != "-c" ]; then
read -p "Install config file to /etc/hauk? [Y/n]: " empty
case "$empty" in
[Nn]*) ;;
*) hauk_config;;
esac
else
hauk_config
fi
cp -R backend-php/* "$webroot"
cp -R frontend/* "$webroot"
# Determine the path in which config is saved
if [ "$useconf" -eq 0 ]; then
confpath="$webroot/include/config.php"
cp backend-php/include/config-sample.php "$confpath" >/dev/null 2>&1
fi
echo ""
echo -e "\033[1m\033[92mInstallation complete!\033[0m"
echo "Before you use Hauk, make sure to change Hauk's configuration."
echo "The configuration file can be found at:"
echo -e "\033[1m$confpath\033[0m"
# Try to get the user's editor
if [ "$EDITOR" ]; then
editor="$EDITOR"
elif [ "$SUDO_USER" ]; then
editor=$(su - $SUDO_USER -c '. ~/.profile; echo $EDITOR')
fi
# If found, prompt to edit the config
if [ "$editor" ]; then
echo ""
read -p "Do you wish to open this file for editing now? [Y/n]: " edit
case "$edit" in
[Nn]*) ;;
*) "$editor" "$confpath";;
esac
fi