dockerfiles/nasp-ubuntu/startup.sh

29 lines
823 B
Bash
Raw Normal View History

2024-05-30 15:11:11 +08:00
#!/usr/bin/env bash
2023-04-29 18:45:26 +08:00
set -e
2024-05-30 15:11:11 +08:00
error() {
echo $@
return 1
}
2023-04-29 18:45:26 +08:00
/etc/init.d/ssh start || echo "Failed to start sshd. Maybe the port is already in use, and please check your sshd_config. This is not an error if it's the first time you run this container."
2024-05-30 15:11:11 +08:00
if [[ ! -e /root/.config/code-server/config.yaml ]]; then
mkdir -p /root/.config/code-server
sockname=$(openssl rand -hex 12)
test "${#sockname}" = "24" || error "invalid sock name: ${sockname}"
password=$(openssl rand -base64 15)
test -n "$password" || error "invalid password: ${password}"
cat << EOF > /root/.config/code-server/config.yaml
socket: /home2/run/$sockname.sock
socket-mode: 777
auth: password
password: $password
cert: false
EOF
fi
if [[ -d /home2/run && -x $(command -v code-server) ]]; then
code-server
else
bash
fi