-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from ivanilves/wrapper
Add invocation/update wrapper
- Loading branch information
Showing
4 changed files
with
71 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} ${@} |