Skip to content

Instantly share code, notes, and snippets.

@mavjs
Last active May 31, 2022 18:30
Show Gist options
  • Save mavjs/d6e8cc5f16cd8f55b62595e5e0723b6c to your computer and use it in GitHub Desktop.
Save mavjs/d6e8cc5f16cd8f55b62595e5e0723b6c to your computer and use it in GitHub Desktop.

Revisions

  1. mavjs revised this gist May 31, 2022. 1 changed file with 8 additions and 2 deletions.
    10 changes: 8 additions & 2 deletions unpacking go.md
    Original file line number Diff line number Diff line change
    @@ -38,6 +38,7 @@ FILE_URL="${DL_URL}${LATEST_FILE}"
    CHECKSUM_URL="${FILE_URL}.sha256"
    CHECKSUM_FILE="${LATEST_FILE}.sha256sum"


    echo "Downloading: ${FILE_URL} at ${LATEST_FILE}"
    curl -L -s -o "${LATEST_FILE}" "${FILE_URL}"
    echo "Downloading checksum: ${CHECKSUM_URL} at ${CHECKSUM_FILE}"
    @@ -47,7 +48,7 @@ echo "${CHECKSUM}" "${LATEST_FILE}" > "${CHECKSUM_FILE}"
    echo "Checking hashsum ....."
    STATUS=$(sha256sum -c "${LATEST_FILE}.sha256sum" | grep OK)
    if [ -n "${STATUS}" ];
    then
    then
    echo "Hashsum is good!"
    else
    echo "HASHSUM IS NOT GOOD!"
    @@ -57,13 +58,18 @@ fi
    echo "Installing....."
    if [ -d "/home/${USER}/goroot" ];
    then
    echo "Removing goroot before upgrade"
    rm -rf "/home/${USER}/goroot"
    mkdir "/home/${USER}/goroot/"
    echo "Installing in ~/goroot"
    tar -C "/home/${USER}/goroot" -xzf "${LATEST_FILE}" --strip-components=1
    else
    echo "Removing goroot before upgrade"
    rm -rf "/usr/local/go"
    echo "Installing /usr/local/"
    tar -C "/usr/local/" -xzf "${LATEST_FILE}"
    fi

    echo "Cleaning up temp directory at: ${FILE_DIR}"
    rm -rf "${FILE_DIR}"
    ```
    ```
  2. mavjs revised this gist May 31, 2022. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion unpacking go.md
    Original file line number Diff line number Diff line change
    @@ -38,7 +38,6 @@ FILE_URL="${DL_URL}${LATEST_FILE}"
    CHECKSUM_URL="${FILE_URL}.sha256"
    CHECKSUM_FILE="${LATEST_FILE}.sha256sum"


    echo "Downloading: ${FILE_URL} at ${LATEST_FILE}"
    curl -L -s -o "${LATEST_FILE}" "${FILE_URL}"
    echo "Downloading checksum: ${CHECKSUM_URL} at ${CHECKSUM_FILE}"
  3. mavjs revised this gist May 31, 2022. 1 changed file with 22 additions and 13 deletions.
    35 changes: 22 additions & 13 deletions unpacking go.md
    Original file line number Diff line number Diff line change
    @@ -12,39 +12,47 @@ tar -C ~/goroot -xzvf go$VERSION.linux-amd64.tar.gz --strip-components=1
    # set -e
    set -o pipefail

    FILE_DIR=$(mktemp -d -t upgover-XXXXXXXX)

    echo "Entering into temporary work directory: ${FILE_DIR}"
    cd "${FILE_DIR}" || exit

    URL="https://golang.org"
    VER_CHECK="${URL}/dl/"
    DL_URL="https://dl.google.com/go/"
    LATEST_FILE=$(curl -s "${VER_CHECK}" | grep filename | grep download | grep linux-amd64.tar.gz | head -n 1 | cut -d">" -f 3 | cut -d"<" -f 1)
    LATEST_FILE=$(curl -L -s "${VER_CHECK}" | grep filename | grep download | grep linux-amd64.tar.gz | head -n 1 | cut -d">" -f 3 | cut -d"<" -f 1)

    echo "Latest file: ${LATEST_FILE}"

    VER=$(echo "${LATEST_FILE}" | grep -oP 'go[0-9\.]+')
    LATEST_VER=${VER%?}
    CUR_VER=$(go version | cut -d" " -f3)

    if [ "${LATEST_VER}" == "${CUR_VER}" ];
    then
    echo "You're on the latest golang version: ${CUR_VER}"
    exit
    echo "You are already on the latest golang version: ${CUR_VER}"
    exit 1
    fi

    FILE_URL="${DL_URL}${LATEST_FILE}"
    CHECKSUM_URL="${FILE_URL}.sha256"
    FILE_DIR=$(mktemp -d -t upgover-XXXXXXXX)
    CHECKSUM_FILE="${LATEST_FILE}.sha256sum"

    echo "Downloading: ${FILE_URL} at ${FILE_DIR}/${LATEST_FILE}"
    echo "Downloading checksum: ${CHECKSUM_URL} at ${FILE_DIR}/${LATEST_FILE}.sha256"

    curl -s -o "${FILE_DIR}/${LATEST_FILE}" "${FILE_URL}"
    echo "Downloading: ${FILE_URL} at ${LATEST_FILE}"
    curl -L -s -o "${LATEST_FILE}" "${FILE_URL}"
    echo "Downloading checksum: ${CHECKSUM_URL} at ${CHECKSUM_FILE}"
    CHECKSUM=$(curl -s "${CHECKSUM_URL}")
    echo "${CHECKSUM}" "${LATEST_FILE}" > "${CHECKSUM_FILE}"

    pushd "${FILE_DIR}" || exit

    STATUS=$(echo "${CHECKSUM} ${LATEST_FILE}" | sha256sum -c | grep OK)
    echo "Checking hashsum ....."
    STATUS=$(sha256sum -c "${LATEST_FILE}.sha256sum" | grep OK)
    if [ -n "${STATUS}" ];
    then
    echo "Pretty ok!"
    then
    echo "Hashsum is good!"
    else
    echo "NOT OK!"
    echo "HASHSUM IS NOT GOOD!"
    exit 1
    fi

    echo "Installing....."
    @@ -54,6 +62,7 @@ then
    tar -C "/home/${USER}/goroot" -xzf "${LATEST_FILE}" --strip-components=1
    else
    echo "Installing /usr/local/"
    tar -C "/usr/local/" -xzf "${LATEST_FILE}"
    fi

    echo "Cleaning up temp directory at: ${FILE_DIR}"
  4. mavjs revised this gist Sep 16, 2020. 1 changed file with 54 additions and 0 deletions.
    54 changes: 54 additions & 0 deletions unpacking go.md
    Original file line number Diff line number Diff line change
    @@ -4,4 +4,58 @@ By default the go tar file will unpack with `go/` as a prefix directory, thus we

    ```bash
    tar -C ~/goroot -xzvf go$VERSION.linux-amd64.tar.gz --strip-components=1
    ```

    ## Script to update
    ```bash
    #!/bin/bash
    # set -e
    set -o pipefail

    URL="https://golang.org"
    VER_CHECK="${URL}/dl/"
    DL_URL="https://dl.google.com/go/"
    LATEST_FILE=$(curl -s "${VER_CHECK}" | grep filename | grep download | grep linux-amd64.tar.gz | head -n 1 | cut -d">" -f 3 | cut -d"<" -f 1)

    VER=$(echo "${LATEST_FILE}" | grep -oP 'go[0-9\.]+')
    LATEST_VER=${VER%?}
    CUR_VER=$(go version | cut -d" " -f3)

    if [ "${LATEST_VER}" == "${CUR_VER}" ];
    then
    echo "You're on the latest golang version: ${CUR_VER}"
    exit
    fi

    FILE_URL="${DL_URL}${LATEST_FILE}"
    CHECKSUM_URL="${FILE_URL}.sha256"
    FILE_DIR=$(mktemp -d -t upgover-XXXXXXXX)

    echo "Downloading: ${FILE_URL} at ${FILE_DIR}/${LATEST_FILE}"
    echo "Downloading checksum: ${CHECKSUM_URL} at ${FILE_DIR}/${LATEST_FILE}.sha256"

    curl -s -o "${FILE_DIR}/${LATEST_FILE}" "${FILE_URL}"
    CHECKSUM=$(curl -s "${CHECKSUM_URL}")

    pushd "${FILE_DIR}" || exit

    STATUS=$(echo "${CHECKSUM} ${LATEST_FILE}" | sha256sum -c | grep OK)
    if [ -n "${STATUS}" ];
    then
    echo "Pretty ok!"
    else
    echo "NOT OK!"
    fi

    echo "Installing....."
    if [ -d "/home/${USER}/goroot" ];
    then
    echo "Installing in ~/goroot"
    tar -C "/home/${USER}/goroot" -xzf "${LATEST_FILE}" --strip-components=1
    else
    echo "Installing /usr/local/"
    fi

    echo "Cleaning up temp directory at: ${FILE_DIR}"
    rm -rf "${FILE_DIR}"
    ```
  5. mavjs created this gist May 31, 2020.
    7 changes: 7 additions & 0 deletions unpacking go.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    # About
    If your `$GOROOT` is in `~/goroot` and your `$GOPATH` is in `~/go`, you want to make sure that your new go version goes to the right folder.
    By default the go tar file will unpack with `go/` as a prefix directory, thus we want to remove that when unpacking, thus the `--strip-components=1`.

    ```bash
    tar -C ~/goroot -xzvf go$VERSION.linux-amd64.tar.gz --strip-components=1
    ```