-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandbox
executable file
·41 lines (37 loc) · 856 Bytes
/
sandbox
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
#!/bin/bash
basename="$1"
shift
sandbox="$1"
shift
container="${basename}-${sandbox}"
commandline="$@"
fullcommand=(
sudo -HnSu $sandbox \
-i DISPLAY=$DISPLAY \
-- $commandline
)
set -m
info(){
printf "Container:\t $container\n"
printf "Display:\t $DISPLAY\n"
printf "Running:\t ${fullcommand[@]}"
}
containerrun(){
printf "\nStarting container '$container'\n"
sudo lxc-start -n $container
if sudo lxc-wait --name=$container --state=RUNNING; then
printf "'$container' entered state 'RUNNING', running '$commandline'\n"
sudo lxc-attach -n $container -- "${fullcommand[@]}"
containerrc=$?
printf "'$commandline' exited with return code '$containerrc'\n"
else
printf "Failed to start '$container'\n"
exit 1
fi
sudo lxc-wait --name=$container --state=STOPPED
}
main(){
info
containerrun
}
main