-
Notifications
You must be signed in to change notification settings - Fork 14
/
moin.sh
executable file
·101 lines (92 loc) · 3.2 KB
/
moin.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
#!/usr/bin/env bash
#===============================================================================
# FILE: moin.sh
#
# USAGE: ./moin.sh
#
# DESCRIPTION: Entrypoint for moinmoin docker container
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: David Personette (dperson@gmail.com),
# ORGANIZATION:
# CREATED: 2014-10-16 02:56
# REVISION: 1.0
#===============================================================================
set -o nounset # Treat unset variables as an error
### prefix: Configure expected URI location for service
# Arguments:
# prefix) URI
# Return: setup URI
prefix() { local prefix="$1" file=/usr/local/share/moin/wikiconfig.py
if [[ $prefix == "/" ]]; then
sed -i '/^url_prefix_static = /s|^|#|' $file
else
sed -i 's|.*\(url_prefix_static = \)|'"'$prefix'"'|' $file
fi
}
### super: Configure admin user for wiki
# Arguments:
# super) admin ID
# Return: setup admin ID
super() { local super="$1" file=/usr/local/share/moin/wikiconfig.py
sed -i '/superuser/s|".*"|"'"$super"'"|' $file
}
### usage: Help
# Arguments:
# none)
# Return: Help text
usage() { local RC="${1:-0}"
echo "Usage: ${0##*/} [-opt] [command]
Options (fields in '[]' are optional, '<>' are required):
-h This help
-p \"</prefix>\" Configure URI prefix for wiki, if you want other than
/wiki required arg: \"</prefix>\" - URI location
-s \"<super>\" Configure superuser (admin ID) for the wiki
required arg: \"<UserName>\" - The user to manage the wiki
The 'command' (if provided and valid) will be run instead of moinmoin
" >&2
exit $RC
}
while getopts ":hp:s:" opt; do
case "$opt" in
h) usage ;;
p) prefix "$OPTARG" ;;
s) super "$OPTARG" ;;
"?") echo "Unknown option: -$OPTARG"; usage 1 ;;
":") echo "No argument value for option: -$OPTARG"; usage 2 ;;
esac
done
shift $(( OPTIND - 1 ))
[[ "${PREFIX:-""}" ]] && prefix "$PREFIX"
[[ "${SUPER:-""}" ]] && super "$SUPER"
[[ "${USERID:-""}" =~ ^[0-9]+$ ]] && usermod -u $USERID -o uwsgi
[[ "${GROUPID:-""}" =~ ^[0-9]+$ ]] && groupmod -g $GROUPID -o uwsgi
chown -Rh uwsgi. /usr/local/share/moin/data /usr/local/share/moin/underlay 2>&1|
grep -iv 'Read-only' || :
if [[ $# -ge 1 && -x $(which $1 2>&-) ]]; then
exec "$@"
elif [[ $# -ge 1 ]]; then
echo "ERROR: command not found: $1"
exit 13
elif ps -ef | egrep -v grep | grep -q uwsgi; then
echo "Service already running, please restart container to apply changes"
else
[[ "${LANG:-""}" ]] || export LANG=en_US.UTF-8
exec uwsgi --uid uwsgi \
-s /tmp/uwsgi.sock \
--uwsgi-socket 0.0.0.0:3031 \
--plugins python \
--pidfile /tmp/uwsgi-moinmoin.pid \
--chdir /usr/local/share/moin \
--python-path /usr/local/lib/python2.7/site-packages \
--python-path /usr/local/share/moin \
--wsgi-file server/moin.wsgi \
--master \
--processes 4 \
--harakiri 30 \
--die-on-term \
--thunder-lock
fi