Skip to content

Commit

Permalink
Add wrapper to get the latest app. ALWAYS
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanilves committed Nov 15, 2017
1 parent 2d69832 commit 149f619
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 git@github.com: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 git@github.com: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 149f619

Please sign in to comment.