|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Simple bash script to build basic lndinit for all the platforms we support |
| 4 | +# 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 | +PKG="github.com/lightninglabs/lndinit" |
| 13 | +PACKAGE=lndinit |
| 14 | + |
| 15 | +# green prints one line of green text (if the terminal supports it). |
| 16 | +function green() { |
| 17 | + echo -e "\e[0;32m${1}\e[0m" |
| 18 | +} |
| 19 | + |
| 20 | +# red prints one line of red text (if the terminal supports it). |
| 21 | +function red() { |
| 22 | + echo -e "\e[0;31m${1}\e[0m" |
| 23 | +} |
| 24 | + |
| 25 | +# build_release builds the actual release binaries. |
| 26 | +# arguments: <version-tag> <build-system(s)> <ldflags> |
| 27 | +function build_release() { |
| 28 | + local tag=$1 |
| 29 | + local sys=$2 |
| 30 | + local ldflags=$3 |
| 31 | + |
| 32 | + green " - Packaging vendor" |
| 33 | + go mod vendor |
| 34 | + tar -czf vendor.tar.gz vendor |
| 35 | + |
| 36 | + maindir=$PACKAGE-$tag |
| 37 | + mkdir -p $maindir |
| 38 | + |
| 39 | + cp vendor.tar.gz $maindir/ |
| 40 | + rm vendor.tar.gz |
| 41 | + rm -r vendor |
| 42 | + |
| 43 | + package_source="${maindir}/${PACKAGE}-source-${tag}.tar" |
| 44 | + git archive -o "${package_source}" HEAD |
| 45 | + gzip -f "${package_source}" >"${package_source}.gz" |
| 46 | + |
| 47 | + cd "${maindir}" |
| 48 | + |
| 49 | + for i in $sys; do |
| 50 | + os=$(echo $i | cut -f1 -d-) |
| 51 | + arch=$(echo $i | cut -f2 -d-) |
| 52 | + arm= |
| 53 | + |
| 54 | + if [[ $arch == "armv6" ]]; then |
| 55 | + arch=arm |
| 56 | + arm=6 |
| 57 | + elif [[ $arch == "armv7" ]]; then |
| 58 | + arch=arm |
| 59 | + arm=7 |
| 60 | + fi |
| 61 | + |
| 62 | + dir="${PACKAGE}-${i}-${tag}" |
| 63 | + mkdir "${dir}" |
| 64 | + pushd "${dir}" |
| 65 | + |
| 66 | + green " - Building: ${os} ${arch} ${arm}" |
| 67 | + env CGO_ENABLED=0 GOOS=$os GOARCH=$arch GOARM=$arm go build -v -trimpath -ldflags="${ldflags}" ${PKG} |
| 68 | + popd |
| 69 | + |
| 70 | + if [[ $os == "windows" ]]; then |
| 71 | + zip -r "${dir}.zip" "${dir}" |
| 72 | + else |
| 73 | + tar -cvzf "${dir}.tar.gz" "${dir}" |
| 74 | + fi |
| 75 | + |
| 76 | + rm -r "${dir}" |
| 77 | + done |
| 78 | + |
| 79 | + shasum -a 256 * >manifest-$tag.txt |
| 80 | +} |
| 81 | + |
| 82 | +# usage prints the usage of the whole script. |
| 83 | +function usage() { |
| 84 | + red "Usage: " |
| 85 | + red "release.sh build-release <version-tag> <build-system(s)> <ldflags>" |
| 86 | +} |
| 87 | + |
| 88 | +# Whatever sub command is passed in, we need at least 2 arguments. |
| 89 | +if [ "$#" -lt 2 ]; then |
| 90 | + usage |
| 91 | + exit 1 |
| 92 | +fi |
| 93 | + |
| 94 | +# Extract the sub command and remove it from the list of parameters by shifting |
| 95 | +# them to the left. |
| 96 | +SUBCOMMAND=$1 |
| 97 | +shift |
| 98 | + |
| 99 | +# Call the function corresponding to the specified sub command or print the |
| 100 | +# usage if the sub command was not found. |
| 101 | +case $SUBCOMMAND in |
| 102 | +build-release) |
| 103 | + green "Building release" |
| 104 | + build_release "$@" |
| 105 | + ;; |
| 106 | +*) |
| 107 | + usage |
| 108 | + exit 1 |
| 109 | + ;; |
| 110 | +esac |
0 commit comments