#!/bin/bash # # entrypoint.sh - Script to set up and run code-server in a Docker container # Copyright (C) 2025 Jesus E. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # set -e # === Set TimeZone === TZ="${TZ:-UTC}" echo "[entrypoint] Setting TimeZone to $TZ" ln -snf "/usr/share/zoneinfo/$TZ" /etc/localtime echo "$TZ" > /etc/timezone DOCKER_USER="${DOCKER_USER:-coder}" UID="${UID:-1000}" GID="${GID:-1000}" PASSWORD="${PASSWORD:-undefined}" HASHED_PASSWORD="${HASHED_PASSWORD:-undefined}" HOME_DIR="/home/coder" if ! getent group "$DOCKER_USER" > /dev/null; then groupadd -g "$GID" "$DOCKER_USER" fi if ! id "$DOCKER_USER" > /dev/null 2>&1; then useradd -u "$UID" -g "$GID" -d "$HOME_DIR" -s /bin/bash "$DOCKER_USER" usermod -aG docker "$DOCKER_USER" echo "$DOCKER_USER ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers fi echo "permit persist :$DOCKER_USER" > /etc/doas.conf echo "permit nopass :$DOCKER_USER" >> /etc/doas.conf chmod 0440 /etc/doas.conf chown root:root /etc/doas.conf mkdir -p "$HOME_DIR" chown -R "$DOCKER_USER:$DOCKER_USER" "$HOME_DIR" CONFIG_DIR="$HOME_DIR/.config/code-server" mkdir -p "$CONFIG_DIR" case "$PASSWORD:$HASHED_PASSWORD" in none:*) echo "[entrypoint] Disabling authentication" AUTH_MODE="none" YAML_AUTH_LINE="" ;; undefined:undefined|:) echo "ERROR: you must set either PASSWORD or HASHED_PASSWORD environment variable" exit 1 ;; *:undefined) echo "[entrypoint] Setting PASSWORD" AUTH_MODE="password" YAML_AUTH_LINE="password: \"$PASSWORD\"" ;; undefined:*) echo "[entrypoint] Setting HASHED_PASSWORD" AUTH_MODE="password" YAML_AUTH_LINE="hashed-password: \"$HASHED_PASSWORD\"" ;; *) echo "ERROR: Not supported combination of PASSWORD and HASHED_PASSWORD" exit 1 ;; esac cat > "$CONFIG_DIR/config.yaml" < /dev/null 2>&1 & until docker info >/dev/null 2>&1; do echo "[entrypoint] Waiting for Docker daemon to start..." sleep 2 done # === Install hyperterm === if ! stat $HOME_DIR/.hyperterm > /dev/null 2>&1; then echo "[entrypoint] Installing hyperterm..." su - "$DOCKER_USER" -c "curl -Ls https://git.fridu.us/heckyel/hyperterm/raw/branch/master/install.sh \ -o \"$HOME_DIR/install.sh\" && bash \"$HOME_DIR/install.sh\" -s && rm \"$HOME_DIR/install.sh\"" else echo "[entrypoint] Hyperterm already installed, skipping installation." fi # === Run code-server === echo "[entrypoint] Launching code-server as $DOCKER_USER" exec su - "$DOCKER_USER" -c "code-server"