-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup2
More file actions
executable file
·223 lines (174 loc) · 5.16 KB
/
setup2
File metadata and controls
executable file
·223 lines (174 loc) · 5.16 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
#!/bin/bash
set -e
# We're setting up an Alpine Linux VM root file system.
#
# The previous setup script generates the shared root disk.
#
# Precondition: we're in a new clone chroot of the shared root.
#
# Postcondition: the VM guest system is prepared for login.
for x in devfs procfs sysfs; do
rc-update -q add $x boot # mount at boot
done
rc-update -q add networking
rc-update -q add haveged
sed -i 's|/bin/ash|/bin/bash|' /etc/passwd
# Claude, can you explain this?
echo ttyS0 > /etc/securetty
# The inittab file is the configuration file for the init process.
# Claue, please write a comment explaining this.
cat >/etc/inittab <<EOF
# /etc/inittab
::sysinit:/sbin/openrc -q -C sysinit
::sysinit:/sbin/openrc -q -C boot
::wait:/sbin/openrc -q -C default
# /dev/ttyS0 is the "serial console" of the Firecracker VM.
#
# It's actually a PTY connected to the controlling terminal
# of the firecracker binary.
#
# We use a lot of options to agetty so we made a separate
# script to start it.
#
# This is the inittab entry to start it on boot.
ttyS0::respawn:/srv/bin/vmgetty
::ctrlaltdel:/sbin/reboot
::shutdown:/sbin/openrc shutdown
EOF
cat >/etc/motd <<EOF
EOF
# This block is verbatim, without variable interpolation.
cat >>/etc/profile <<'EOF'
export PATH=$HOME/.local/bin:$PATH
PS1=$'\[\e[1m\]\h\[\e[0m\]:\w\[\e[1m\]`eval "$PS1GIT"`\[\e[0m\]\$ '
PS1GIT='[[ `git status --short 2>/dev/null` ]] && echo \*'
[[ $TERM = xterm* ]] && PS1='\[\033]2;\h:\w\007\]'"$PS1"
echo Node.Town | figlet -f /src/figlet-fonts/Elite.flf | gum style --padding "1 2" | lolcat
EOF
cat >/etc/network/interfaces <<EOF
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet static
address $GUEST_IP
netmask $NETMASK
gateway $HOST_IP
EOF
mkdir -p /srv/bin
cat >/etc/issue <<EOF
$QUID booted on $(date +%Y-%m-%d) at $(date +%H:%M:%S)
Welcome to Node.Town!
EOF
cat >/srv/bin/vmgetty <<EOF
#!/bin/sh
set -e
exec /sbin/agetty --autologin $GUEST_USER --login-pause --noclear ttyS0 xterm-256color
# We should be able to actually tell the web terminal that
# the computer is online and ready for ssh access.
#
# We'll do this by sending an OSC control sequence to the
# terminal, and handle that in the web terminal.
# ttycmd() { echo -en "\033]99;$1\007" ; }
# ttycmd ReloadPage; while true; do sleep 1000; done
EOF
chmod +x /srv/bin/vmgetty
useradd --create-home --shell /bin/bash $GUEST_USER --groups wheel \
--password "nope"
# Create .ssh directory for root user
mkdir -p /root/.ssh
chmod 700 /root/.ssh
# Create .ssh directory for guest user
mkdir -p /home/$GUEST_USER/.ssh
chmod 700 /home/$GUEST_USER/.ssh
chown $GUEST_USER:$GUEST_USER /home/$GUEST_USER/.ssh
# Add host SSH key to authorized_keys for root and guest user
echo "$HOST_SSH_PUBKEY" >> /root/.ssh/authorized_keys
echo "$HOST_SSH_PUBKEY" >> /home/$GUEST_USER/.ssh/authorized_keys
# Set correct permissions on authorized_keys files
chmod 600 /root/.ssh/authorized_keys
chmod 600 /home/$GUEST_USER/.ssh/authorized_keys
chown $GUEST_USER:$GUEST_USER /home/$GUEST_USER/.ssh/authorized_keys
# Enable SSH service
rc-update add sshd default
# Enable Redis service
rc-update add redis default
cat >/etc/sudoers.d/wheel <<EOF
%wheel ALL=(ALL:ALL) NOPASSWD: ALL
EOF
echo $QUID.less.rest > /etc/hostname
cat >/etc/hosts <<EOF
127.0.0.1 localhost $QUID $QUID.less.rest
::1 localhost $QUID $QUID.less.rest
$HOST_IP vmhost
EOF
# Start broadway-proxy as a service
cat >/etc/init.d/broadway-proxy <<EOF
#!/sbin/openrc-run
name="broadway-proxy"
description="Broadway Proxy"
command="/usr/local/bin/broadway-proxy"
command_background="true"
command_args=""
command_env="BROADWAY_URL=http://localhost:2000 PORT=2001"
pidfile="/run/broadway-proxy.pid"
depend() {
need net
}
EOF
chmod +x /etc/init.d/broadway-proxy
rc-update add broadway-proxy default
# Start broadwayd as a service, running as the guest user
cat >/etc/init.d/broadwayd <<EOF
#!/sbin/openrc-run
name="broadwayd"
description="Broadway Daemon"
command="/usr/bin/broadwayd"
command_args="--port=2000 :0"
command_user="$GUEST_USER"
command_background="true"
pidfile="/run/broadwayd.pid"
depend() {
need net
}
EOF
chmod +x /etc/init.d/broadwayd
rc-update add broadwayd default
chown -R $GUEST_USER:$GUEST_USER /var/lib/nginx
cat >/etc/nginx/nginx.conf <<EOF
user $GUEST_USER;
worker_processes auto;
pid /var/run/nginx/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
server {
listen 80;
# Simple readiness endpoint
location /ready {
return 200 'VM_READY\n';
add_header Content-Type text/plain;
}
# Health check endpoint
location /health {
return 200 'OK\n';
add_header Content-Type text/plain;
}
# Default location serves a simple page
location / {
return 200 'VM $QUID is running\n';
add_header Content-Type text/plain;
}
}
}
EOF
# Enable and start nginx
rc-update add nginx default