From e6a246f0408eaa688ac3d81bac6dcdac8f9a12b8 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Dec 2018 20:03:46 +0000 Subject: [PATCH 1/7] Chop up contrib/semver/version.sh --- contrib/semver/version.sh | 61 +++++++++------------------------------ 1 file changed, 14 insertions(+), 47 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 964a3208..37fc524f 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -1,63 +1,30 @@ #!/bin/sh -# Merge commits from this branch are counted -DEVELOPBRANCH="yggdrasil-network/develop" - # Get the last tag -TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.0" 2>/dev/null) +TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) +test $? != 0 && (echo "unknown"; exit 1) -# Get last merge to master -MERGE=$(git rev-list $TAG..master --grep "from $DEVELOPBRANCH" 2>/dev/null | head -n 1) - -# Get the number of merges since the last merge to master -PATCH=$(git rev-list $TAG..master --count --merges --grep="from $DEVELOPBRANCH" --first-parent master 2>/dev/null) - -# Decide whether we should prepend the version with "v" - the default is that -# we do because we use it in git tags, but we might not always need it -PREPEND="v" -if [ "$1" = "--bare" ]; then - PREPEND="" -fi - -# If it fails then there's no last tag - go from the first commit -if [ $? != 0 ]; then - PATCH=$(git rev-list HEAD --count 2>/dev/null) - - # Complain if the git history is not available - if [ $? != 0 ]; then - printf 'unknown' - exit 1 - fi - - printf '%s0.0.%d' "$PREPEND" "$PATCH" - exit 1 -fi +# Get the current branch +BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null) +test $? != 0 && BRANCH="master" # Split out into major, minor and patch numbers MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1) MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2) - -# Get the current checked out branch -BRANCH=$(git rev-parse --abbrev-ref HEAD) +PATCH=$(echo $TAG | cut -c 2- | cut -d "." -f 3) # Output in the desired format -if [ $PATCH = 0 ]; then - if [ ! -z $FULL ]; then - printf '%s%d.%d.0' "$PREPEND" "$MAJOR" "$MINOR" - else - printf '%s%d.%d' "$PREPEND" "$MAJOR" "$MINOR" - fi +if [ $((PATCH)) -eq 0 ]; then + printf '%s%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" else - printf '%s%d.%d.%d' "$PREPEND" "$MAJOR" "$MINOR" "$PATCH" + printf '%s%d.%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" "$((PATCH))" fi -# Get the number of merges on the current branch since the last tag -TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" --first-parent master 2>/dev/null) -BUILD=$(git rev-list $TAG.. --count) - # Add the build tag on non-master branches -if [ $BRANCH != "master" ]; then - if [ $BUILD != 0 ]; then - printf -- "-%04d" "$BUILD" +if [ "$BRANCH" != "master" ]; then + BUILD=$(git rev-list $TAG..HEAD --count) + + if [ $? == 0 ] && [ $((BUILD)) -gt 0 ]; then + printf -- "-%04d" "$((BUILD))" fi fi From 57894541b78dc1b597103a0fd15b82d073780935 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Dec 2018 21:14:23 +0000 Subject: [PATCH 2/7] Check string emptiness --- contrib/semver/version.sh | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 37fc524f..14dafa15 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -2,11 +2,11 @@ # Get the last tag TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) -test $? != 0 && (echo "unknown"; exit 1) +(test $? != 0 || test -z "$TAG") && (echo "unknown"; exit 1) # Get the current branch BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null) -test $? != 0 && BRANCH="master" +(test $? != 0 || test -z "$BRANCH") && BRANCH="master" # Split out into major, minor and patch numbers MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1) @@ -23,8 +23,9 @@ fi # Add the build tag on non-master branches if [ "$BRANCH" != "master" ]; then BUILD=$(git rev-list $TAG..HEAD --count) - - if [ $? == 0 ] && [ $((BUILD)) -gt 0 ]; then - printf -- "-%04d" "$((BUILD))" + if [ $? = 0 ] && [ -n "$BUILD" ]; then + if [ $((BUILD)) -gt 0 ]; then + printf -- "-%04d" "$((BUILD))" + fi fi fi From 7eaee172cf22e5b54a619a2a08c233f83511224c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Dec 2018 21:22:46 +0000 Subject: [PATCH 3/7] Replace tests with ifs --- contrib/semver/version.sh | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 14dafa15..ca035ff5 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -2,11 +2,20 @@ # Get the last tag TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/null) -(test $? != 0 || test -z "$TAG") && (echo "unknown"; exit 1) + +# Did getting the tag succeed? +if [ $? != 0 ] || [ -z "$TAG" ]; then + printf "unknown" + exit 1 +fi # Get the current branch BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null) -(test $? != 0 || test -z "$BRANCH") && BRANCH="master" + +# Did getting the branch succeed? +if [ $? != 0 ] || [ -z "$BRANCH" ]; then + BRANCH="master" +fi # Split out into major, minor and patch numbers MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1) @@ -22,10 +31,15 @@ fi # Add the build tag on non-master branches if [ "$BRANCH" != "master" ]; then - BUILD=$(git rev-list $TAG..HEAD --count) - if [ $? = 0 ] && [ -n "$BUILD" ]; then - if [ $((BUILD)) -gt 0 ]; then - printf -- "-%04d" "$((BUILD))" - fi + BUILD=$(git rev-list $TAG..HEAD --count 2>/dev/null) + + # Did getting the count of commits since the tag succeed? + if [ $? != 0 ] && [ -z "$BUILD" ]; then + exit 1 + fi + + # Is the build greater than zero? + if [ $((BUILD)) -gt 0 ]; then + printf -- "-%04d" "$((BUILD))" fi fi From 6fcd8a8dbdb290a045e7d54b84e59df425859837 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Dec 2018 21:36:50 +0000 Subject: [PATCH 4/7] Fix incorrect check --- contrib/semver/version.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index ca035ff5..7d4f3736 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -5,7 +5,7 @@ TAG=$(git describe --abbrev=0 --tags --match="v[0-9]*\.[0-9]*\.[0-9]*" 2>/dev/nu # Did getting the tag succeed? if [ $? != 0 ] || [ -z "$TAG" ]; then - printf "unknown" + printf -- "unknown" exit 1 fi @@ -34,7 +34,8 @@ if [ "$BRANCH" != "master" ]; then BUILD=$(git rev-list $TAG..HEAD --count 2>/dev/null) # Did getting the count of commits since the tag succeed? - if [ $? != 0 ] && [ -z "$BUILD" ]; then + if [ $? != 0 ] || [ -z "$BUILD" ]; then + printf -- "-unknown" exit 1 fi From 8c7b9e2f90f2b1ce8f432295599acdcb1b963e0c Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Dec 2018 21:44:29 +0000 Subject: [PATCH 5/7] Add a null check to name.sh --- contrib/semver/name.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/semver/name.sh b/contrib/semver/name.sh index 935cc750..1fa2ce07 100644 --- a/contrib/semver/name.sh +++ b/contrib/semver/name.sh @@ -4,8 +4,8 @@ BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) # Complain if the git history is not available -if [ $? != 0 ]; then - printf "unknown" +if [ $? != 0 ] || [ -z "$BRANCH" ]; then + printf "yggdrasil" exit 1 fi From e6e7f9377f47c5101ac20bccf9782361eeafb6e6 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Thu, 27 Dec 2018 21:45:30 +0000 Subject: [PATCH 6/7] Move --count parameter --- contrib/semver/version.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/semver/version.sh b/contrib/semver/version.sh index 7d4f3736..3052094a 100644 --- a/contrib/semver/version.sh +++ b/contrib/semver/version.sh @@ -31,7 +31,7 @@ fi # Add the build tag on non-master branches if [ "$BRANCH" != "master" ]; then - BUILD=$(git rev-list $TAG..HEAD --count 2>/dev/null) + BUILD=$(git rev-list --count $TAG..HEAD 2>/dev/null) # Did getting the count of commits since the tag succeed? if [ $? != 0 ] || [ -z "$BUILD" ]; then From fb47c9822fc62acae64e41aaf1cea6617ad42457 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Mon, 31 Dec 2018 11:48:50 +0000 Subject: [PATCH 7/7] getNodeInfo: Show own info if box_pub_key/coords not specified --- src/yggdrasil/admin.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/yggdrasil/admin.go b/src/yggdrasil/admin.go index bd3c9051..2496b309 100644 --- a/src/yggdrasil/admin.go +++ b/src/yggdrasil/admin.go @@ -324,12 +324,27 @@ func (a *admin) init(c *Core, listenaddr string) { return admin_info{}, err } }) - a.addHandler("getNodeInfo", []string{"box_pub_key", "coords", "[nocache]"}, func(in admin_info) (admin_info, error) { + a.addHandler("getNodeInfo", []string{"[box_pub_key]", "[coords]", "[nocache]"}, func(in admin_info) (admin_info, error) { var nocache bool if in["nocache"] != nil { nocache = in["nocache"].(string) == "true" } - result, err := a.admin_getNodeInfo(in["box_pub_key"].(string), in["coords"].(string), nocache) + var box_pub_key, coords string + if in["box_pub_key"] == nil && in["coords"] == nil { + nodeinfo := []byte(a.core.nodeinfo.getNodeInfo()) + var jsoninfo interface{} + if err := json.Unmarshal(nodeinfo, &jsoninfo); err != nil { + return admin_info{}, err + } else { + return admin_info{"nodeinfo": jsoninfo}, nil + } + } else if in["box_pub_key"] == nil || in["coords"] == nil { + return admin_info{}, errors.New("Expecting both box_pub_key and coords") + } else { + box_pub_key = in["box_pub_key"].(string) + coords = in["coords"].(string) + } + result, err := a.admin_getNodeInfo(box_pub_key, coords, nocache) if err == nil { var m map[string]interface{} if err = json.Unmarshal(result, &m); err == nil {