From 8512144bb67a5ab1c8c10a1fea1b2b5d7557b7a8 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Fri, 20 Mar 2026 14:16:06 +0100 Subject: [PATCH] Harden code-server addon install script (#13116) --- tools/addon/coder-code-server.sh | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/tools/addon/coder-code-server.sh b/tools/addon/coder-code-server.sh index ac3a1d056..95039aebe 100644 --- a/tools/addon/coder-code-server.sh +++ b/tools/addon/coder-code-server.sh @@ -89,26 +89,31 @@ VERSION=$(curl -fsSL https://api.github.com/repos/coder/code-server/releases/lat awk '{print substr($2, 3, length($2)-4) }') msg_info "Installing Code-Server v${VERSION}" +config_path="${HOME}/.config/code-server/config.yaml" +preexisting_config=false -if [ -f ~/.config/code-server/config.yaml ]; then - existing_config=true +if [ -f "$config_path" ]; then + preexisting_config=true fi curl -fOL https://github.com/coder/code-server/releases/download/v"$VERSION"/code-server_"${VERSION}"_amd64.deb &>/dev/null dpkg -i code-server_"${VERSION}"_amd64.deb &>/dev/null rm -rf code-server_"${VERSION}"_amd64.deb -mkdir -p ~/.config/code-server/ -systemctl enable -q --now code-server@"$USER" +mkdir -p "${HOME}/.config/code-server/" -if [ $existing_config = false ]; then -cat <~/.config/code-server/config.yaml +if [ "$preexisting_config" = false ]; then +cat <"$config_path" bind-addr: 0.0.0.0:8680 auth: none password: cert: false EOF fi +systemctl enable -q --now code-server@"$USER" systemctl restart code-server@"$USER" +if ! systemctl is-active --quiet code-server@"$USER"; then + error_exit "code-server service failed to start." +fi msg_ok "Installed Code-Server v${VERSION} on $hostname" echo -e "${APP} should be reachable by going to the following URL.