forked from dokku-alt/dokku-alt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands
More file actions
executable file
·154 lines (127 loc) · 3.58 KB
/
commands
File metadata and controls
executable file
·154 lines (127 loc) · 3.58 KB
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
#!/usr/bin/env bash
set -eo pipefail; [[ $DOKKU_TRACE ]] && set -x
# Check if name is specified
if [[ $1 == config ]] || [[ $1 == config:* ]]; then
if [[ -z $2 ]]; then
echo "You must specify an app name"
exit 1
else
APP="$2"
ENV_FILE="$DOKKU_ROOT/$APP/ENV"
ENV_FILE_TEMP="$DOKKU_ROOT/$APP/ENV.tmp"
# Check if app exists with the same name
if [ ! -d "$DOKKU_ROOT/$APP" ]; then
echo "App $APP does not exist"
exit 1
fi
[ -f $ENV_FILE ] || {
# echo "-----> Creating $ENV_FILE"
touch $ENV_FILE
}
fi
fi
config_styled_hash () {
sed 's/^\([^=]*\)=/\1:|/g' | column -t -s '|'
}
config_shell_hash() {
while read var
do
KEY=`echo "$var" | cut -d"=" -f1`
VALUE=`echo "$var" | cut -d"=" -f2-`
echo "export $(printf "%q" "$KEY")=$(printf "%q" "$VALUE")"
done
}
config_write() {
ENV_TEMP="$1"
echo -e "$ENV_TEMP" | sed '/^$/d' | sort > "$ENV_FILE_TEMP"
if ! cmp -s "$ENV_FILE" "$ENV_FILE_TEMP"; then
cp -f "$ENV_FILE_TEMP" "$ENV_FILE"
dokku rebuild "$APP"
fi
rm -f "$ENV_FILE_TEMP"
}
case "$1" in
config)
APP="$2"
for var in "$@"; do
if [[ "$var" == "--shell" ]]; then
: | pluginhook env-vars "$APP" | config_shell_hash
exit 0
fi
done
echo "=== $APP config vars ==="
: | pluginhook env-vars "$APP" | config_styled_hash
;;
config:get)
if [[ -z $3 ]]; then
echo "Usage: dokku config:get APP KEY"
echo "Must specify KEY."
exit 1
fi
KEY="$3"
: | pluginhook env-vars "$APP" | grep "^$KEY=" | cut -d"=" -f2-
;;
config:set)
if [[ -z "${*:3}" ]]; then
echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]"
echo "Must specify KEY and VALUE to set."
exit 1
fi
APP="$2"; APP_DIR="$DOKKU_ROOT/$APP"
ENV_ADD=""
ENV_TEMP=`cat "${ENV_FILE}"`
RESTART_APP=false
shift 2
for var in "$@"; do
if [[ "$var" != *"="* ]]; then
echo "Usage: dokku config:set APP KEY1=VALUE1 [KEY2=VALUE2 ...]"
echo "Must specify KEY and VALUE to set."
exit 1
fi
done
for var in "$@"; do
KEY=`echo "$var" | cut -d"=" -f1`
VALUE=`echo "$var" | cut -d"=" -f2-`
if [[ $KEY =~ [a-zA-Z_][a-zA-Z0-9_]* ]]; then
RESTART_APP=true
ENV_TEMP=$(echo -e "${ENV_TEMP}" | sed "/^export $KEY=/ d")
ENV_TEMP="${ENV_TEMP}\nexport $KEY=$VALUE"
ENV_ADD=$(echo -e "${ENV_ADD}" | sed "/^$KEY=/ d")
ENV_ADD="${ENV_ADD}\n${KEY}=${VALUE}"
fi
done
if [[ $RESTART_APP ]]; then
echo "-----> Setting config vars and restarting $APP"
echo -e "$ENV_ADD" | config_styled_hash
config_write "$ENV_TEMP"
fi
;;
config:unset)
if [[ -z "$3" ]]; then
echo "Usage: dokku config:unset APP KEY1 [KEY2 ...]"
echo "Must specify KEY to unset."
exit 1
fi
APP="$2"; APP_DIR="$DOKKU_ROOT/$APP"
ENV_TEMP=`cat "${ENV_FILE}"`
RESTART_APP=false
shift 2
for var in "$@"; do
echo "-----> Unsetting $var and restarting $APP"
ENV_TEMP=$(echo -e "${ENV_TEMP}" | sed "/^export $var=/ d")
RESTART_APP=true
done
config_write "$ENV_TEMP"
;;
help|config:help)
cat && cat<<EOF
config <app> Display the config vars for an app
config:get <app> KEY Display a config value for an app
config:set <app> KEY1=VALUE1 [KEY2=VALUE2 ...] Set one or more config vars
config:unset <app> KEY1 [KEY2 ...] Unset one or more config vars
EOF
;;
*)
exit $DOKKU_NOT_IMPLEMENTED_EXIT
;;
esac