forked from badsyntax/dokku-discourse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions
executable file
·99 lines (87 loc) · 3.49 KB
/
functions
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
#!/usr/bin/env bash
source "$PLUGIN_AVAILABLE_PATH/discourse/config"
source "$PLUGIN_AVAILABLE_PATH/discourse/internal-functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/ps/functions"
discourse_create_app() {
declare APP_NAME="$1" \
HOSTNAME="$2" \
DEVELOPER_EMAILS="$3" \
SMTP_ADDRESS="$4" \
SMTP_PORT="$5" \
SMTP_USERNAME="$6" \
SMTP_PASSWORD="$7"
## TODO: call plugin functions instead of dokku
if grep -qxF "$(dokku apps:list 2> /dev/null)" <<< "$APP_NAME"; then
dokku_log_warn "dokku app '$APP_NAME' already exists and will be used for this discourse instance"
else
plugn trigger app-create "$APP_NAME"
echo "$APP_NAME" >> "$DISCOURSE_APPS"
fi
fn-create-default-discourse-container-config "$APP_NAME"
[[ -z "$APP_NAME" ]] && dokku_log_fail "Missing app argument"
[[ -z "$HOSTNAME" ]] && HOSTNAME=$(fn-get-input "Hostname for your Discourse?" "$(fn-get-env-config DISCOURSE_HOSTNAME)")
[[ -z "$DEVELOPER_EMAILS" ]] && DEVELOPER_EMAILS=$(fn-get-input "Email address for admin account(s)?" "$(fn-get-env-config DISCOURSE_DEVELOPER_EMAILS)")
[[ -z "$SMTP_ADDRESS" ]] && SMTP_ADDRESS=$(fn-get-input "SMTP server address?" "$(fn-get-env-config DISCOURSE_SMTP_ADDRESS)")
[[ -z "$SMTP_PORT" ]] && SMTP_PORT=$(fn-get-input "SMTP port?" "$(fn-get-env-config DISCOURSE_SMTP_PORT)")
[[ -z "$SMTP_USERNAME" ]] && SMTP_USERNAME=$(fn-get-input "SMTP user name?" "$(fn-get-env-config DISCOURSE_SMTP_USER_NAME)")
[[ -z "$SMTP_PASSWORD" ]] && SMTP_PASSWORD=$(fn-get-input "SMTP password?" "$(fn-get-env-config DISCOURSE_SMTP_PASSWORD)")
local APP_STORAGE_ROOT="$STORAGE_ROOT/$APP_NAME"
fn-update-discourse-container-config "$APP_NAME" \
"$APP_STORAGE_ROOT" \
"$HOSTNAME" \
"$DEVELOPER_EMAILS" \
"$SMTP_ADDRESS" \
"$SMTP_PORT" \
"$SMTP_USERNAME" \
"$SMTP_PASSWORD"
fn-update-discourse-build-files
fn-build-image "$APP_NAME"
fn-configure-app "$APP_NAME" "$HOSTNAME" "$APP_STORAGE_ROOT"
fn-deploy-app "$APP_NAME"
dokku_log_info1 "Data stored in $APP_STORAGE_ROOT"
dokku_log_info2 "Discourse app '$APP_NAME' created"
}
discourse_destroy_apps() {
[[ -z "$1" ]] && dokku_log_fail "Missing app argument"
for APP_NAME in "$@"
do
[[ "$APP_NAME" == "--force" ]] && continue
fn-destroy-app "$APP_NAME"
local APP_STORAGE_ROOT="$STORAGE_ROOT/$APP_NAME"
dokku_log_warn "Leaving data directory unchanged at $APP_STORAGE_ROOT"
dokku_log_info2 "Discourse app '$APP_NAME' destroyed"
done
}
discourse_list() {
local QUIET=""
while getopts "q" flag; do
case "${flag}" in
q) QUIET="true" ;;
*) ;;
esac
done
if [[ ! -f "$DISCOURSE_APPS" ]]; then
[[ -z "$QUIET" ]] && dokku_log_warn "No discourse apps have been created"
else
[[ -z "$QUIET" ]] && dokku_log_info2 "Discourse apps"
cat "$DISCOURSE_APPS" 2> /dev/null
fi
}
discourse_install_plugin() {
declare APP_NAME="$1" PLUGIN_GIT_URL="$2";
[[ -z "$APP_NAME" ]] && dokku_log_fail "Missing app argument"
[[ -z "$PLUGIN_GIT_URL" ]] && dokku_log_fail "Missing git_url argument"
plugn trigger app-exists "$APP_NAME"
fn-install-plugin "$APP_NAME" "$PLUGIN_GIT_URL"
fn-deploy-app "$APP_NAME"
dokku_log_info2 "Plugin '$PLUGIN_GIT_URL' installed"
}
discourse_upgrade_app() {
declare APP_NAME="$1"
[[ -z "$APP_NAME" ]] && dokku_log_fail "Missing app argument"
plugn trigger app-exists "$APP_NAME"
fn-upgrade-app "$APP_NAME"
fn-deploy-app "$APP_NAME"
dokku_log_info2 "Discourse app '$APP_NAME' upgraded"
}