Software installation

Introduction

This page explains the automation procedure for the software installation required for the CIFO courses

Required software

IDEs

Visual Studio Code

Used mainly for any type of development or documentation maintenance; its plugins allow to easily manage Git and GitHub repositories, create Quarto/Markdown files and publish them as static websites, and many more things.

IntelliJ IDEA

Its main purpose is to ease Java applications development. It also has a nice Git and GitHub repository manager, so it’s easy to keep track of the updates and latest changes on our code.

  • Installation page: JetBrains Toolbox App
    • It’s recommended to install any JetBrains application through their Toolbox, as it also manages any available update of them

Vim

One of the most popular terminal IDEs for Linux, useful when no Desktop application is available or quick changes on files have to be done from a terminal.

  • Installation command:
sudo apt-get install vim

Sublime Text

A good text editor which features can be expanded by installing additional extensions/packages. With the correct configuration it can also compile and test projects from within the application.

Version Control Software

Git

This is the main tool to manage git repositories, any other software uses it on background or includes it within the app. Available by default in the default Linux Package Repositories.

  • Installation command:
sudo apt-get install git

GitHub

The CLI tool to interact with GitHub repositories, very useful to manage your own repositories, branches, etc… It can also create and solve Pull Requests from the CLI.

GitHub Desktop

The Desktop app to interact with GitHub repositories, more user-friendly than the CLI version. There’s no official linux release, but GitHub themselves redirect users to a trusted fork (Community Releases).

Documentation

Obsidian

A Markdown editor with many more features. The installation packages for Linux are available in their GitHub releases repository.

Quarto CLI

A Markdown framework that expands the language by adding compatibily with other documentation tools, such as Medusa for diagrams. The installation packages for Linux are available in their GitHub repository.


Debugging

Postman

Postman is a tool to analyse HTTP requests and responses. Follow this guide or this other guide to install Postman.

Automating the software installation

Almost all the required software can be installed directly from the command line interface (CLI), so in order to avoid repeating commands and human errors, some scripts are created to automate all the process

Software installation script

The script software_install.sh is a shell script that automates all the installation process. As some steps require a more complex parsing logic, the script invokes extra scripts that act as tools. The script is split into the following steps:

  1. Install pre-required programs (wget, curl, apt-transport-https, etc…)
  2. Add both GPG keys and package repositories for the software that has them.
    • The sources lists are stored in /etc/apt/sources.list.d.
    • The GPG keys are stored in different paths depending on the app creator instructions
  3. Install software from newly-added repositories
  4. Install software that comes with its own installation scripts
    • Jetbrains Toolbox: tools/jetbrains-toolbox.sh
  5. Retrieve and install .deb packages of software maintained as GitHub repositories
    • This step uses the tools/retrieve_latest_release.py script
#!/bin/bash
#   CIFO Web Applications - Software installation
#   - This script install the required software for the course
#   - Categories:
#       - IDEs
#       - Version Control Sofware
#       - Documentation

# Check that the user has enough privileges to install software
if [[ $EUID -ne 0 ]]; then
    echo "This script must be run with administrator privileges. Please execute it with 'sudo' or as root user"
    exit 1
fi

# Define the installation command
# -qq flag prior to the install command reduces the output messages except for errors
# -y after the install command is for non-interactive/unattended installations
INSTALL="apt-get -qq install -y"
UPDATE="apt-get -qq update"

# Pre-requisites:
# - Install download and GPG binaries
# - Apt installation via HTTPS paths must also be installed
# - FUSE (libfuse2) for AppImages (jetbrains-toolbox) --> Required on Ubuntu 22.04 with FUSE3 installed by default
#sudo apt-get install -y wget gpg curl apt-transport-https
$INSTALL wget gpg curl apt-transport-https libfuse2

