-
Notifications
You must be signed in to change notification settings - Fork 7
/
Rserv.sh
executable file
·81 lines (70 loc) · 1.51 KB
/
Rserv.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
#!/bin/bash
# Copying: This code is in the public domain
ldata=8000000
ltime=300
lfile=20000
shell=no
usage()
{ echo "Usage: docker run [docker options] rserve [rserve options]"
echo "rserve options:"
echo
echo " --bash Run bash"
echo " --limit-data Limit data (K-bytes, default 4000000)"
echo " --limit-time Limit time (Seconds, default 300)"
echo " --limit-file Limit file size (K-bytes, default 20000)"
}
while [ ! -z "$1" ]; do
case "$1" in
--bash) shell=yes
shift
;;
--limit-data=*) ldata="$(echo $1 | sed 's/[^=]*=//')"
shift
;;
--limit-time=*) ltime="$(echo $1 | sed 's/[^=]*=//')"
shift
;;
--limit-file=*) lfile="$(echo $1 | sed 's/[^=]*=//')"
shift
;;
--help) usage
exit 0
;;
*) usage
exit 1
esac
done
# Set some hard limits
ulimit -d $ldata
ulimit -t $ltime
ulimit -f $lfile
ulimit -a
mkuser()
{ f="$1"
u="$2"
groupadd "$(ls -nd "$f" | awk '{printf "-g %s\n",$4 }')" -o $u
useradd "$(ls -nd "$f" | awk '{printf "-u %s\n",$3 }')" -g $u -o $u
}
setuser()
{ f="$1"
ls -nd "$f" | awk '{printf "uid %s\ngid %s\n",$3,$4 }' >> Rserv.conf
}
noroot()
{ f="$1"
if [ "$(ls -nd "$f" | awk '{printf "%s",$3 }')" = 0 -o \
"$(ls -nd "$f" | awk '{printf "%s",$4 }')" = 0 ]; then
useradd -U ruser
chown ruser:ruser $f
else
mkuser $1 ruser
fi
}
noroot /rserve
setuser /rserve
chown ruser:ruser .
cat Rserv.conf
if [ $shell == yes ]; then
bash
else
exec /usr/bin/R CMD Rserve --no-save --RS-conf Rserv.conf
fi