#!/usr/bin/env bash has-cmd() { command -v "$1" &> /dev/null } NL=$'\n' xsudo() { local x_input=() y_input="" while read -t 1 line; do x_input+=("$line") done for z in "${x_input[@]}"; do y_input+="${z}${NL}" done if (( EUID == 0 )); then [[ -z "$y_input" ]] && env "$@" || env "$@" <<< "$y_input" return $? else if has-cmd sudo; then >&2 echo -e " >> Current user isn't root. Running command with sudo: $*" [[ -z "$y_input" ]] && sudo "$@" || sudo "$@" <<< "$y_input" return $? else >&2 echo -e " [!!!] Current user isn't root, but sudo isn't available..." >&2 echo -e " [!!!] Trying 'su -c' for command: $*" [[ -z "$y_input" ]] && su -c "$*" || su -c "$*" <<< "$y_input" return $? fi fi } dl-key() { if ! has-cmd curl && ! has-cmd wget; then >&2 echo -e "\n [!!!] Neither cURL nor wget are installed!" >&2 echo -e " [!!!] Attempting to auto-install 'curl'\n" xsudo apt-get update -qy > /dev/null xsudo apt-get install -qy curl > /dev/null fi echo -e "\n >>> Attempting to download key from $mnt_key_src - outputting to: $1" if has-cmd curl; then curl -fsSL "$mnt_key_src" -o "$1" return $? elif has-cmd wget; then wget -q "$mnt_key_src" -O "$1" return $? else >&2 echo -e "\n [!!!] Neither cURL nor wget are installed!" >&2 echo -e " [!!!] Already attempted to install curl but failed. Something is really wrong." >&2 echo -e " [!!!] Aborting Privex key + repo installation. Please install either curl or wget manually." exit 3 fi } : ${mnt_key_src="https://apt.privex.io/maintainer.gpg"} : ${mnt_out="$(mktemp)"} : ${mnt_kc_dir="/etc/apt/trusted.gpg.d"} : ${mnt_kc="${mnt_kc_dir}/privex-packaging-2022.gpg"} OLD_KEYS=( "${mnt_kc_dir}/privex-packaging-2020.gpg" ) for f in "${OLD_KEYS[@]}"; do if [[ -f "$f" ]]; then echo -e " [!!!] Found old key: $f" echo -e " [---] Removing old key to prevent issues: $f" xsudo rm -vf "$f" fi done dl-key "$mnt_out" echo -e "\n [+++] Successfully downloaded maintainer key to file: $mnt_out \n" if [[ -d "$mnt_kc_dir" ]]; then echo -e " >>> Found apt keychain folder: $mnt_kc_dir" echo -e " >>> Assuming this is a modern apt version, and simply copying the key into the folder.\n" xsudo cp -v "$mnt_out" "$mnt_kc" >> Did not find apt keychain folder: $mnt_kc_dir" echo -e " >>> Assuming older version of apt - will use 'apt-key add' instead." xsudo apt-key add "$mnt_out" >> Adding apt.privex.io repo to /etc/apt/sources.list.d/privex.list\n" xsudo tee /etc/apt/sources.list.d/privex.list <>> Running apt-get update\n" xsudo apt-get update -qy >> Installing 'privex-keyring' package, to ensure Privex's maintainer GPG key is kept up to date" xsudo apt-get install -qy privex-keyring privex-repo