2019-07-17 13:37:18 -04:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
BUILD_PATH=$1
|
|
|
|
|
|
|
|
function debug() {
|
|
|
|
#eval ""
|
|
|
|
echo "${@}"
|
|
|
|
}
|
|
|
|
|
|
|
|
VERSION_FILE="build_version.txt"
|
|
|
|
if [[ -f ${VERSION_FILE} ]]; then
|
|
|
|
rm ${VERSION_FILE}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -z ${BUILD_PATH} ]]; then
|
|
|
|
echo "Missing versions path!"
|
|
|
|
#exit 1
|
|
|
|
fi
|
|
|
|
|
2020-01-24 13:39:43 -05:00
|
|
|
CURRENT_VERSION=$(cat env/buildVersion.txt)
|
2019-07-17 13:37:18 -04:00
|
|
|
CURRENT_VERSION_ESCAPED=$(echo "${CURRENT_VERSION}" | sed -e 's/[\/&\.\-]/\\&/g')
|
2020-01-24 13:39:43 -05:00
|
|
|
AVAILABLE_VERSIONS=$(ssh -i build_private_key TeaSpeak-Jenkins@mcgalaxy.de "
|
2019-07-17 13:37:18 -04:00
|
|
|
if [ -d versions/${BUILD_PATH} ]; then
|
|
|
|
ls versions/${BUILD_PATH} | grep -E '^${CURRENT_VERSION_ESCAPED}(\-[0-9]+)?$'
|
|
|
|
fi
|
2020-01-24 13:39:43 -05:00
|
|
|
")
|
2019-07-17 13:37:18 -04:00
|
|
|
debug "${AVAILABLE_VERSIONS}"
|
|
|
|
|
|
|
|
TARGET_VERSION=""
|
|
|
|
TARGET_VERSION_INDEX=0
|
|
|
|
|
|
|
|
while [[ true ]]; do
|
|
|
|
if [[ ! ${TARGET_VERSION_INDEX} -eq 0 ]]; then
|
|
|
|
TARGET_VERSION="${CURRENT_VERSION}-${TARGET_VERSION_INDEX}"
|
|
|
|
else
|
|
|
|
TARGET_VERSION="${CURRENT_VERSION}"
|
|
|
|
fi
|
|
|
|
debug "Testing => ${TARGET_VERSION}"
|
|
|
|
debug "${AVAILABLE_VERSIONS}" | grep "${TARGET_VERSION}" &>/dev/null
|
|
|
|
if [[ $? -ne 0 ]]; then
|
|
|
|
debug "Found version ${TARGET_VERSION}"
|
|
|
|
break
|
|
|
|
fi
|
|
|
|
|
|
|
|
TARGET_VERSION_INDEX=$(($TARGET_VERSION_INDEX+1))
|
|
|
|
done
|
|
|
|
|
|
|
|
echo "${TARGET_VERSION} ${CURRENT_VERSION} ${TARGET_VERSION_INDEX} TeaSpeak-${TARGET_VERSION}.tar.gz" > ${VERSION_FILE}
|