-
Notifications
You must be signed in to change notification settings - Fork 1
/
subl-wrapper
47 lines (44 loc) · 1.15 KB
/
subl-wrapper
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
#!/bin/bash -e
if [ ! -O / ]
then
/usr/bin/subl "$@"
exit $?
fi
if [ -z "$HOME" ]
then
export HOME=/workspace
fi
if [ -z "$DISPLAY" -o ! -d "$HOME" ]
then
echo 'Usage: sudo docker run -ti --net=host --rm -e DISPLAY -v $HOME/workspace/:/workspace/:z docbill/subl' 2>&1
echo '-or-: sudo docker run -ti --net=host --rm -e DISPLAY -e HOME -v "$HOME/:$HOME/:z" docbill/subl' 2>&1
exit 1
fi
cd "$HOME"
values=( $(stat -c '%g %u %U %G' "$HOME") )
XGID=${values[0]}
XUID=${values[1]}
XUSER=${values[2]}
XGROUP=${values[3]}
if [ "$XGROUP" = "UNKNOWN" ]
then
XGROUP=g$XGID
if ! ( groupadd -f -g $XGID "$XGROUP" 2>>/dev/null )
then
XGROUP="#$XGID"
fi
fi
if [ "$XUSER" = "UNKNOWN" ]
then
XUSER=u$XUID-$XGID
if ! ( useradd -u $XUID -g "$XGROUP" -d "$HOME" "$XUSER" 2>>/dev/null || usermod -u $XUID -g "$XGROUP" "$XUSER" 2>>/dev/null )
then
XUSER="#$XUID"
fi
fi
# Hook to allow pre-installed software
if [ -d /opt/sublime_text/config -a ! -d ".config/sublime-text-3" ]
then
sudo -u u$XUID-$XGID bash -c '([ -d .config ] || mkdir -p .config) && cp -ur /opt/sublime_text/config/. .config/.'
fi
exec sudo -u "$XUSER" -g "$XGROUP" /usr/bin/subl "$@"