# Additional repositories installation
# ====================================
# IDEs:
echo "Configuring repositories for IDEs..."
echo "===================================="
# - Microsoft: Visual Studio Code
echo "- Visual Studio Code"
# Retrieve the Microsoft GPG key and install it
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
# Add the Microsoft Visual Studio Code repository to the apt sources list
sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
# Delete the already installed GPG key
rm -f packages.microsoft.gpg
echo ""
# - Sublime Text
echo "- Sublime Text"
# Retrieve and install GPG key
wget -qO - https://download.sublimetext.com/sublimehq-pub.gpg | gpg --dearmor > sublimehq-pub.gpg
install -D -o root -g root -m 644 sublimehq-pub.gpg /usr/share/keyrings/sublimehq-pub.gpg
# Add Sublime Text repository to apt sources list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/sublimehq-pub.gpg] https://download.sublimetext.com/ apt/stable/" | tee /etc/apt/sources.list.d/sublime-text.list > /dev/null
# Delete the already installed GPG key
rm -f sublimehq-pub.gpg
echo ""
# VCS:
echo "Configuring repositories for VCS:"
echo "================================="
# - GitHub:
echo "- GitHub"
# Install CURL to retrieve GitHub GPG key
#type -p curl >/dev/null || sudo apt install curl -y
# Retrieve the GPG key and install it
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg
# Add GitHub CLI repository to apt sources list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null
echo ""
# Browsers:
echo "Configuring repositories for browsers:"
echo "======================================"
# - Google Chrome
echo "- Google Chrome"
# Retrieve and install the public key
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | gpg --dearmor > google-chrome-pub.gpg
install -D -o root -g root -m 644 google-chrome-pub.gpg /usr/share/keyrings/google-chrome-pub.gpg
# Add Google Chrome repository to apt sources list
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/google-chrome-pub.gpg] http://dl.google.com/linux/chrome/deb/ stable main" | tee /etc/apt/sources.list.d/google-chrome.list > /dev/null
# Delete the already installed GPG key
rm -f google-chrome-pub.gpg
echo ""
# Repositories update
echo "Updating repositories packages lists..."
echo "======================================="
$UPDATE
echo "Done"
echo ""
# Software installation
echo "Installing software from repositories:"
echo "======================================"
# - IDEs: Visual Studio Code, vim, Sublime Text
echo "Installing IDEs..."
$INSTALL code vim sublime-text
echo ""
# - VCS: Git, GitHub
echo "Installing VCS..."
$INSTALL git gh
echo ""
# - Browsers: Google Chrome (stable)
echo "Installing browsers..."
$INSTALL google-chrome-stable
echo ""
# - Documentation: TBD
echo "Installing Documentation software... TBD"
echo ""
# - Desktop tools
echo "Installing Desktop tools..."
$INSTALL flameshot
echo ""

# External software
echo "Installing software not in repositories:"
echo "========================================"
# Jetbrains Toolbox: once installed, use it to install IntelliJ IDEA
echo "- Jetbrains Toolbox"
if ! [ $(command -v jetbrains-toolbox) ] && [ -f tools/jetbrains-toolbox.sh ]; then
    # Install toolbox as ROOT and execute it as the current user
    # This is required as jetbrains toolbox configures the installation paths based on the 'home' folder of the user that executes it
    ./tools/jetbrains-toolbox.sh && su -c jetbrains-toolbox $SUDO_USER
    echo "Toolbox installed, now install IntelliJ IDEA from there"
else
    echo "WARNING: Either jetbrains-toolbox.sh script not found or already installed. Skipping installation"
fi
echo ""

# Install from latest releases of GitHub repositories
echo "Install from GitHub repositories latest releases"
echo "================================================"
if [[ -f tools/retrieve_latest_release.py ]]; then
    # VCS:
    # - GitHub Desktop
    echo "- GitHub Desktop"
    ./tools/retrieve_latest_release.py --gh-user shiftkey --gh-repo desktop --pattern .deb
    echo ""
    # Documentation:
    # - Obsidian
    echo "- Obsidian"
    ./tools/retrieve_latest_release.py --gh-user obsidianmd --gh-repo obsidian-releases --pattern .deb
    echo ""
    # - Quarto
    echo "- Quarto"
    ./tools/retrieve_latest_release.py --gh-user quarto-dev --gh-repo quarto-cli --pattern .deb
    echo ""
    echo "Installing all downloaded packages..."
    $INSTALL ./*.deb
    echo "Deleting already installed packages..."
    rm -r *.deb
else
    echo "ERROR: retrieve_latest_release.py script not found!! Aborting installation"
fi

echo "DONE!!"

Tools scripts

Tools scripts are scripts that help the main script with more complex tasks or simply have all the installation process for a single software:

JetBrains Toolbox

#!/bin/bash

[ $(id -u) != "0" ] && exec sudo "$0" "$@"
echo -e " \e[94mInstalling Jetbrains Toolbox\e[39m"
echo ""

function getLatestUrl() {
USER_AGENT=('User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36')

URL=$(curl 'https://data.services.jetbrains.com/products/releases?code=TBA&latest=true&type=release' -H 'Origin: https://www.jetbrains.com' -H 'Accept-Encoding: gzip, deflate, br' -H 'Accept-Language: en-US,en;q=0.8' -H "${USER_AGENT[@]}" -H 'Accept: application/json, text/javascript, */*; q=0.01' -H 'Referer: https://www.jetbrains.com/toolbox/download/' -H 'Connection: keep-alive' -H 'DNT: 1' --compressed | grep -Po '"linux":.*?[^\\]",' | awk -F ':' '{print $3,":"$4}'| sed 's/[", ]//g')
echo $URL
}
getLatestUrl

