#!/bin/bash ## Script Location SCRIPTDIR=$(dirname $0) source "$SCRIPTDIR/common/colors.sh" source "$SCRIPTDIR/common/functions.sh" source "$SCRIPTDIR/common/load-defaults.sh" topgrade_install_directory="/opt/topgrade" topgrade_binary="/opt/topgrade/topgrade" install_topgrade() { topgrade_tar="/opt/topgrade/topgrade.tar.gz" topgrade_git_owner="r-darwish" topgrade_git_repo="topgrade" newest_release_url=$(curl -sL https://api.github.com/repos/$topgrade_git_owner/$topgrade_git_repo/releases/latest | jq -r ".assets[].browser_download_url" | grep x86_64-unknown-linux-gnu.tar.gz) wget $newest_release_url -q -O "$topgrade_tar" tar -xvf $topgrade_tar -C $topgrade_install_directory rm $topgrade_tar chmod +x $topgrade_binary } update_topgrade() { current_version=$($topgrade_binary --version | sed 's/[A-Za-z]*//g') printf "$COL_GREEN" "** Locally installed topgrade version: $current_version" newest_release=$(curl -sL https://api.github.com/repos/$topgrade_git_owner/$topgrade_git_repo/releases/latest | jq -r ".tag_name" | sed 's/[A-Za-z]*//g') printf "$COL_GREEN" "** Online topgrade version: $newest_release" if [ "$current_version" != "$newest_release" ]; then printf "$COL_LIGHT_BLUE" "* Updating topgrade binary" install_topgrade fi } check_topgrade_dir() { if [ ! -d "$topgrade_install_directory" ]; then printf "$COL_YELLOW" "** creating topgrade installation directory" mkdir $topgrade_install_directory else printf "$COL_YELLOW" "** topgrade installation directory exists" fi } printf "$COL_LIGHT_BLUE" "* Checking for topgrade directory" check_topgrade_dir printf "$COL_LIGHT_BLUE" "* Checking for topgrade binary" if [ ! -f "$topgrade_binary" ]; then printf "$COL_YELLOW" "** topgrade binary missing, installing now" install_topgrade else printf "$COL_LIGHT_BLUE" "* Checking for topgrade binary updates" update_topgrade fi # Ubuntu Jammy need focal repo to get this if ! is_shared_lib_present libssl.so.1.1 then distro=$(get_dist) printf "$COL_YELLOW" "** Distrobution detected as $distro" if get_dist == "Ubuntu" ]] then printf "$COL_YELLOW" "** libssl.so.1.1 library missing, installing now" echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list apt update apt install -y libssl1.1 else printf "$COL_RED" "** libssl.so.1.1 library missing, and no special fix for distro: $distro" fi fi printf "$COL_LIGHT_BLUE" "checking for topgrade confs" custom_topgrade_confs_path="/etc/topgrade" custom_topgrade_confs_git="https://git.deathbybandaid.net/deathbybandaid/topgrade.git" git_update "topgrade" "$custom_topgrade_confs_path" "$custom_topgrade_confs_git"