#!/bin/bash VBOX_VERSION='7.1' VBOX_PACKAGE="virtualbox-$VBOX_VERSION" FINGERPRINT_VBOX='B9F8 D658 297A F3EF C18D 5CDF A2F6 83C5 2980 AECF' VBOX_PUBKEY_LOCATION='/usr/share/keyrings/oracle-virtualbox-2016.gpg' VBOX_PUBKEY_LINK='https://www.virtualbox.org/download/oracle_vbox_2016.asc' if [ ! -f /etc/os-release ]; then echo "[Error] /etc/os-release not found, cannot detect distro" exit 1 fi # shellcheck disable=SC1091 . /etc/os-release IS_DEBIAN_LIKE=false case "$ID" in debian|ubuntu) IS_DEBIAN_LIKE=true ;; esac if [ "$IS_DEBIAN_LIKE" = false ]; then case " ${ID_LIKE:-} " in *debian*|*ubuntu*) IS_DEBIAN_LIKE=true ;; esac fi if [ "$IS_DEBIAN_LIKE" = false ]; then echo "[Error] Detected distro '$PRETTY_NAME' is not Debian/Ubuntu based. Aborting." exit 1 fi # On derivatives (e.g. Linux Mint, LMDE) VERSION_CODENAME is the # distro's own codename and isn't recognized by the VirtualBox repo. # Prefer the upstream Ubuntu/Debian codename when the distro exposes one. DISTRO="${UBUNTU_CODENAME:-${DEBIAN_CODENAME:-$VERSION_CODENAME}}" echo "Detected distro: $PRETTY_NAME (ID=$ID, base codename=$DISTRO)" read -r -p "Is this correct? Continue with VirtualBox installation for '$DISTRO'? [y/N] " CONFIRM case "$CONFIRM" in y|Y|yes|YES) ;; *) echo "Aborted by user."; exit 1 ;; esac SOURCE_LIST="deb [arch=amd64 signed-by=$VBOX_PUBKEY_LOCATION] https://download.virtualbox.org/virtualbox/debian $DISTRO contrib" sudo apt update && sudo apt install -y wget gpg wget -O- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --yes --output $VBOX_PUBKEY_LOCATION --dearmor if gpg --show-keys --fingerprint "$VBOX_PUBKEY_LOCATION" 2>/dev/null | grep -q "$FINGERPRINT_VBOX"; then echo "Good FingerPrint is valid!" sleep 5 else echo "[Error] Fingerprint is not valid" exit 1 fi echo $SOURCE_LIST | sudo tee /etc/apt/sources.list.d/vbox.list sudo apt-get update sudo apt-get install -y $VBOX_PACKAGE