-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcrumpet
More file actions
executable file
·122 lines (101 loc) · 2.85 KB
/
Copy pathcrumpet
File metadata and controls
executable file
·122 lines (101 loc) · 2.85 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/bin/bash
ROOTFS=/rootfs
TARBALL_URL=https://dl.sh1mmer.me/crumpet/rootfs.tar.gz # it's only on this host because it's the fastest DDL server i have access to
TTY=9
SELF=$(realpath "$0")
DIR=$(dirname "$SELF")
inside(){
chroot "$ROOTFS" /usr/bin/env LD_LIBRARY_PATH=/opt/google/chrome:/usr/local/lib64 PATH=/usr/local/bin/:/usr/local/sbin/:/usr/bin/:/usr/sbin/:/bin/:/sbin/ "$@"
}
inside_chronos(){
chroot "$ROOTFS" sudo -u chronos LD_LIBRARY_PATH=/opt/google/chrome:/usr/local/lib64 PATH=/usr/local/bin/:/usr/local/sbin/:/usr/bin/:/usr/sbin/:/bin/:/sbin/ bash -c "$*"
}
mnt(){
mkdir -p "$ROOTFS/sys" "$ROOTFS/proc" "$ROOTFS/dev" "$ROOTFS/tmp" "$ROOTFS/run"
mount --bind /sys "$ROOTFS/sys"
mount --bind /proc "$ROOTFS/proc"
mount --bind /dev "$ROOTFS/dev"
mount --bind /run "$ROOTFS/run"
mount --bind /tmp "$ROOTFS/tmp"
inside chmod 1777 /dev/shm
}
unmnt(){
umount "$ROOTFS/"*
}
xserver(){
OTTY=$(fgconsole)
if [[ "$(tty)" == *"/dev/tty"* ]]; then
clear
echo starting x
startx "$SELF" xserver_poststart $OTTY
else
openvt -c$TTY -- "$SELF" xserver
fi
}
stop(){
kill $(</tmp/crumpet-pid)
kill $(</tmp/crumpet-ash-pid)
pkill -f chrome_silly
}
startui(){
if ! isactive; then
echo "X Server inactive. Run 'crumpet activate' to activate the chroot"
return
fi
. /tmp/crumpet-x
inside_chronos rm '~/.Xauthority'
inside_chronos touch '~/.Xauthority'
while read cookie; do
inside_chronos xauth -f '~/.Xauthority' add $cookie
done <<< "$(xauth list)"
cp "$DIR/scripts/kiosk.sh" "$ROOTFS/opt/google/chrome"
cp "$DIR/scripts/launch.sh" "$ROOTFS/opt/google/chrome"
chvt "$TTY"
echo $$ > /tmp/crumpet-ash-pid
export DISPLAY
inside_chronos /opt/google/chrome/launch.sh
}
xserver_poststart(){
echo "DISPLAY=$DISPLAY">/tmp/crumpet-x
echo $$ > /tmp/crumpet-pid
xhost +
chvt "$1"
tail -f /dev/null
}
isactive(){
[ -f /tmp/crumpet-pid ] && [ -d "/proc/$(</tmp/crumpet-pid)/" ]
}
activate(){
mnt
if ! isactive; then
xserver
echo "X server started! Launch ash with 'crumpet startui', outside of the chroot "
fi
}
enter-chroot(){
mnt
if ! isactive; then
echo "X Server inactive. Run 'crumpet activate' to activate the chroot"
fi
inside_chronos bash
}
help(){
cat <<-EOF
Usage: sudo ./crumpet [command]
activate - activates the environment. usually you want to run this before you run some of the other commands
startui - launches and switches to the chromiumos UI
enter-chroot - gives you a shell inside the chroot
inside - runs a single command inside the chroot (as root)
inside_chronos - runs a single command inside the chroot (as chronos)
help - prints this screen
EOF
}
install(){
mkdir "$ROOTFS"
curl -SL "$TARBALL_URL" | tar -xvzf - -C "/"
mkdir -p "$ROOTFS/home/chronos/user"
chown -R 1000:1000 "$ROOTFS/home/chronos"
echo "installed!"
}
test -z "$@" && help
$@ || help