DEV Community

abbazs
abbazs

Posted on • Edited on

A zoom installer script for linux

Often when you install zoom in linux you would have encountered broken install issue. Here is a function to save you from installing and keeping it updated:

#!/bin/bash

set -euo pipefail

print_style() {
    local style="${1:-0}"
    local color="${2:-32}"
    local message="${3:-$color}"
    echo -e "\e[${style};${color}m${message}\e[0m"
}

get_version_from_json() {
    local url="https://zoom.us/rest/download?os=linux"
    curl -s "$url" | jq -r '.result.downloadVO.zoom.version'
}

get_installed_version() {
    dpkg-query -W -f='${Version}' zoom 2>/dev/null || echo "Not installed"
}

download_zoom() {
    local version="$1"
    local filename="zoom_amd64.deb"
    print_style 1 31 "Downloading Zoom version $version"
    curl -LO "https://zoom.us/client/latest/$filename"
    echo "$filename"
}

install_dependencies() {
    local filename="$1"
    local package_names

    package_names=$(dpkg-deb -f "$filename" Depends | sed -e 's/,//g' -e 's/([^)]*)//g')

    if [[ "$package_names" == *"|"* ]]; then
        IFS='|' read -ra dep_choices <<< "$package_names"
        for choice in "${dep_choices[@]}"; do
            sudo apt-get install -y $choice && break
        done
    else
        sudo apt-get install -y $package_names
    fi
}

install_zoom() {
    local filename="$1"
    sudo dpkg -i "$filename"
    sudo apt-get install -f -y
}

update_zoom() {
    local latest_version
    local installed_version
    local filename

    latest_version=$(get_version_from_json)
    installed_version=$(get_installed_version)

    print_style 1 34 "Latest version   : $latest_version"
    print_style 1 34 "Installed version: $installed_version"

    if [ "$installed_version" = "$latest_version" ]; then
        print_style 1 32 "The current version $installed_version is already installed."
        return
    fi

    filename=$(download_zoom "$latest_version")
    install_dependencies "$filename"
    install_zoom "$filename"

    rm -f "$filename"
    print_style 1 32 "Zoom has been successfully updated to version $latest_version"
}

main() {
    if ! command -v jq &> /dev/null; then
        print_style 1 31 "jq is not installed. Please install it first."
        exit 1
    fi

    update_zoom
}

main "$@"
Enter fullscreen mode Exit fullscreen mode

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs