1#!/bin/bash 2# 3# Copyright The Mbed TLS Contributors 4# SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later 5# 6# Purpose 7# 8# Sets the version numbers in the source code to those given. 9# 10# Usage: bump_version.sh [ --version <version> ] [ --so-crypto <version>] 11# [ --so-x509 <version> ] [ --so-tls <version> ] 12# [ -v | --verbose ] [ -h | --help ] 13# 14 15VERSION="" 16SOVERSION="" 17 18# Parse arguments 19# 20until [ -z "$1" ] 21do 22 case "$1" in 23 --version) 24 # Version to use 25 shift 26 VERSION=$1 27 ;; 28 --so-crypto) 29 shift 30 SO_CRYPTO=$1 31 ;; 32 --so-x509) 33 shift 34 SO_X509=$1 35 ;; 36 --so-tls) 37 shift 38 SO_TLS=$1 39 ;; 40 -v|--verbose) 41 # Be verbose 42 VERBOSE="1" 43 ;; 44 -h|--help) 45 # print help 46 echo "Usage: $0" 47 echo -e " -h|--help\t\tPrint this help." 48 echo -e " --version <version>\tVersion to bump to." 49 echo -e " --so-crypto <version>\tSO version to bump libmbedcrypto to." 50 echo -e " --so-x509 <version>\tSO version to bump libmbedx509 to." 51 echo -e " --so-tls <version>\tSO version to bump libmbedtls to." 52 echo -e " -v|--verbose\t\tVerbose." 53 exit 1 54 ;; 55 *) 56 # print error 57 echo "Unknown argument: '$1'" 58 exit 1 59 ;; 60 esac 61 shift 62done 63 64if [ "X" = "X$VERSION" ]; 65then 66 echo "No version specified. Unable to continue." 67 exit 1 68fi 69 70[ $VERBOSE ] && echo "Bumping VERSION in library/CMakeLists.txt" 71sed -e "s/ VERSION [0-9.]\{1,\}/ VERSION $VERSION/g" < library/CMakeLists.txt > tmp 72mv tmp library/CMakeLists.txt 73 74if [ "X" != "X$SO_CRYPTO" ]; 75then 76 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/CMakeLists.txt" 77 sed -e "/mbedcrypto/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_CRYPTO/g" < library/CMakeLists.txt > tmp 78 mv tmp library/CMakeLists.txt 79 80 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedcrypto in library/Makefile" 81 sed -e "s/SOEXT_CRYPTO=so.[0-9]\{1,\}/SOEXT_CRYPTO=so.$SO_CRYPTO/g" < library/Makefile > tmp 82 mv tmp library/Makefile 83fi 84 85if [ "X" != "X$SO_X509" ]; 86then 87 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/CMakeLists.txt" 88 sed -e "/mbedx509/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_X509/g" < library/CMakeLists.txt > tmp 89 mv tmp library/CMakeLists.txt 90 91 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedx509 in library/Makefile" 92 sed -e "s/SOEXT_X509=so.[0-9]\{1,\}/SOEXT_X509=so.$SO_X509/g" < library/Makefile > tmp 93 mv tmp library/Makefile 94fi 95 96if [ "X" != "X$SO_TLS" ]; 97then 98 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/CMakeLists.txt" 99 sed -e "/mbedtls/ s/ SOVERSION [0-9]\{1,\}/ SOVERSION $SO_TLS/g" < library/CMakeLists.txt > tmp 100 mv tmp library/CMakeLists.txt 101 102 [ $VERBOSE ] && echo "Bumping SOVERSION for libmbedtls in library/Makefile" 103 sed -e "s/SOEXT_TLS=so.[0-9]\{1,\}/SOEXT_TLS=so.$SO_TLS/g" < library/Makefile > tmp 104 mv tmp library/Makefile 105fi 106 107[ $VERBOSE ] && echo "Bumping VERSION in include/mbedtls/version.h" 108read MAJOR MINOR PATCH <<<$(IFS="."; echo $VERSION) 109VERSION_NR="$( printf "0x%02X%02X%02X00" $MAJOR $MINOR $PATCH )" 110cat include/mbedtls/version.h | \ 111 sed -e "s/_VERSION_MAJOR .\{1,\}/_VERSION_MAJOR $MAJOR/" | \ 112 sed -e "s/_VERSION_MINOR .\{1,\}/_VERSION_MINOR $MINOR/" | \ 113 sed -e "s/_VERSION_PATCH .\{1,\}/_VERSION_PATCH $PATCH/" | \ 114 sed -e "s/_VERSION_NUMBER .\{1,\}/_VERSION_NUMBER $VERSION_NR/" | \ 115 sed -e "s/_VERSION_STRING .\{1,\}/_VERSION_STRING \"$VERSION\"/" | \ 116 sed -e "s/_VERSION_STRING_FULL .\{1,\}/_VERSION_STRING_FULL \"Mbed TLS $VERSION\"/" \ 117 > tmp 118mv tmp include/mbedtls/version.h 119 120[ $VERBOSE ] && echo "Bumping version in tests/suites/test_suite_version.data" 121sed -e "s/version:\".\{1,\}/version:\"$VERSION\"/g" < tests/suites/test_suite_version.data > tmp 122mv tmp tests/suites/test_suite_version.data 123 124[ $VERBOSE ] && echo "Bumping PROJECT_NAME in doxygen/mbedtls.doxyfile and doxygen/input/doc_mainpage.h" 125for i in doxygen/mbedtls.doxyfile doxygen/input/doc_mainpage.h; 126do 127 sed -e "s/\\([Mm]bed TLS v\\)[0-9][0-9.]*/\\1$VERSION/g" < $i > tmp 128 mv tmp $i 129done 130 131[ $VERBOSE ] && echo "Re-generating library/error.c" 132scripts/generate_errors.pl 133 134[ $VERBOSE ] && echo "Re-generating programs/test/query_config.c" 135scripts/generate_query_config.pl 136 137[ $VERBOSE ] && echo "Re-generating library/version_features.c" 138scripts/generate_features.pl 139 140[ $VERBOSE ] && echo "Re-generating visualc files" 141scripts/generate_visualc_files.pl 142 143