-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck_update.sh
executable file
·49 lines (39 loc) · 1.5 KB
/
check_update.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
case $1 in
beta) CHANNEL="beta" ;;
dev) CHANNEL="dev" ;;
*) CHANNEL="production"
esac
CWD=`dirname $(readlink -f $0)`
cd $CWD
if [ -f "$CWD/.release_channel" ]; then
CHANNEL=`cat "$CWD/.release_channel"`
fi
case $CHANNEL in
production) PATTERN='"tag_name": *".*[0-9]"' ;;
beta) PATTERN='"tag_name": *".*[0-9]-beta"' ;;
dev) PATTERN="dev";;
*) echo "wrong channel name $CHANNEL"
exit 5
esac
if [ "$PATTERN" = "dev" ]; then
DT=`date -I -d'6 months ago'`
RELEASES=`curl -s -q "https://api.github.com/repos/gasparch/vim-ide-elixir/commits?since=$DT&sha=master"`
LAST_RELEASE=`echo "$RELEASES" | egrep '"sha":' | head -n 1 | sed -e 's#^.*"\([0-9a-f]*\)".*$#\1#'`
LAST_VERSION=$LAST_RELEASE
CURRENT_RELEASE=`git log --format=format:%H -n1`
else
RELEASES=`curl -s -q "https://api.github.com/repos/gasparch/vim-ide-elixir/releases" | egrep '"url":.*vim-ide-elixir|"tag_name":'`
LAST_RELEASE=`echo "$RELEASES" | egrep -B1 "$PATTERN" | grep '"url"' | sed -e 's#^.*\/\([0-9]*\).*$#\1#' | sort -n | tail -n1`
if [ -z "$LAST_RELEASE" ]; then
echo "no releases in channel $CHANNEL"
exit 5
fi
LAST_VERSION=`echo "$RELEASES" | egrep -A1 "url.*releases/$LAST_RELEASE" | grep '"tag_name"' | cut -d: -f2 | sed -e 's/,$//' -e 's/ //g' -e 's/"//g'`
CURRENT_RELEASE=`[ -f $CWD/.current_release ] && cat $CWD/.current_release`
fi
if [ ! -z "$CURRENT_RELEASE" -a "$CURRENT_RELEASE" = "$LAST_RELEASE" ]; then
echo "noupdate,$CURRENT_RELEASE"
else
echo "update,$CURRENT_RELEASE,$LAST_RELEASE,$LAST_VERSION"
fi