github.com/decred/dcrlnd@v0.7.6/scripts/release.sh (about) 1 #!/bin/bash 2 3 # Simple bash script to build basic lnd tools for all the platforms 4 # we support with the golang cross-compiler. 5 # 6 # Copyright (c) 2016 Company 0, LLC. 7 # Use of this source code is governed by the ISC 8 # license. 9 10 set -e 11 12 LND_VERSION_REGEX="lnd version (.+) commit" 13 PKG="github.com/lightningnetwork/lnd" 14 PACKAGE=lnd 15 16 # Needed for setting file timestamps to get reproducible archives. 17 BUILD_DATE="2020-01-01 00:00:00" 18 BUILD_DATE_STAMP="202001010000.00" 19 20 # reproducible_tar_gzip creates a reproducible tar.gz file of a directory. This 21 # includes setting all file timestamps and ownership settings uniformly. 22 function reproducible_tar_gzip() { 23 local dir=$1 24 local tar_cmd=tar 25 26 # MacOS has a version of BSD tar which doesn't support setting the --mtime 27 # flag. We need gnu-tar, or gtar for short to be installed for this script to 28 # work properly. 29 tar_version=$(tar --version) 30 if [[ ! "$tar_version" =~ "GNU tar" ]]; then 31 if ! command -v "gtar"; then 32 echo "GNU tar is required but cannot be found!" 33 echo "On MacOS please run 'brew install gnu-tar' to install gtar." 34 exit 1 35 fi 36 37 # We have gtar installed, use that instead. 38 tar_cmd=gtar 39 fi 40 41 # Pin down the timestamp time zone. 42 export TZ=UTC 43 44 find "${dir}" -print0 | LC_ALL=C sort -r -z | $tar_cmd \ 45 "--mtime=${BUILD_DATE}" --no-recursion --null --mode=u+rw,go+r-w,a+X \ 46 --owner=0 --group=0 --numeric-owner -c -T - | gzip -9n > "${dir}.tar.gz" 47 48 rm -r "${dir}" 49 } 50 51 # reproducible_zip creates a reproducible zip file of a directory. This 52 # includes setting all file timestamps. 53 function reproducible_zip() { 54 local dir=$1 55 56 # Pin down file name encoding and timestamp time zone. 57 export TZ=UTC 58 59 # Set the date of each file in the directory that's about to be packaged to 60 # the same timestamp and make sure the same permissions are used everywhere. 61 chmod -R 0755 "${dir}" 62 touch -t "${BUILD_DATE_STAMP}" "${dir}" 63 find "${dir}" -print0 | LC_ALL=C sort -r -z | xargs -0r touch \ 64 -t "${BUILD_DATE_STAMP}" 65 66 find "${dir}" | LC_ALL=C sort -r | zip -o -X -r -@ "${dir}.zip" 67 68 rm -r "${dir}" 69 } 70 71 # green prints one line of green text (if the terminal supports it). 72 function green() { 73 echo -e "\e[0;32m${1}\e[0m" 74 } 75 76 # Extract version command output. 77 LND_VERSION_OUTPUT=`./dcrlnd --version` 78 79 # Use a regex to isolate the version string. 80 LND_VERSION_REGEX="dcrlnd version (.+) commit" 81 if [[ $LND_VERSION_OUTPUT =~ $LND_VERSION_REGEX ]]; then 82 # Prepend 'v' to match git tag naming scheme. 83 LND_VERSION="v${BASH_REMATCH[1]}" 84 echo "version: $LND_VERSION" 85 86 # If tag contains a release candidate suffix, append this suffix to the 87 # lnd reported version before we compare. 88 RC_REGEX="-rc[0-9]+$" 89 if [[ $TAG =~ $RC_REGEX ]]; then 90 LND_VERSION+=${BASH_REMATCH[0]} 91 fi 92 93 # Match git tag with lnd version. 94 if [[ $TAG != $LND_VERSION ]]; then 95 echo "dcrlnd version $LND_VERSION does not match tag $TAG" 96 exit 1 97 fi 98 else 99 echo "malformed dcrlnd version output" 100 exit 1 101 fi 102 103 PACKAGE=dcrlnd 104 MAINDIR=$PACKAGE-$TAG 105 106 mkdir -p releases/$MAINDIR 107 108 green " - Packaging vendor" 109 go mod vendor 110 reproducible_tar_gzip vendor 111 112 maindir=$PACKAGE-$tag 113 mkdir -p $maindir 114 mv vendor.tar.gz "${maindir}/" 115 116 # Don't use tag in source directory, otherwise our file names get too long and 117 # tar starts to package them non-deterministically. 118 package_source="${PACKAGE}-source" 119 120 # The git archive command doesn't support setting timestamps and file 121 # permissions. That's why we unpack the tar again, then use our reproducible 122 # method to create the final archive. 123 git archive -o "${maindir}/${package_source}.tar" HEAD 124 125 cd "${maindir}" 126 mkdir -p ${package_source} 127 tar -xf "${package_source}.tar" -C ${package_source} 128 rm "${package_source}.tar" 129 reproducible_tar_gzip ${package_source} 130 mv "${package_source}.tar.gz" "${package_source}-$tag.tar.gz" 131 132 # Use the first element of $GOPATH in the case where GOPATH is a list 133 # (something that is totally allowed). 134 PKG="github.com/decred/dcrlnd" 135 COMMIT=$(git describe --abbrev=40 --dirty) 136 COMMITFLAGS="-X $PKG/build.PreRelease= -X $PKG/build.BuildMetadata=release -X $PKG/build.Commit=$COMMIT" 137 138 for i in $SYS; do 139 OS=$(echo $i | cut -f1 -d-) 140 ARCH=$(echo $i | cut -f2 -d-) 141 ARM= 142 143 if [[ $ARCH = "armv6" ]]; then 144 ARCH=arm 145 ARM=6 146 elif [[ $ARCH = "armv7" ]]; then 147 ARCH=arm 148 ARM=7 149 fi 150 151 dir="${PACKAGE}-${i}-${tag}" 152 mkdir "${dir}" 153 pushd "${dir}" 154 155 echo "Building:" $OS $ARCH $ARM 156 env CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH GOARM=$ARM go build -v -trimpath -ldflags "-s -w -buildid= $COMMITFLAGS" github.com/decred/dcrlnd/cmd/dcrlnd 157 env CGO_ENABLED=0 GOOS=$OS GOARCH=$ARCH GOARM=$ARM go build -v -trimpath -ldflags "-s -w -buildid= $COMMITFLAGS" github.com/decred/dcrlnd/cmd/dcrlncli 158 cd .. 159 160 # Add the hashes for the individual binaries as well for easy verification 161 # of a single installed binary. 162 shasum -a 256 "${dir}/"* >> "manifest-$tag.txt" 163 164 if [[ $os == "windows" ]]; then 165 reproducible_zip "${dir}" 166 else 167 reproducible_tar_gzip "${dir}" 168 fi 169 done 170 171 # Add the hash of the packages too, then sort by the second column (name). 172 shasum -a 256 lnd-* vendor* >> "manifest-$tag.txt" 173 LC_ALL=C sort -k2 -o "manifest-$tag.txt" "manifest-$tag.txt" 174 cat "manifest-$tag.txt" 175 } 176 177 # usage prints the usage of the whole script. 178 function usage() { 179 red "Usage: " 180 red "release.sh check-tag <version-tag>" 181 red "release.sh build-release <version-tag> <build-system(s)> <build-tags> <ldflags>" 182 } 183 184 # Whatever sub command is passed in, we need at least 2 arguments. 185 if [ "$#" -lt 2 ]; then 186 usage 187 exit 1 188 fi 189 190 shasum -a 256 * > manifest-$PACKAGE-$TAG.txt