62 lines
2.2 KiB
Bash
62 lines
2.2 KiB
Bash
#!/bin/bash
|
|
|
|
## Script Location
|
|
SCRIPTDIR=$(dirname $0)
|
|
source "$SCRIPTDIR/common/colors.sh"
|
|
source "$SCRIPTDIR/common/functions.sh"
|
|
|
|
load_defaults=""
|
|
case "$1" in
|
|
defaults) load_defaults="defaults";;
|
|
"") load_defaults="";;
|
|
*) echo "'$1' is not a valid template-setup command";;
|
|
esac
|
|
if [ "$load_defaults" == "defaults" ]; then
|
|
source $SCRIPTDIR/defaults-dbb.sh
|
|
else
|
|
source $SCRIPTDIR/defaults-blank.sh
|
|
fi
|
|
|
|
printf "$COL_LIGHT_BLUE" "* Checking for topgrade directory"
|
|
topgrade_install_directory="/opt/topgrade"
|
|
if [ ! -d "$topgrade_install_directory" ]; then
|
|
printf "$COL_YELLOW" "** creating topgrade installation directory"
|
|
mkdir $topgrade_install_directory
|
|
fi
|
|
|
|
printf "$COL_LIGHT_BLUE" "* Checking for topgrade binary"
|
|
topgrade_binary="/opt/topgrade/topgrade"
|
|
topgrade_tar="/opt/topgrade/topgrade.tar.gz"
|
|
topgrade_git_owner="r-darwish"
|
|
topgrade_git_repo="topgrade"
|
|
if [ ! -f "$topgrade_binary" ]; then
|
|
printf "$COL_YELLOW" "** topgrade binary missing, installing now"
|
|
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
|
|
else
|
|
printf "$COL_YELLOW" "** topgrade binary exists"
|
|
fi
|
|
|
|
if [ ! -f "$topgrade_binary" ]; then
|
|
printf "$COL_RED" "** topgrade binary not present at $topgrade_binary"
|
|
else
|
|
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"
|
|
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"
|
|
|
|
## Update
|
|
if [ -f "$topgrade_binary" ]; then
|
|
printf "$COL_CYAN" "* Running topgrade"
|
|
$topgrade_binary
|
|
fi
|