FILE=$(basename ${URL})
DEST=$PWD/$FILE

echo ""
echo -e "\e[94mDownloading Toolbox files \e[39m"
echo ""
wget -cO  ${DEST} ${URL} --read-timeout=5 --tries=0
echo ""
echo -e "\e[32mDownload complete!\e[39m"
echo ""
DIR="/opt/jetbrains-toolbox"
echo ""
echo  -e "\e[94mInstalling to $DIR\e[39m"
echo ""
if mkdir ${DIR}; then
    tar -xzf ${DEST} -C ${DIR} --strip-components=1
fi

chmod -R +rwx ${DIR}

ln -s ${DIR}/jetbrains-toolbox /usr/local/bin/jetbrains-toolbox
chmod -R +rwx /usr/local/bin/jetbrains-toolbox
echo ""
rm ${DEST}
echo  -e "\e[32mDone.\e[39m"

Retrieve latest package released from GitHub repositories

If the GitHub CLI package is installed, then this can be used to retrieve the latest .deb release of any reachable repository:

# Download the latest release
gh release download --repo ${GH_USER}/${GH_REPO} --pattern '*.deb'

Example:

gh release download --repo quarto-dev/quarto-cli --pattern '*.deb'

If gh cli is not available, then the following python script has been created for the same purpose:

#!/usr/bin/python3
# GitHub latest release package retrieval
import json
import requests
from argparse import ArgumentParser

def parse_arguments():
    parser = ArgumentParser(
        prog="retrieve_latest_release",
        description="Retrieves latest release from a GitHub repository",
        epilog="GitHub user and repository name are mandatory, as well as the file pattern (.deb, .tar.gz, etc...)"
    )

    parser.add_argument('--gh-user', dest='gh_user', type=str, help='The GitHub username', required=True)
    parser.add_argument('--gh-repo', dest='gh_repo', help='The GitHub repository', required=True)
    parser.add_argument('--pattern', dest='pattern', help='The pattern of the asst to download', default='.deb', required=False)

    return parser.parse_args()


def main():
    args = parse_arguments()
    print(f"Requesting latest release from {args.gh_user}/{args.gh_repo}, ({args.pattern} format)")
    gh_api_url=f"https://api.github.com/repos/{args.gh_user}/{args.gh_repo}/releases/latest"
    r = requests.get(gh_api_url)
    response_text = json.loads(r.content)
    #print(json.dumps(response_text, indent=2))

    # Search fot the first asset that matches the file pattern
    if "assets" in response_text:
        for asset in response_text["assets"]:
            if "name" in asset and asset["name"].endswith(args.pattern):
                print(f'Downloading {asset["browser_download_url"]}...')
                filename = asset["name"]
                download = requests.get(asset["browser_download_url"])
                print(f"Saving content into {filename}")
                open(filename, "wb").write(download.content)
                break

if __name__ == '__main__':
    # Execute the main program
    main()

Install additional extensions for VSCode

Visual Studio Code comes with a CLI that allows the user to install/uninstall extensions from the terminal. More info can be found in the official documentation.

Pending to create a list of useful extensions and a shell script to install them

Install additional extensions for IntelliJ IDEA

Pending to see if IntelliJ IDEA has any CLI to automate the process