@@ -1,46 +1,60 @@
3SSH_USER="__SSH_USER__"
4SSH_USER="__SSH_USER__"
4−SUDO_PASSWORD="__SUDO_PASSWORD__"
5PROJECT_NAME="__PROJECT_NAME__"
5PROJECT_NAME="__PROJECT_NAME__"
6KEY_PATH="__KEY_PATH__"
6KEY_PATH="__KEY_PATH__"
8−if [ -d /root/${PROJECT_NAME}/.vibebox ]; then
8+# 1) tmpfs mount
9+TARGET="/root/${PROJECT_NAME}/.vibebox"
10+if [ -d "$TARGET" ] && ! mountpoint -q "$TARGET"; then
9− mount -t tmpfs tmpfs /root/${PROJECT_NAME}/.vibebox
11+ mount -t tmpfs tmpfs "$TARGET"
12−if ! command -v sshd >/dev/null 2>&1; then
15+if ! id -u "$SSH_USER" >/dev/null 2>&1; then
13− apt-get update && apt-get install -y openssh-server sudo
16+ useradd -m -s /bin/bash -U "$SSH_USER"
17+ usermod -aG sudo "$SSH_USER" || true
16−systemctl enable ssh >/dev/null 2>&1 || true
17−id -u ${SSH_USER} >/dev/null 2>&1 || useradd -m -s /bin/bash ${SSH_USER}
18−echo "${SSH_USER}:${SUDO_PASSWORD}" | chpasswd
19−usermod -aG sudo ${SSH_USER}
20−install -d -m 700 /home/${SSH_USER}/.ssh
20+install -d -m 700 -o "$SSH_USER" -g "$SSH_USER" "/home/${SSH_USER}/.ssh"
21−install -m 600 ${KEY_PATH} /home/${SSH_USER}/.ssh/authorized_keys
21+install -m 600 -o "$SSH_USER" -g "$SSH_USER" "$KEY_PATH" "/home/${SSH_USER}/.ssh/authorized_keys"
22−chown -R ${SSH_USER}:${SSH_USER} /home/${SSH_USER}/.ssh
22+
23−rm -f /home/${SSH_USER}/.bash_logout
23+# 3)
24−mkdir -p /etc/ssh/sshd_config.d
24+systemctl start ssh >/dev/null 2>&1 || true
25−cat >/etc/ssh/sshd_config.d/vibebox.conf <<'VIBEBOX_SSHD'
25+
26−PasswordAuthentication no
26+# 4)
27−KbdInteractiveAuthentication no
27+i=0
28−ChallengeResponseAuthentication no
28+while :; do
29−PubkeyAuthentication yes
29+ if ss -lnt 2>/dev/null | awk '{print $4}' | grep -qE '(:22)$'; then
30−PermitRootLogin no
30+ break
31−AllowUsers __SSH_USER__
31+ fi
32−VIBEBOX_SSHD
32+ i=$((i+1))
33−systemctl restart ssh
33+ [ "$i" -ge 40 ] && break # ~4s
34echo VIBEBOX_SSH_READY
37echo VIBEBOX_SSH_READY
36−echo "=== generated network file ==="
39+find_ip() {
37−sed -n '1,200p' /run/systemd/network/10-netplan-all-en.network || true
40+ if command -v ip >/dev/null 2>&1; then
41+ ip -4 -o addr show scope global 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | head -n 1
44+ if command -v hostname >/dev/null 2>&1; then
45+ hostname -I 2>/dev/null | awk '{print $1}'
39−while true; do
51+while :; do
40− ip=$(ip -4 -o addr show scope global | awk '{print $4}' | cut -d/ -f1 | head -n 1)
52+ ip="$(find_ip || true)"
41 if [ -n "$ip" ]; then
53 if [ -n "$ip" ]; then
42 echo VIBEBOX_IPV4=$ip
54 echo VIBEBOX_IPV4=$ip
58+ [ "$i" -ge 60 ] && break