Skip to content
This repository has been archived by the owner on Jan 14, 2022. It is now read-only.

Commit

Permalink
Close #7 - Use Github auth token if available
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed May 10, 2017
1 parent 74111bb commit 9fab27e
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 32 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ Your new `hugo` binary is in `./bin`, so change your Makefie or scripts to use `
* #3 Zip support
* #4 and format over-rides.
* #5 Checksum support
* #6 Move curl/wget abstraction to top of script
* #7 Figure out how to use an existing GITHUB token so `latest` doesn't fail on CI systems
* #8 Setup travis.ci
* #10 Adjustment of default `TMPDIR` and `BINDIR` (install directory)
* #11 Use goreleaser to release godownloader
Expand Down
24 changes: 14 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,35 @@ echo "specify version number or 'latest'"
exit 1
fi
# download dest source
# if dest is "-", then output to stdout
# if source is api.github.com add auth token
download() {
DEST=$1
SOURCE=$2
HEADER=""
case $SOURCE in
https://api.github.com*)
test -z "$GITHUB_TOKEN" || HEADER="Authorization: token $GITHUB_TOKEN"
;;
esac
if which curl > /dev/null; then
WGET="curl -sSL"
test -z "$GITHUB_TOKEN" || WGET="${WGET} -H \"${HEADER}\""
if [ "${DEST}" != "-" ]; then
WGET="$WGET -o $DEST"
fi
elif which wget > /dev/null; then
WGET="wget -q -O $DEST"
test -z "$GITHUB_TOKEN" || WGET="${WGET} --header \"${HEADER}\""
else
echo "Unable to find wget or curl. Exit"
exit 1
fi
# TODO: if source starts with github
# and we have env auth token
# then add it
HEADER=""
case $SOURCE in
https://api.github.com*)
HEADER=""
;;
esac
${WGET} $HEADER $SOURCE
${WGET} ${SOURCE}
}
if [ "${VERSION}" = "latest" ]; then
Expand Down
24 changes: 14 additions & 10 deletions samples/godownloader-goreleaser.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,35 @@ echo "specify version number or 'latest'"
exit 1
fi

# download dest source
# if dest is "-", then output to stdout
# if source is api.github.com add auth token
download() {
DEST=$1
SOURCE=$2

HEADER=""
case $SOURCE in
https://api.github.com*)
test -z "$GITHUB_TOKEN" || HEADER="Authorization: token $GITHUB_TOKEN"
;;
esac

if which curl > /dev/null; then
WGET="curl -sSL"
test -z "$GITHUB_TOKEN" || WGET="${WGET} -H \"${HEADER}\""
if [ "${DEST}" != "-" ]; then
WGET="$WGET -o $DEST"
fi
elif which wget > /dev/null; then
WGET="wget -q -O $DEST"
test -z "$GITHUB_TOKEN" || WGET="${WGET} --header \"${HEADER}\""
else
echo "Unable to find wget or curl. Exit"
exit 1
fi

# TODO: if source starts with github
# and we have env auth token
# then add it
HEADER=""
case $SOURCE in
https://api.github.com*)
HEADER=""
;;
esac
${WGET} $HEADER $SOURCE
${WGET} ${SOURCE}
}

if [ "${VERSION}" = "latest" ]; then
Expand Down
24 changes: 14 additions & 10 deletions samples/godownloader-hugo.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,35 @@ echo "specify version number or 'latest'"
exit 1
fi

# download dest source
# if dest is "-", then output to stdout
# if source is api.github.com add auth token
download() {
DEST=$1
SOURCE=$2

HEADER=""
case $SOURCE in
https://api.github.com*)
test -z "$GITHUB_TOKEN" || HEADER="Authorization: token $GITHUB_TOKEN"
;;
esac

if which curl > /dev/null; then
WGET="curl -sSL"
test -z "$GITHUB_TOKEN" || WGET="${WGET} -H \"${HEADER}\""
if [ "${DEST}" != "-" ]; then
WGET="$WGET -o $DEST"
fi
elif which wget > /dev/null; then
WGET="wget -q -O $DEST"
test -z "$GITHUB_TOKEN" || WGET="${WGET} --header \"${HEADER}\""
else
echo "Unable to find wget or curl. Exit"
exit 1
fi

# TODO: if source starts with github
# and we have env auth token
# then add it
HEADER=""
case $SOURCE in
https://api.github.com*)
HEADER=""
;;
esac
${WGET} $HEADER $SOURCE
${WGET} ${SOURCE}
}

if [ "${VERSION}" = "latest" ]; then
Expand Down

0 comments on commit 9fab27e

Please sign in to comment.