Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions cmd/updater/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,88 @@ function determine_current_version() {
echo Current Version = ${CURRENTVER}
}

function get_updater_url() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment that the function sets UPDATER_FILENAME and UPDATER_URL

local UNAME
local OS
local ARCH
UNAME=$(uname)
if [[ "${UNAME}" = "Darwin" ]]; then
OS="darwin"
UNAME=$(uname -m)
if [[ "${UNAME}" = "x86_64" ]]; then
ARCH="amd64"
else
echo "This platform ${UNAME} is not supported by updater."
exit 1
fi
elif [[ "${UNAME}" = "Linux" ]]; then
OS="linux"
UNAME=$(uname -m)
if [[ "${UNAME}" = "x86_64" ]]; then
ARCH="amd64"
elif [[ "${UNAME}" = "armv6l" ]]; then
ARCH="arm"
elif [[ "${UNAME}" = "armv7l" ]]; then
ARCH="arm"
elif [[ "${UNAME}" = "aarch64" ]]; then
ARCH="arm64"
else
echo "This platform ${UNAME} is not supported by updater."
exit 1
fi
else
echo "This operation system ${UNAME} is not supported by updater."
exit 1
fi
UPDATER_FILENAME="install_master_${OS}-${ARCH}.tar.gz"
UPDATER_URL="https://github.com/algorand/go-algorand-doc/raw/master/downloads/installers/${OS}_${ARCH}/${UPDATER_FILENAME}"
}

# check to see if the binary updater exists. if not, it will automatically the correct updater binary for the current platform
function check_for_updater() {
# check if the updater binary exist.
if [ -f "${SCRIPTPATH}/updater" ]; then
return 0
fi
get_updater_url

# check the curl is available.
CURL_VER=$(curl -V 2>/dev/null || true)
if [ "${CURL_VER}" = "" ]; then
# no curl is installed.
echo "updater binary is missing and cannot be downloaded since curl is missing."
if [[ "$(uname)" = "Linux" ]]; then
echo "To install curl, run the following command:"
echo "apt-get update; apt-get install -y curl"
fi
exit 1
fi

CURL_OUT=$(curl -LJO --silent ${UPDATER_URL})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confused.

  1. -J tells curl to use Content-Disposition for output file name instead of URL name. But after we refer the file as UPDATER_FILENAME from URL. Can't Content-Disposition and actual file name be different?
  2. curl drops file into current directory but we looking the file at "${SCRIPTPATH}/${UPDATER_FILENAME}" I do not see where SCRIPTPATH is set as CWD.

if [ "$?" != "0" ]; then
echo "failed to download updater binary from ${UPDATER_URL} using curl."
echo "${CURL_OUT}"
exit 1
fi

if [ ! -f "${SCRIPTPATH}/${UPDATER_FILENAME}" ]; then
echo "downloaded file ${SCRIPTPATH}/${UPDATER_FILENAME} is missing."
exit
fi

tar -zxvf "${SCRIPTPATH}/${UPDATER_FILENAME}" updater
if [ "$?" != "0" ]; then
echo "failed to extract updater binary from ${SCRIPTPATH}/${UPDATER_FILENAME}"
exit 1
fi

rm -f "${SCRIPTPATH}/${UPDATER_FILENAME}"
echo "updater binary was downloaded"
}

function check_for_update() {
determine_current_version
check_for_updater
LATEST="$(${SCRIPTPATH}/updater ver check -c ${CHANNEL} ${BUCKET} | sed -n '2 p')"
if [ $? -ne 0 ]; then
echo "No remote updates found"
Expand Down