5
0
mirror of https://github.com/cwinfo/yggdrasil-go.git synced 2024-11-26 17:41:36 +00:00

Merge branch 'develop' into nodeconfig

This commit is contained in:
Neil Alexander 2018-12-31 11:55:37 +00:00
commit 4d3e90cbfe
No known key found for this signature in database
GPG Key ID: A02A2019A2BB0944
3 changed files with 45 additions and 47 deletions

View File

@ -4,8 +4,8 @@
BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null) BRANCH=$(git symbolic-ref --short HEAD 2>/dev/null)
# Complain if the git history is not available # Complain if the git history is not available
if [ $? != 0 ]; then if [ $? != 0 ] || [ -z "$BRANCH" ]; then
printf "unknown" printf "yggdrasil"
exit 1 exit 1
fi fi

View File

@ -1,63 +1,46 @@
#!/bin/sh #!/bin/sh
# Merge commits from this branch are counted
DEVELOPBRANCH="yggdrasil-network/develop"
# Get the last tag # 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)
# Get last merge to master # Did getting the tag succeed?
MERGE=$(git rev-list $TAG..master --grep "from $DEVELOPBRANCH" 2>/dev/null | head -n 1) if [ $? != 0 ] || [ -z "$TAG" ]; then
printf -- "unknown"
# Get the number of merges since the last merge to master exit 1
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 fi
# If it fails then there's no last tag - go from the first commit # Get the current branch
if [ $? != 0 ]; then BRANCH=$(git symbolic-ref -q HEAD --short 2>/dev/null)
PATCH=$(git rev-list HEAD --count 2>/dev/null)
# Complain if the git history is not available # Did getting the branch succeed?
if [ $? != 0 ]; then if [ $? != 0 ] || [ -z "$BRANCH" ]; then
printf 'unknown' BRANCH="master"
exit 1
fi
printf '%s0.0.%d' "$PREPEND" "$PATCH"
exit 1
fi fi
# Split out into major, minor and patch numbers # Split out into major, minor and patch numbers
MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1) MAJOR=$(echo $TAG | cut -c 2- | cut -d "." -f 1)
MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2) MINOR=$(echo $TAG | cut -c 2- | cut -d "." -f 2)
PATCH=$(echo $TAG | cut -c 2- | cut -d "." -f 3)
# Get the current checked out branch
BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Output in the desired format # Output in the desired format
if [ $PATCH = 0 ]; then if [ $((PATCH)) -eq 0 ]; then
if [ ! -z $FULL ]; then printf '%s%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))"
printf '%s%d.%d.0' "$PREPEND" "$MAJOR" "$MINOR"
else
printf '%s%d.%d' "$PREPEND" "$MAJOR" "$MINOR"
fi
else else
printf '%s%d.%d.%d' "$PREPEND" "$MAJOR" "$MINOR" "$PATCH" printf '%s%d.%d.%d' "$PREPEND" "$((MAJOR))" "$((MINOR))" "$((PATCH))"
fi 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 # Add the build tag on non-master branches
if [ $BRANCH != "master" ]; then if [ "$BRANCH" != "master" ]; then
if [ $BUILD != 0 ]; then BUILD=$(git rev-list --count $TAG..HEAD 2>/dev/null)
printf -- "-%04d" "$BUILD"
# Did getting the count of commits since the tag succeed?
if [ $? != 0 ] || [ -z "$BUILD" ]; then
printf -- "-unknown"
exit 1
fi
# Is the build greater than zero?
if [ $((BUILD)) -gt 0 ]; then
printf -- "-%04d" "$((BUILD))"
fi fi
fi fi

View File

@ -343,12 +343,27 @@ func (a *admin) init(c *Core) {
return admin_info{}, err 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 var nocache bool
if in["nocache"] != nil { if in["nocache"] != nil {
nocache = in["nocache"].(string) == "true" 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 { if err == nil {
var m map[string]interface{} var m map[string]interface{}
if err = json.Unmarshal(result, &m); err == nil { if err = json.Unmarshal(result, &m); err == nil {