mirror of
https://github.com/deadc0de6/dotdrop.git
synced 2026-02-09 22:14:17 +00:00
update version checker
This commit is contained in:
@@ -4,26 +4,27 @@
|
|||||||
|
|
||||||
api="https://api.github.com/repos"
|
api="https://api.github.com/repos"
|
||||||
pro="deadc0de6/dotdrop"
|
pro="deadc0de6/dotdrop"
|
||||||
|
logs="/tmp/dotdrop-version.log"
|
||||||
|
|
||||||
|
########################
|
||||||
|
## git operations
|
||||||
|
########################
|
||||||
|
|
||||||
git_get_changes()
|
git_get_changes()
|
||||||
{
|
{
|
||||||
#git fetch origin
|
#git fetch origin
|
||||||
git remote update
|
git remote update >>${logs} 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
# get current status
|
get_current_commit()
|
||||||
get_current()
|
|
||||||
{
|
{
|
||||||
tag=$(get_current_tag)
|
git rev-parse --short HEAD
|
||||||
[ "$tag" != "" ] && echo "tag: ${tag}"
|
|
||||||
branch=$(get_current_branch)
|
|
||||||
[ "$branch" != "" ] && echo "branch: ${branch}"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# get current tag
|
# get current tag
|
||||||
get_current_tag()
|
get_current_tag()
|
||||||
{
|
{
|
||||||
git describe --tags --long 2>/dev/null
|
git describe --tags 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
get_current_branch()
|
get_current_branch()
|
||||||
@@ -31,80 +32,139 @@ get_current_branch()
|
|||||||
git branch --show-current 2>/dev/null
|
git branch --show-current 2>/dev/null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
is_on_release()
|
||||||
|
{
|
||||||
|
git describe --exact-match --tags HEAD >>${logs} 2>&1
|
||||||
|
echo "$?"
|
||||||
|
}
|
||||||
|
|
||||||
|
checkout()
|
||||||
|
{
|
||||||
|
git checkout "$1" >>${logs} 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
########################
|
||||||
|
## api operations
|
||||||
|
########################
|
||||||
|
|
||||||
# get latest release
|
# get latest release
|
||||||
get_latest()
|
get_latest()
|
||||||
{
|
{
|
||||||
curl "${api}/${pro}/releases/latest" 2>/dev/null | grep 'tag_name' | sed 's/^.*: "\(.*\)",/\1/g'
|
curl "${api}/${pro}/releases/latest" 2>>${logs} | grep 'tag_name' | sed 's/^.*: "\(.*\)",/\1/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
# list all releases
|
# list all releases
|
||||||
get_releases()
|
get_releases()
|
||||||
{
|
{
|
||||||
curl "${api}/${pro}/releases" 2>/dev/null | grep 'tag_name' | sed 's/^.*: "\(.*\)",/\1/g'
|
curl "${api}/${pro}/releases" 2>>${logs} | grep 'tag_name' | sed 's/^.*: "\(.*\)",/\1/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
# list all branches
|
# list all branches
|
||||||
get_branches()
|
get_branches()
|
||||||
{
|
{
|
||||||
curl "${api}/${pro}/branches" 2>/dev/null | grep name | sed 's/^.*: "\(.*\)",/\1/g'
|
curl "${api}/${pro}/branches" 2>>${logs} | grep name | sed 's/^.*: "\(.*\)",/\1/g'
|
||||||
}
|
}
|
||||||
|
|
||||||
need_update()
|
########################
|
||||||
|
## print status
|
||||||
|
########################
|
||||||
|
|
||||||
|
# get current status
|
||||||
|
get_current()
|
||||||
{
|
{
|
||||||
git fetch origin >/dev/null 2>&1
|
local tag
|
||||||
|
local commit
|
||||||
|
local branch
|
||||||
|
echo "current version:"
|
||||||
|
stable=$(is_on_release)
|
||||||
|
if [ "${stable}" = "0" ]; then
|
||||||
|
echo -e "\ton stable"
|
||||||
|
tag=$(get_current_tag)
|
||||||
|
echo -e "\trelease version: ${tag}"
|
||||||
|
else
|
||||||
|
echo -e "\ton unstable"
|
||||||
|
tag=$(get_current_tag)
|
||||||
|
echo -e "\ttag: ${tag}"
|
||||||
|
commit=$(get_current_commit)
|
||||||
|
echo -e "\tcommit: ${commit}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
branch=$(get_current_branch)
|
||||||
|
[ "$branch" != "" ] && echo -e "\tbranch: ${branch}"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# check if new stable release is available
|
||||||
|
need_update_stable()
|
||||||
|
{
|
||||||
|
local last
|
||||||
|
local cur
|
||||||
|
local tag
|
||||||
|
git fetch origin >>${logs} 2>&1
|
||||||
last=$(get_latest)
|
last=$(get_latest)
|
||||||
cur=$(get_current_tag)
|
cur=$(get_current_tag)
|
||||||
# get short tag if on a lightweight tag
|
# get short tag if on a lightweight tag
|
||||||
|
|
||||||
tag=$(echo "$cur" | sed 's/\(v.*\)-[0-9]*.-.*$/\1/g')
|
tag=$(echo "$cur" | sed 's/\(v.*\)-[0-9]*.-.*$/\1/g')
|
||||||
nb=$(echo "$cur" | sed 's/v.*-\([0-9]*\)-.*$/\1/g')
|
if [ "${tag}" != "${last}" ]; then
|
||||||
commit=$(echo "$cur" | sed 's/v.*-[0-9]*-\(.*\)$/\1/g')
|
echo "new stable version available: ${last}" && return
|
||||||
|
|
||||||
if [ "${commit}" != "" ]; then
|
|
||||||
echo "you are on ${tag} commit ${commit}"
|
|
||||||
else
|
|
||||||
echo "you are on ${cur}"
|
|
||||||
fi
|
fi
|
||||||
|
echo "your version is up-to-date"
|
||||||
|
}
|
||||||
|
|
||||||
|
# check if new updates are available
|
||||||
|
need_update()
|
||||||
|
{
|
||||||
|
local changes
|
||||||
|
git fetch origin >>${logs} 2>&1
|
||||||
|
|
||||||
# compare
|
# compare
|
||||||
if [ "${tag}" != "${last}" ]; then
|
changes=$(git log HEAD..origin --oneline)
|
||||||
echo "new version available: ${last}" && return
|
|
||||||
fi
|
|
||||||
changes=$(git status -s)
|
|
||||||
[ "${changes}" != "" ] && echo "new updates available" && return
|
[ "${changes}" != "" ] && echo "new updates available" && return
|
||||||
echo "your version is up-to-date"
|
echo "your version is up-to-date"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
########################
|
||||||
|
## change operations
|
||||||
|
########################
|
||||||
|
|
||||||
checkout_last_tag()
|
checkout_last_tag()
|
||||||
{
|
{
|
||||||
|
local last
|
||||||
|
local cur
|
||||||
last=$(get_latest)
|
last=$(get_latest)
|
||||||
[ "${last}" = "" ] && echo "unable to get last release" && return
|
[ "${last}" = "" ] && echo "unable to get last release" && return
|
||||||
cur=$(get_current_tag)
|
cur=$(get_current_tag)
|
||||||
[ "${cur}" = "${last}" ] && return
|
[ "${cur}" = "${last}" ] && return
|
||||||
git_get_changes && git checkout "${last}"
|
git_get_changes && checkout "${last}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1: tag
|
# $1: tag
|
||||||
checkout_tag()
|
checkout_tag()
|
||||||
{
|
{
|
||||||
|
local cur
|
||||||
cur=$(get_current_tag)
|
cur=$(get_current_tag)
|
||||||
[ "${cur}" = "${1}" ] && return
|
[ "${cur}" = "${1}" ] && return
|
||||||
git_get_changes && git checkout "${1}"
|
git_get_changes && checkout "${1}"
|
||||||
}
|
}
|
||||||
|
|
||||||
checkout_branch()
|
checkout_branch()
|
||||||
{
|
{
|
||||||
git_get_changes && git checkout "${1}" && git pull origin "${1}"
|
git_get_changes && checkout "${1}" && git pull origin "${1}" >/dev/null 2>&1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
########################
|
||||||
|
## helpers
|
||||||
|
########################
|
||||||
|
|
||||||
# move to base of dotdrop
|
# move to base of dotdrop
|
||||||
move_to_base()
|
move_to_base()
|
||||||
{
|
{
|
||||||
|
local curpwd
|
||||||
curpwd=$(pwd)
|
curpwd=$(pwd)
|
||||||
git submodule | grep dotdrop >/dev/null 2>&1
|
git submodule | grep dotdrop >/dev/null 2>&1
|
||||||
if [ "$?" ]; then
|
if [ "$?" ]; then
|
||||||
# dotdrop is a submodule
|
# dotdrop is a submodule
|
||||||
echo "dotdrop used as a submodule"
|
#echo "dotdrop used as a submodule"
|
||||||
cd dotdrop || (echo "cannot change directory to dotdrop" && exit 1)
|
cd dotdrop || (echo "cannot change directory to dotdrop" && exit 1)
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@@ -113,7 +173,7 @@ move_to_base()
|
|||||||
grep deadc0de6 dotdrop/version.py >/dev/null 2>&1
|
grep deadc0de6 dotdrop/version.py >/dev/null 2>&1
|
||||||
if [ "$?" ]; then
|
if [ "$?" ]; then
|
||||||
# dotdrop is in current dir
|
# dotdrop is in current dir
|
||||||
echo "dotdrop is in current directory"
|
#echo "dotdrop is in current directory"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
@@ -125,45 +185,68 @@ move_to_base()
|
|||||||
# print usage
|
# print usage
|
||||||
usage()
|
usage()
|
||||||
{
|
{
|
||||||
echo "$(basename "${0}") current : current version tracked"
|
echo "$(basename "${0}") print current : print the version you are on"
|
||||||
echo "$(basename "${0}") releases : list all releases"
|
echo "$(basename "${0}") print releases : list available stable releases"
|
||||||
echo "$(basename "${0}") branches : list all branches"
|
echo "$(basename "${0}") print branches : list available branches"
|
||||||
echo "$(basename "${0}") check : check for updates"
|
echo "$(basename "${0}") check unstable : check for new unstable updates"
|
||||||
echo "$(basename "${0}") get latest : get latest stable release"
|
echo "$(basename "${0}") check stable : check for new stable release"
|
||||||
echo "$(basename "${0}") get master : get master branch"
|
echo "$(basename "${0}") get stable : change to latest stable release"
|
||||||
echo "$(basename "${0}") get <version> : get a specific version"
|
echo "$(basename "${0}") get unstable : change to latest unstable"
|
||||||
echo "$(basename "${0}") get branch <branch> : get a specific version"
|
echo "$(basename "${0}") get version <version> : change to a specific version"
|
||||||
|
echo "$(basename "${0}") get branch <branch> : change to a specific branch"
|
||||||
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
[ "$1" = "" ] && usage && exit 1
|
########################
|
||||||
[ "$1" != "current" ] && \
|
## entry point
|
||||||
[ "$1" != "releases" ] && \
|
########################
|
||||||
[ "$1" != "get" ] && \
|
|
||||||
[ "$1" != "branches" ] && \
|
[ "$1" = "" ] && usage
|
||||||
|
[ "$1" != "print" ] && \
|
||||||
[ "$1" != "check" ] && \
|
[ "$1" != "check" ] && \
|
||||||
usage && exit 1
|
[ "$1" != "get" ] && \
|
||||||
[ "$1" = "get" ] && [ "$2" = "" ] && usage && exit 1
|
usage
|
||||||
[ "$1" = "get" ] && [ "$2" = "branch" ] && [ "$3" = "" ] && usage && exit 1
|
[ "$2" = "" ] && usage
|
||||||
|
|
||||||
move_to_base
|
move_to_base
|
||||||
|
|
||||||
if [ "$1" = "current" ]; then
|
if [ "$1" = "print" ]; then
|
||||||
get_current
|
if [ "$2" = "current" ]; then
|
||||||
elif [ "$1" = "releases" ]; then
|
get_current
|
||||||
get_releases
|
elif [ "$2" = "releases" ]; then
|
||||||
elif [ "$1" = "branches" ]; then
|
get_releases
|
||||||
get_branches
|
elif [ "$2" = "branches" ]; then
|
||||||
elif [ "$1" = "check" ]; then
|
get_branches
|
||||||
need_update
|
|
||||||
elif [ "$1" = "get" ]; then
|
|
||||||
if [ "$2" = "latest" ]; then
|
|
||||||
checkout_last_tag
|
|
||||||
elif [ "$2" = "master" ]; then
|
|
||||||
checkout_branch master
|
|
||||||
elif [ "$2" = "branch" ]; then
|
|
||||||
checkout_branch "${3}"
|
|
||||||
else
|
else
|
||||||
checkout_tag "${2}"
|
usage
|
||||||
|
fi
|
||||||
|
elif [ "$1" = "check" ]; then
|
||||||
|
if [ "$2" = "stable" ]; then
|
||||||
|
get_current
|
||||||
|
need_update_stable
|
||||||
|
elif [ "$2" = "unstable" ]; then
|
||||||
|
get_current
|
||||||
|
need_update
|
||||||
|
else
|
||||||
|
usage
|
||||||
|
fi
|
||||||
|
elif [ "$1" = "get" ]; then
|
||||||
|
if [ "$2" = "stable" ]; then
|
||||||
|
checkout_last_tag
|
||||||
|
get_current
|
||||||
|
elif [ "$2" = "unstable" ]; then
|
||||||
|
checkout_branch master
|
||||||
|
get_current
|
||||||
|
elif [ "$2" = "branch" ]; then
|
||||||
|
[ "$3" = "" ] && usage
|
||||||
|
checkout_branch "${3}"
|
||||||
|
get_current
|
||||||
|
elif [ "$2" = "version" ]; then
|
||||||
|
[ "$3" = "" ] && usage
|
||||||
|
checkout_tag "${3}"
|
||||||
|
get_current
|
||||||
|
else
|
||||||
|
usage
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user