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.
atif/support-kasm-images
Muhammad Atif Ali 8 months ago
parent ce5a5b383a
commit df507ca559

@ -14,7 +14,7 @@ Automatically install [KasmVNC](https://kasmweb.com/kasmvnc) in a workspace, and
```tf ```tf
module "kasmvnc" { module "kasmvnc" {
source = "registry.coder.com/modules/kasmvnc/coder" source = "registry.coder.com/modules/kasmvnc/coder"
version = "1.0.22" version = "1.0.23"
agent_id = coder_agent.example.id agent_id = coder_agent.example.id
desktop_environment = "xfce" desktop_environment = "xfce"
} }

@ -75,35 +75,35 @@ install_alpine() {
rm /tmp/kasmvncserver.tgz rm /tmp/kasmvncserver.tgz
} }
# Detect system information # Check if vncserver is installed, and install if not
distro=$(grep "^ID=" /etc/os-release | awk -F= '{print $2}') if ! check_installed; then
version=$(grep "^VERSION_ID=" /etc/os-release | awk -F= '{print $2}' | tr -d '"') # Detect system information
arch=$(uname -m) distro=$(grep "^ID=" /etc/os-release | awk -F= '{print $2}')
version=$(grep "^VERSION_ID=" /etc/os-release | awk -F= '{print $2}' | tr -d '"')
echo "Detected Distribution: $distro" arch=$(uname -m)
echo "Detected Version: $version"
echo "Detected Architecture: $arch" echo "Detected Distribution: $distro"
echo "Detected Version: $version"
# Map arch to package arch echo "Detected Architecture: $arch"
if [[ "$arch" == "x86_64" ]]; then
if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then # Map arch to package arch
arch="amd64" if [[ "$arch" == "x86_64" ]]; then
else if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then
arch="x86_64" arch="amd64"
fi else
elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then arch="x86_64"
if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then fi
arch="arm64" elif [[ "$arch" == "aarch64" || "$arch" == "arm64" ]]; then
if [[ "$distro" == "ubuntu" || "$distro" == "debian" || "$distro" == "kali" ]]; then
arch="arm64"
else
arch="aarch64"
fi
else else
arch="aarch64" echo "Unsupported architecture: $arch"
exit 1
fi 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}" echo "Installing KASM version: ${VERSION}"
case $distro in case $distro in
ubuntu | debian | kali) ubuntu | debian | kali)
@ -158,8 +158,11 @@ else
echo "vncserver already installed. Skipping installation." echo "vncserver already installed. Skipping installation."
fi fi
# Coder port-forwarding from dashboard only supports HTTP # if sudo is not available, create the config file as the current user .vnc/kasmvnc.yaml
sudo bash -c "cat > /etc/kasmvnc/kasmvnc.yaml <<EOF config_path="~/.vnc/kasmvnc.yaml"
[ sudo -n true ] 2> /dev/null && config_path="/etc/kasmvnc/kasmvnc.yaml"
sudo bash -c "cat > $config_path <<EOF
network: network:
protocol: http protocol: http
websocket_port: ${PORT} websocket_port: ${PORT}
@ -176,4 +179,8 @@ echo -e "password\npassword\n" | vncpasswd -wo -u $USER
# Start the server # Start the server
printf "🚀 Starting KasmVNC server...\n" printf "🚀 Starting KasmVNC server...\n"
sudo -u $USER bash -c "vncserver -select-de ${DESKTOP_ENVIRONMENT} -disableBasicAuth" > /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

Loading…
Cancel
Save