Skip to content

Commit

Permalink
Merge pull request #98 from ivanilves/wrapper
Browse files Browse the repository at this point in the history
Add invocation/update wrapper
  • Loading branch information
vonrabbe authored Nov 16, 2017
2 parents 52ffc3d + 20ec072 commit 12ef622
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ script:
- make lint
- make vet

after_success:
- if [[ "${TRAVIS_PULL_REQUEST}" == "false" ]]; then make release; fi
before_deploy:
- make release

deploy:
provider: script
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ release:

validate-release:
test -s ./dist/release/TAG && test -s ./dist/release/NAME
egrep "^\* " ./dist/release/CHANGELOG.md
test -f ./dist/release/CHANGELOG.md
[[ `find dist/assets -mindepth 2 -type f | wc -l` -ge 2 ]]

deploy: TAG=$(shell cat ./dist/release/TAG)
Expand All @@ -132,3 +132,9 @@ docker: DOCKER_REPO:=ivanilves/lstags
docker: RELEASE_TAG:=latest
docker:
@docker image build -t ${DOCKER_REPO}:${RELEASE_TAG} .

wrapper: PREFIX=/usr/local
wrapper:
install -o root -g root -m755 scripts/wrapper.sh ${PREFIX}/bin/lstags

install: wrapper
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ You can either:
## Install: Binaries
https://github.com/ivanilves/lstags/releases

## Install: Wrapper
```sh
git clone [email protected]:ivanilves/lstags.git
cd lstags
sudo make wrapper
lstags -h
```
A special wrapper script will be installed to manage `lstags` invocation and updates. :sunglasses:

## Install: From source
```sh
git clone [email protected]:ivanilves/lstags.git
Expand Down
53 changes: 53 additions & 0 deletions scripts/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env bash
#
[[ "${DEBUG}" == "true" || "${DEBUG}" == "yes" ]] && set -x

set -uo pipefail

declare -r -i CACHE_TTL_MINUTES=2880

declare -r LOCAL_PATH=${HOME}/.lstags; mkdir -p "${LOCAL_PATH}" || exit 2
declare -r LSTAGS=${LOCAL_PATH}/lstags
declare -r UPDATE_MARKER="${LOCAL_PATH}/update"

declare -r LATEST_RELEASE_URL=https://api.github.com/repos/ivanilves/lstags/releases/latest
declare -r DOWNLOAD_URL=https://github.com/ivanilves/lstags/releases/download

CHECK_FOR_UPDATE=false
if [[ ! -x "${LSTAGS}" || ! -f "${UPDATE_MARKER}" ]]; then
CHECK_FOR_UPDATE=true
elif [[ -n "$(find ${UPDATE_MARKER} -type f -cmin +${CACHE_TTL_MINUTES})" ]]; then
CHECK_FOR_UPDATE=true
fi

PERFORM_UPDATE=false
if [[ "${CHECK_FOR_UPDATE}" == "true" ]]; then
declare -r LATEST_VERSION=$(curl --connect-timeout 5 -m10 -s -f -H "Content-Type:application/json" "${LATEST_RELEASE_URL}" | jq -r '.name')
declare -r LATEST_TAG=${LATEST_VERSION/-*/}
declare -r LATEST_VERSION_URL=${DOWNLOAD_URL}/${LATEST_TAG}/lstags-$(uname -s | tr [A-Z] [a-z])-${LATEST_VERSION}.tar.gz

if [[ -x "${LSTAGS}" && -n "${LATEST_VERSION}" ]]; then
LOCAL_VERSION=$(${LSTAGS} --version | cut -d' ' -f2)
if [[ "${LOCAL_VERSION}" != "${LATEST_VERSION}" ]]; then
echo "Local version: ${LOCAL_VERSION} / Will download new one: ${LATEST_VERSION}"
PERFORM_UPDATE=true
else
echo "You already have the latest version: ${LOCAL_VERSION}"
fi
elif [[ -n "${LATEST_VERSION}" ]]; then
echo "No binary found, will download latest version: ${LATEST_VERSION}"
PERFORM_UPDATE=true
else
echo "Failed to check for update!" >>/dev/stderr
fi

echo '-'
fi

if [[ "${PERFORM_UPDATE}" == "true" ]]; then
curl --connect-timeout 5 -m30 -s -f "${LATEST_VERSION_URL}" -L | tar -C "${LOCAL_PATH}" -xz
fi

touch "${UPDATE_MARKER}"

exec ${LSTAGS} ${@}

0 comments on commit 12ef622

Please sign in to comment.