-
Notifications
You must be signed in to change notification settings - Fork 2
/
init.sh
executable file
·58 lines (48 loc) · 1.6 KB
/
init.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
#!/bin/bash
# To avoid running uwsgi as root, create new user, then run start.sh as this user.
#
# Reason: OpenGenomeBrowser writes files to the folder structure. If uwsgi is root,
# all files will belong to root.
re='^[0-9]+$'
if ! [[ $USER_ID =~ $re ]]; then
echo "Error: Environment variable USER_ID is ill-defined!" >&2
exit 1
fi
if ! [[ $GROUP_ID =~ $re ]]; then
echo "Error: Environment variable GROUP_ID is ill-defined!" >&2
exit 1
fi
if [ "$DEBUG" = "true" ] || [ "$DEBUG" = "false" ]; then
echo "DEBUG is $DEBUG"
else
echo "Error: Environment variable DEBUG is ill-defined!" >&2
exit 1
fi
if id user &>/dev/null; then
echo 'USER ALREADY EXISTS'
else
echo 'CREATE USER'
# create new user in container
addgroup --gid $GROUP_ID user
adduser --disabled-password --gecos '' --uid $USER_ID --gid $GROUP_ID user
# give user ownership of relevant locations inside container
sudo chown -R user:user /root
sudo chown -R user:user /tmp
sudo chown -R user:user /opt
sudo chown -R user:user /opengenomebrowser/cache/
sudo chown -R user:user /opengenomebrowser/static_root/
# in production mode give user ownership of code and socker
if [ "$DEBUG" = "false" ]; then
sudo chown -R user:user /socket
sudo chown -R user:user /opengenomebrowser
fi
# add user to sudoers
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >>/etc/sudoers
fi
# generate secret key if none exists
if [ -z ${DJANGO_SECRET_KEY+x} ]; then
echo "GENERATE DJANGO_SECRET_KEY"
export DJANGO_SECRET_KEY="$(date | sha256sum | base64 | head -c 60)"
fi
# start django
sudo -u user --preserve-env bash -c "cd '$PWD'; ./start.sh"