-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·229 lines (205 loc) · 4.79 KB
/
configure
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env zsh
#
# configure
# Generate a config file
#
SCRIPT_NAME="flyingpaste/configure"
SCRIPT_VERSION="0.20220905"
#
# Default values
#
FLYINGPASTE_INI="${FLYINGPASTE_INI:-flyingpaste.ini}"
CONFIG_OWNDIR=$(realpath $(dirname $0))
CONFIG_SERVICE_URL="http://nopaste.$(hostname -d)"
CONFIG_SERVICE_NAME="Flying Paste"
CONFIG_MYSQL_HOST="localhost"
CONFIG_MYSQL_USER="flyingpaste"
CONFIG_MYSQL_PASSWORD=""
CONFIG_MYSQL_DB="flyingpaste"
#
# Functions
#
_ANSI_ESCAPE=$(printf "\e")
_ANSI_RESET="${_ANSI_ESCAPE}[0m"
_ANSI_ATTR_BOLD="${_ANSI_ESCAPE}[1m"
_ANSI_ATTR_ITALIC="${_ANSI_ESCAPE}[3m"
_ANSI_ATTR_UNDERLINE="${_ANSI_ESCAPE}4m"
_ANSI_COLOR_BLACK="${_ANSI_ESCAPE}[0;30m"
_ANSI_COLOR_RED="${_ANSI_ESCAPE}[0;31m"
_ANSI_COLOR_GREEN="${_ANSI_ESCAPE}[0;32m"
_ANSI_COLOR_YELLOW="${_ANSI_ESCAPE}[0;33m"
_ANSI_COLOR_BLUE="${_ANSI_ESCAPE}[0;34m"
_ANSI_COLOR_DARK_MAGENTA="${_ANSI_ESCAPE}[0;35m"
_ANSI_COLOR_DARK_CYAN="${_ANSI_ESCAPE}[0;36m"
_ANSI_COLOR_GREY="${_ANSI_ESCAPE}[0;37m"
_ANSI_COLOR_DARK_GREY="${_ANSI_ESCAPE}[1;30m"
_ANSI_COLOR_LIGHT_RED="${_ANSI_ESCAPE}[1;31m"
_ANSI_COLOR_LIGHT_GREEN="${_ANSI_ESCAPE}[1;32m"
_ANSI_COLOR_LIGHT_YELLOW="${_ANSI_ESCAPE}[1;33m"
_ANSI_COLOR_LIGHT_BLUE="${_ANSI_ESCAPE}[1;34m"
_ANSI_COLOR_MAGENTA="${_ANSI_ESCAPE}[1;35m"
_ANSI_COLOR_CYAN="${_ANSI_ESCAPE}[1;36m"
_ANSI_COLOR_WHITE="${_ANSI_ESCAPE}[1;37m"
_print() {
printf "$@"
}
_println() {
printf "$@"
echo
}
_print_term() {
if [[ $TERM != "dump" ]]; then
_print $@
fi
}
_println_term() {
if [[ $TERM != "dump" ]]; then
_println $@
fi
}
message() {
_print_term $_ANSI_COLOR_GREEN
_print "[${SCRIPT_NAME}] "
_print_term $_ANSI_RESET
_println $@
}
message_error() {
(
_print_term $_ANSI_COLOR_RED
_print "[${SCRIPT_NAME}] Error: "
_print_term $_ANSI_RESET
_println $@
) >&2
}
message_debug() {
(
_print_term $_ANSI_COLOR_YELLOW
_print "[${SCRIPT_NAME}] [DEBUG] "
_print_term $_ANSI_RESET
_println $@
) >&2
}
message_ask() {
_print_term $_ANSI_COLOR_GREEN
_print "[${SCRIPT_NAME}] "
_print_term $_ANSI_RESET
_print $1
_print ' ['
_print_term $_ANSI_ATTR_ITALIC
if [[ -n $2 ]]; then
_print $2
else
_print "(empty)"
fi
_print_term $_ANSI_RESET
_print ']? '
}
version() {
echo "$SCRIPT_NAME $SCRIPT_VERSION"
}
# OS detection
OS=`uname -s`
OSVERSION=`uname -r`
if [[ "$OS" == "Darwin" ]]; then
OS="Mac OS X"
OSVARIANT=$OS
OSXVersion=`python3 -c 'import platform;print(platform.mac_ver()[0],end="")'`
OSVERSION=$OSXVersion
else
OS=`uname -o`
if which lsb_release &>/dev/null; then
OSVARIANT=`lsb_release -s -i`
else
OSVARIANT=$OS
fi
OSVERSION=`uname -r`
fi
if [[ "$1" == "--version" || "$1" == "-V" ]]; then
version
exit 0
fi
usage() {
echo "Usage:"
echo " ${SCRIPT_NAME%%*/}"
echo " $SCRIPT_NAME [--version|--help]"
echo
echo "Options:"
echo " --version -V Show the version and exit"
echo " --help -h Show this help and exit"
echo
}
##########################################
# Ask the user for input
#
message "Welcome to Flying Paste ./configure"
#message_debug ""
message_ask "Output path" "$FLYINGPASTE_INI"
read _input
if [[ -n $_input ]]; then
FLYINGPASTE_INI="$_input"
fi
message_ask "Application path" "$CONFIG_OWNDIR"
read _input
if [[ -n $_input ]]; then
CONFIG_OWNDIR="$_input"
fi
message_ask "Service URL" "$CONFIG_SERVICE_URL"
read _input
if [[ -n $_input ]]; then
CONFIG_SERVICE_URL="$_input"
fi
message_ask "Service Name" "$CONFIG_SERVICE_NAME"
read _input
if [[ -n $_input ]]; then
CONFIG_SERVICE_NAME="$_input"
fi
message_ask "MySQL/MariaDB host" "$CONFIG_MYSQL_HOST"
read _input
if [[ -n $_input ]]; then
CONFIG_MYSQL_HOST="$_input"
fi
message_ask "MySQL/MariaDB user" "$CONFIG_MYSQL_USER"
read _input
if [[ -n $_input ]]; then
CONFIG_MYSQL_USER="$_input"
fi
message_ask "MySQL/MariaDB password" "$CONFIG_MYSQL_PASSWORD"
read _input
CONFIG_MYSQL_PASSWORD="$_input"
message_ask "MySQL/MariaDB database" "$CONFIG_MYSQL_DB"
read _input
if [[ -n $_input ]]; then
CONFIG_MYSQL_DB="$_input"
fi
##########################################
# Generate and save config
#
cat <<EOF >$FLYINGPASTE_INI
;
; Flying Paste Configuration
; → Generated using ./configure
;
;
; Generic/instace config
;
[APP]
; Where is flying paste installed (i.e. where are the templates etc.)
OWNDIR = $CONFIG_OWNDIR
; Where will the paste service be available to the public?
SERVICE_URL = $CONFIG_SERVICE_URL
; Name of the paste service (used in document titles)
SERVICE_NAME = $CONFIG_SERVICE_NAME
; Wether started for testing or productive use. WSGI is used if True.
PRODUCTIVE = False
;
; Database (only MySQL supported at the moment)
;
[DATABASE]
TYPE = MySQL
MYSQL_HOST = $CONFIG_MYSQL_HOST
MYSQL_USER = $CONFIG_MYSQL_USER
MYSQL_PASSWORD = $CONFIG_MYSQL_PASSWORD
MYSQL_DB = $CONFIG_MYSQL_DB
EOF
message_debug "Stored config in \"${FLYINGPASTE_INI}\""
# The end :-)