forked from nanograv/nanopulsar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstart.sh
executable file
·54 lines (48 loc) · 1.83 KB
/
start.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
#!/bin/bash
# Copyright (c) Jupyter Development Team.
# Distributed under the terms of the Modified BSD License.
set -e
# Handle special flags if we're root
if [ $(id -u) == 0 ] ; then
# Handle username change. Since this is cheap, do this unconditionally
usermod -d /home/$NB_USER -l $NB_USER jovyan
# Change UID of NB_USER to NB_UID if it does not match
if [ "$NB_UID" != $(id -u $NB_USER) ] ; then
echo "Set user UID to: $NB_UID"
usermod -u $NB_UID $NB_USER
# Careful: $HOME might resolve to /root depending on how the
# container is started. Use the $NB_USER home path explicitly.
for d in "$CONDA_DIR" "$JULIA_PKGDIR" "/home/$NB_USER"; do
if [[ ! -z "$d" && -d "$d" ]]; then
echo "Set ownership to uid $NB_UID: $d"
chown -R $NB_UID "$d"
fi
done
fi
# Change GID of NB_USER to NB_GID if NB_GID is passed as a parameter
if [ "$NB_GID" ] ; then
echo "Change GID to $NB_GID"
groupmod -g $NB_GID -o $(id -g -n $NB_USER)
fi
# Enable sudo if requested
if [[ "$GRANT_SUDO" == '1' || "$GRANT_SUDO" == 'yes' ]]; then
echo "Granting $NB_USER sudo access"
echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook
fi
# Exec the command as NB_USER
echo "Execute the command as $NB_USER"
exec su $NB_USER -c "env PATH=$PATH $*"
else
if [[ ! -z "$NB_UID" && "$NB_UID" != "$(id -u)" ]]; then
echo 'Container must be run as root to set $NB_UID'
fi
if [[ ! -z "$NB_GID" && "$NB_GID" != "$(id -g)" ]]; then
echo 'Container must be run as root to set $NB_GID'
fi
if [ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]; then
echo 'Container must be run as root to grant sudo permissions'
fi
# Exec the command
echo "Execute the command"
exec $*
fi