From df507ca559302e2fed656de7e174125b8287d2c3 Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 23 Oct 2024 20:12:08 +0500 Subject: [PATCH] feat(kasmvnc): support images without sudo access - Allow KasmVNC to be installed and run on systems where `sudo` is not available. - Automatically adjust config file location and server start method based on `sudo` availability. - Enhance portability for broader usage across various environments. --- kasmvnc/README.md | 2 +- kasmvnc/run.sh | 65 ++++++++++++++++++++++++++--------------------- 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/kasmvnc/README.md b/kasmvnc/README.md index 3b7fe50..0639bf0 100644 --- a/kasmvnc/README.md +++ b/kasmvnc/README.md @@ -14,7 +14,7 @@ Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and ```tf module "kasmvnc" { source = "registry.coder.com/modules/kasmvnc/coder" - version = "1.0.22" + version = "1.0.23" agent_id = coder_agent.example.id desktop_environment = "xfce" } diff --git a/kasmvnc/run.sh b/kasmvnc/run.sh index b831537..423b136 100644 --- a/kasmvnc/run.sh +++ b/kasmvnc/run.sh @@ -75,35 +75,35 @@ install_alpine() { rm /tmp/kasmvncserver.tgz } -# Detect system information -distro=$(grep "^ID=" /etc/os-release | awk -F= '{print $2}') -version=$(grep "^VERSION_ID=" /etc/os-release | awk -F= '{print $2}' | tr -d '"') -arch=$(uname -m) - -echo "Detected Distribution: $distro" -echo "Detected Version: $version" -echo "Detected Architecture: $arch" - -# Map arch to package arch -if [[ "$arch" == "x86_64" ]]; then - if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then - arch="amd64" - else - arch="x86_64" - fi -elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then - if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then - arch="arm64" +# Check if vncserver is installed, and install if not +if ! check_installed; then + # Detect system information + distro=$(grep "^ID=" /etc/os-release | awk -F= '{print $2}') + version=$(grep "^VERSION_ID=" /etc/os-release | awk -F= '{print $2}' | tr -d '"') + arch=$(uname -m) + + echo "Detected Distribution: $distro" + echo "Detected Version: $version" + echo "Detected Architecture: $arch" + + # Map arch to package arch + if [[ "$arch" == "x86_64" ]]; then + if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then + arch="amd64" + else + arch="x86_64" + fi + elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then + if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then + arch="arm64" + else + arch="aarch64" + fi else - arch="aarch64" + echo "Unsupported architecture: $arch" + exit 1 fi -else - echo "Unsupported architecture: $arch" - exit 1 -fi -# Check if vncserver is installed, and install if not -if ! check_installed; then echo "Installing KASM version: ${VERSION}" case $distro in ubuntu | debian | kali) @@ -158,8 +158,11 @@ else echo "vncserver already installed. Skipping installation." fi -# Coder port-forwarding from dashboard only supports HTTP -sudo bash -c "cat > /etc/kasmvnc/kasmvnc.yaml < /dev/null && config_path="/etc/kasmvnc/kasmvnc.yaml" + +sudo bash -c "cat > $config_path < /tmp/kasmvncserver.log 2>&1 & +if sudo -n true 2> /dev/null; then + sudo -u $USER bash -c "vncserver -select-de ${DESKTOP_ENVIRONMENT} -disableBasicAuth" > /tmp/kasmvncserver.log 2>&1 & +else + vncserver -select-de ${DESKTOP_ENVIRONMENT} -disableBasicAuth > /tmp/kasmvncserver.log 2>&1 & +fi