-
Notifications
You must be signed in to change notification settings - Fork 62
fix(kasmvnc): optimize KasmVNC deployment script #329
Changes from 2 commits
a8cc861
8213a57
6d6e0dd
c59ba95
bb7d438
10a86bd
46bbcb9
30e6bed
4d831b4
9c3904d
4a72b2e
a2d8e72
026a5bc
4fc9f6d
d418c81
c4f88fa
52ba74c
d619e65
eff921e
eb974cb
f3a0f98
ab96d93
ebc57a1
86b48dd
15e3ec2
41baf48
7d7c7e8
f35b535
a0373c0
ccf299b
ef4f704
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||
| #!/usr/bin/env bash | ||||||||||
|
|
||||||||||
| #!/bin/bash | ||||||||||
| # Exit on error, undefined variables, and pipe failures | ||||||||||
| set -euo pipefail | ||||||||||
|
|
||||||||||
| # Function to check if vncserver is already installed | ||||||||||
| check_installed() { | ||||||||||
|
|
@@ -14,143 +15,137 @@ check_installed() { | |||||||||
|
|
||||||||||
| # Function to download a file using wget, curl, or busybox as a fallback | ||||||||||
| download_file() { | ||||||||||
| local url=$1 | ||||||||||
| local output=$2 | ||||||||||
| if command -v wget &> /dev/null; then | ||||||||||
| wget $url -O $output | ||||||||||
| elif command -v curl &> /dev/null; then | ||||||||||
| curl -fsSL $url -o $output | ||||||||||
| local url="$1" | ||||||||||
| local output="$2" | ||||||||||
| local download_tool | ||||||||||
|
|
||||||||||
| if command -v curl &> /dev/null; then | ||||||||||
| download_tool="curl -fsSL" | ||||||||||
| elif command -v wget &> /dev/null; then | ||||||||||
| download_tool="wget -q -O-" | ||||||||||
| elif command -v busybox &> /dev/null; then | ||||||||||
| busybox wget -O $output $url | ||||||||||
| download_tool="busybox wget -O-" | ||||||||||
| else | ||||||||||
| echo "Neither wget, curl, nor busybox is installed. Please install one of them to proceed." | ||||||||||
| echo "ERROR: No download tool available (curl, wget, or busybox required)" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Function to install kasmvncserver for debian-based distros | ||||||||||
| install_deb() { | ||||||||||
| local url=$1 | ||||||||||
| download_file $url /tmp/kasmvncserver.deb | ||||||||||
| sudo apt-get update | ||||||||||
| DEBIAN_FRONTEND=noninteractive sudo apt-get install --yes -qq --no-install-recommends --no-install-suggests /tmp/kasmvncserver.deb | ||||||||||
| sudo adduser $USER ssl-cert | ||||||||||
| rm /tmp/kasmvncserver.deb | ||||||||||
| $download_tool "$url" > "$output" || { | ||||||||||
| echo "ERROR: Failed to download $url" | ||||||||||
| exit 1 | ||||||||||
| } | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Function to install kasmvncserver for Oracle 8 | ||||||||||
| install_rpm_oracle8() { | ||||||||||
| local url=$1 | ||||||||||
| download_file $url /tmp/kasmvncserver.rpm | ||||||||||
| sudo dnf config-manager --set-enabled ol8_codeready_builder | ||||||||||
| sudo dnf install oracle-epel-release-el8 -y | ||||||||||
| sudo dnf localinstall /tmp/kasmvncserver.rpm -y | ||||||||||
| sudo usermod -aG kasmvnc-cert $USER | ||||||||||
| rm /tmp/kasmvncserver.rpm | ||||||||||
| # Add user to group using available commands | ||||||||||
| add_user_to_group() { | ||||||||||
| local user="$1" | ||||||||||
| local group="$2" | ||||||||||
|
|
||||||||||
| if command -v usermod &> /dev/null; then | ||||||||||
| sudo usermod -aG "$group" "$user" | ||||||||||
| elif command -v adduser &> /dev/null; then | ||||||||||
| sudo adduser "$user" "$group" | ||||||||||
| else | ||||||||||
| echo "ERROR: At least one of 'adduser'(Debian) 'usermod'(RHEL) is required" | ||||||||||
djarbz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Function to install kasmvncserver for CentOS 7 | ||||||||||
| install_rpm_centos7() { | ||||||||||
djarbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| # Function to install kasmvncserver for debian-based distros | ||||||||||
| install_deb() { | ||||||||||
| local url=$1 | ||||||||||
| download_file $url /tmp/kasmvncserver.rpm | ||||||||||
| sudo yum install epel-release -y | ||||||||||
| sudo yum install /tmp/kasmvncserver.rpm -y | ||||||||||
| sudo usermod -aG kasmvnc-cert $USER | ||||||||||
| rm /tmp/kasmvncserver.rpm | ||||||||||
| download_file "$url" /tmp/kasmvncserver.deb | ||||||||||
| # Define the directory to check | ||||||||||
| CACHE_DIR="/var/lib/apt/lists/partial" | ||||||||||
| # Check if the directory exists and was modified in the last 60 minutes | ||||||||||
| if [ ! -d "$CACHE_DIR" ] || ! find "$CACHE_DIR" -mmin -60 -print -quit &> /dev/null; then | ||||||||||
djarbz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| echo "Stale Package Cache, updating..." | ||||||||||
djarbz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
| # Update package cache with a 300-second timeout for dpkg lock | ||||||||||
| sudo apt-get -o DPkg::Lock::Timeout=300 -qq update | ||||||||||
| fi | ||||||||||
| DEBIAN_FRONTEND=noninteractive sudo apt-get -o DPkg::Lock::Timeout=300 install --yes -qq --no-install-recommends --no-install-suggests /tmp/kasmvncserver.deb | ||||||||||
|
||||||||||
| add_user_to_group "$USER" ssl-cert | ||||||||||
| rm /tmp/kasmvncserver.deb | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Function to install kasmvncserver for rpm-based distros | ||||||||||
| install_rpm() { | ||||||||||
| local url=$1 | ||||||||||
| download_file $url /tmp/kasmvncserver.rpm | ||||||||||
| download_file "$url" /tmp/kasmvncserver.rpm | ||||||||||
| sudo rpm -i /tmp/kasmvncserver.rpm | ||||||||||
|
||||||||||
| rm /tmp/kasmvncserver.rpm | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Function to install kasmvncserver for Alpine Linux | ||||||||||
| install_alpine() { | ||||||||||
| local url=$1 | ||||||||||
| download_file $url /tmp/kasmvncserver.tgz | ||||||||||
| download_file "$url" /tmp/kasmvncserver.tgz | ||||||||||
| tar -xzf /tmp/kasmvncserver.tgz -C /usr/local/bin/ | ||||||||||
| rm /tmp/kasmvncserver.tgz | ||||||||||
| } | ||||||||||
|
|
||||||||||
| # Check for sudo (required) | ||||||||||
| if ! command -v sudo &> /dev/null; then | ||||||||||
| echo "ERROR: Required command 'sudo' not found" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
djarbz marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||||
|
|
||||||||||
| # 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) | ||||||||||
| if [[ ! -f /etc/os-release ]]; then | ||||||||||
djarbz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| echo "ERROR: Cannot detect OS: /etc/os-release not found" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| # shellcheck disable=SC1091 | ||||||||||
| source /etc/os-release | ||||||||||
| distro="$ID" | ||||||||||
| distro_version="$VERSION_ID" | ||||||||||
| codename="$VERSION_CODENAME" | ||||||||||
| arch="$(uname -m)" | ||||||||||
| if [[ "$ID" == "ol" ]]; then | ||||||||||
| distro="oracle" | ||||||||||
| distro_version="$${distro_version%%.*}" | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| echo "Detected Distribution: $distro" | ||||||||||
| echo "Detected Version: $version" | ||||||||||
| echo "Detected Version: $distro_version" | ||||||||||
| echo "Detected Codename: $codename" | ||||||||||
| 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 | ||||||||||
| echo "Unsupported architecture: $arch" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
| case "$arch" in | ||||||||||
| x86_64) | ||||||||||
| [[ "$distro" =~ ^(ubuntu|debian|kali)$ ]] && arch="amd64" || arch="x86_64" | ||||||||||
|
||||||||||
| [[ "$distro" =~ ^(ubuntu|debian|kali)$ ]] && arch="amd64" || arch="x86_64" | |
| if [[ "$distro" =~ ^(ubuntu|debian|kali)$ ]]; then | |
| arch="amd64" | |
| fi |
Suggestion: A bit more verbose but easier to understand, should also be easier to extend in the future if need-be.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above, except I also wonder if we actually want to enforce the overwrite from arm64 to aarch64 when distro isn't one of the three?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For x86_64, it probably doesn't need to overwrite.
For aarch64 or arm64, do we need to do anything other than just match?
I would imagine that each distro would report the correct version for itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't look like arm64 case in aarch64 | arm64) is ever applicable:
❯ for container in ubuntu debian kalilinux/kali-rolling alpine fedora opensuse/leap container-registry.oracle.com/os/oraclelinux:9-slim; do for plat in linux/arm64 linux/amd64; do docker run -it --rm --platform $plat $container /bin/sh -c 'echo $(grep ^NAME= /etc/os-release): $(uname -m)'; done; done 2>/dev/null
NAME="Ubuntu": aarch64
NAME="Ubuntu": x86_64
NAME="Debian GNU/Linux": aarch64
NAME="Debian GNU/Linux": x86_64
NAME="Kali GNU/Linux": aarch64
NAME="Kali GNU/Linux": x86_64
NAME="Alpine Linux": aarch64
NAME="Alpine Linux": x86_64
NAME="Fedora Linux": aarch64
NAME="Fedora Linux": x86_64
NAME="openSUSE Leap": aarch64
NAME="openSUSE Leap": x86_64
NAME="Oracle Linux Server": aarch64
NAME="Oracle Linux Server": x86_64
So we can essentially use the same logic as above for x86_64, default=aarch64, for debian based, use arm64 instead (verified from kasm releases that all others are aarch64).
djarbz marked this conversation as resolved.
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We probably need both install_rpm and install_dnf. I just tried the opensuse/leap image and it has neither dnf nor yum, only zypper and rpm.
I'm not sure if this is a script meant for installing the kasmvnc built package or something else, but this at least gives hints for the expectation per distro: https://github.com/kasmtech/KasmVNC/blob/3a8517d7dc461eaccc7ed8e3d3b155e233426fc8/builder/scripts/common.sh#L22-L29
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps in the install_rpm function, we have a switch case to select based on what tooling is available?
Similar to the download function?
Priority:
- dnf
- zypper
- yum
- rpm
Uh oh!
There was an error while loading. Please reload this page.