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.
This commit is contained in:
@@ -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"
|
||||
}
|
||||
|
||||
@@ -75,6 +75,8 @@ install_alpine() {
|
||||
rm /tmp/kasmvncserver.tgz
|
||||
}
|
||||
|
||||
# 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 '"')
|
||||
@@ -102,8 +104,6 @@ else
|
||||
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 <<EOF
|
||||
# if sudo is not available, create the config file as the current user .vnc/kasmvnc.yaml
|
||||
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:
|
||||
protocol: http
|
||||
websocket_port: ${PORT}
|
||||
@@ -176,4 +179,8 @@ echo -e "password\npassword\n" | vncpasswd -wo -u $USER
|
||||
|
||||
# Start the server
|
||||
printf "🚀 Starting KasmVNC server...\n"
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user