diff --git a/driver-describe.sh b/driver-describe.sh new file mode 100755 index 0000000..71e32b4 --- /dev/null +++ b/driver-describe.sh @@ -0,0 +1,29 @@ +#!/bin/bash + +set -exo pipefail +# This script outputs a version string (along the lines of git-describe) +# to identify the driver version currently in use, starting from tags +# in falcosecurity/libs (or its fork draios/agent-libs). + +# to be called from that directory + +git version >/dev/null || (echo "Please install git" && exit 1) + +[[ -e .git && -e driver/ ]] || (echo "Please run this script from the root folder of the agent-libs git workspace" && exit 1) + +LAST_COMMIT=$(git log -1 --pretty=format:"%h") +# TODO find a better name for tag prefix +LAST_TAG=$(git describe --tags --abbrev=0 --match "driver-*" || echo "") +if [[ -n "$LAST_TAG" ]]; then + LAST_VERSION=$(echo $LAST_TAG | cut -c 8-) # TODO beware of driver- prefix + # Check the number of commits which *actually* changed _something_ in driver/ + N_COMMITS=$(git log --oneline ...${LAST_TAG} -- driver/ | wc -l) + if [[ ${N_COMMITS} -gt 0 ]]; then + echo "${LAST_VERSION}-${N_COMMITS}-${LAST_COMMIT}" + else + echo "${LAST_VERSION}" + fi +else + # We couldn't find a tag, let's make something up + echo "0.0.0-0-${LAST_COMMIT}" +fi diff --git a/sysdig-probe-loader b/sysdig-probe-loader index 3d7e86a..a576111 100755 --- a/sysdig-probe-loader +++ b/sysdig-probe-loader @@ -730,7 +730,14 @@ if [ "${SCRIPT_NAME}" = "sysdig-probe-loader" ]; then PACKAGE_NAME="sysdig" elif [ "${SCRIPT_NAME}" = "sysdigcloud-probe-loader" ]; then EXEPATH=$(dirname "$(readlink -f "${0}")") + # If we were give a SYSDIG_VERSION (which is, indeed, a DRIVER_VERSION), we can just accept it. + # Otherwise, we look for one. if [ -z "$SYSDIG_VERSION" ]; then + # Look for an explicit driver version requirement, if we have one + SYSDIG_VERSION=$(sed -n -e 's/driver version: \(.*\)/\1/p' /opt/draios/etc/.agent_build) + fi + if [ -z "$SYSDIG_VERSION" ]; then + # As a fallback, look for the exact version (this should be the case up to 12.11.0) SYSDIG_VERSION=$("${EXEPATH}"/dragent --version) fi PROBE_NAME="sysdigcloud-probe" @@ -770,4 +777,4 @@ if [ $? -eq 1 ]; then exit 1 fi echo "Probe loaded" -exit 0 \ No newline at end of file +exit 0