Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Commit

Permalink
Added update script
Browse files Browse the repository at this point in the history
  • Loading branch information
Andre Lademann committed May 17, 2018
1 parent 01f3c95 commit c0a9b01
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/tests/assert.sh
/tests/fixtures/
credentials.yml
DAY_UPDATE
3 changes: 3 additions & 0 deletions bashlight
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
# Your settings here
readonly PATH_BASHLIGHT="$HOME/bashlight"

# Check update
. ${PATH_BASHLIGHT}/update.sh

####################################################################################
# Include modules
####################################################################################
Expand Down
Empty file modified install.sh
100644 → 100755
Empty file.
Empty file modified install/git.sh
100644 → 100755
Empty file.
Empty file modified install/tmux.sh
100644 → 100755
Empty file.
1 change: 1 addition & 0 deletions src/notify
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function blPlay() {
### speak
function blSay() {
# OS X
say $1
if type "say" >/dev/null 2>&1 ; then
say -r $VOICE_RATE -v $VOICE_TYPE "$@." 2> /dev/null
fi
Expand Down
55 changes: 55 additions & 0 deletions update.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/sh

####################################################################################
# Bashlight : 0.1.2
# Copyright : 2018, MIT
# Author : André Lademann <[email protected]>
# Repository : https://github.com/vergissberlin/bashlight
####################################################################################

GIT_DIR=~/bashlight/.git

VERSION_LOCAL=$(GIT_DIR=~/bashlight/.git git describe --tags --abbrev=0)
DAY_UPDATE=~/bashlight/DAY_UPDATE
DAY_TODAY=$(date +%j)

function version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1";
}


# Update check only once a day
if [ ! -f ${DAY_UPDATE} ]; then
echo ${DAY_TODAY} > ${DAY_UPDATE}
fi

if [ ${DAY_TODAY} -le $(cat ${DAY_UPDATE}) ]; then
echo -e "\033[34;5;;172mBashlight ${VERSION_LOCAL}\033[0m"
else
# Update check
VERSION_REMOTE=$(git ls-remote --tags [email protected]:vergissberlin/bashlight.git | sort -t '/' -k 3 -V | awk -F/ '{ print $3 }' | tail -1)

if version_gt ${VERSION_REMOTE} ${VERSION_LOCAL}; then
echo -e "\a";
echo -e "\033[34;5;;172m"\
"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓\n"\
"┃ Bashlight update notice ┃\n"\
"┠────────────────────────────────────────────────┨\n"\
"┃ Your version: ${VERSION_LOCAL} ┃\n"\
"┃ Current version: ${VERSION_REMOTE} ┃\n"\
"┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┛\n"\
"\033[0m"

while true; do
read -p "Do you wish to install this program (yes/no)? " yn
case $yn in
[Yy]* ) GIT_DIR=~/bashlight/.git git pull --tags; echo ${DAY_TODAY} > ${DAY_UPDATE}; break;;
[Nn]* ) break;;
* ) echo "Please answer yes or no.";;
esac
done

else
echo -e "\033[34;5;;172mBashlight ${VERSION_LOCAL}\033[0m"
fi
fi

0 comments on commit c0a9b01

Please sign in to comment.