2016-02-23 23:57:14 +01:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
_init() {
|
|
|
|
# Save release LDFLAGS
|
|
|
|
LDFLAGS=$(go run buildscripts/gen-ldflags.go)
|
|
|
|
|
|
|
|
# Extract release tag
|
|
|
|
release_tag=$(echo $LDFLAGS | awk {'print $4'} | cut -f2 -d=)
|
|
|
|
|
|
|
|
# Verify release tag.
|
|
|
|
if [ -z "$release_tag" ]; then
|
|
|
|
echo "Release tag cannot be empty. Please check return value of \`go run buildscripts/gen-ldflags.go\`"
|
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Extract release string.
|
2016-02-24 02:12:23 +01:00
|
|
|
release_str=$(echo $MINIO_RELEASE | tr '[:upper:]' '[:lower:]')
|
2016-02-23 23:57:14 +01:00
|
|
|
|
|
|
|
# Verify release string.
|
|
|
|
if [ -z "$release_str" ]; then
|
2016-02-24 02:12:23 +01:00
|
|
|
echo "Release string cannot be empty. Please set \`MINIO_RELEASE\` env variable."
|
2016-02-23 23:57:14 +01:00
|
|
|
exit 1;
|
|
|
|
fi
|
|
|
|
|
|
|
|
# List of supported architectures
|
2017-01-14 03:51:17 +01:00
|
|
|
SUPPORTED_OSARCH='linux/386 linux/amd64 linux/arm linux/arm64 windows/386 windows/amd64 darwin/amd64 freebsd/amd64'
|
2016-03-18 21:02:06 +01:00
|
|
|
|
|
|
|
## System binaries
|
2016-03-21 23:47:43 +01:00
|
|
|
CP=`which cp`
|
|
|
|
SHASUM=`which shasum`
|
|
|
|
SED=`which sed`
|
2016-02-23 23:57:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
go_build() {
|
|
|
|
local osarch=$1
|
|
|
|
os=$(echo $osarch | cut -f1 -d'/')
|
|
|
|
arch=$(echo $osarch | cut -f2 -d'/')
|
|
|
|
package=$(go list -f '{{.ImportPath}}')
|
|
|
|
echo -n "-->"
|
|
|
|
printf "%15s:%s\n" "${osarch}" "${package}"
|
2016-03-18 21:02:06 +01:00
|
|
|
|
|
|
|
# Release binary name
|
|
|
|
release_bin="$release_str/$os-$arch/$(basename $package).$release_tag"
|
|
|
|
# Release binary downloadable name
|
|
|
|
release_real_bin="$release_str/$os-$arch/$(basename $package)"
|
|
|
|
# Release shasum name
|
|
|
|
release_shasum="$release_str/$os-$arch/$(basename $package).shasum"
|
|
|
|
|
|
|
|
# Go build to build the binary.
|
2017-01-14 03:51:17 +01:00
|
|
|
if [ "${arch}" == "arm" ]; then
|
|
|
|
# Release binary downloadable name
|
|
|
|
release_real_bin_6="$release_str/$os-${arch}6vl/$(basename $package)"
|
2016-03-18 21:02:06 +01:00
|
|
|
|
2017-01-14 03:51:17 +01:00
|
|
|
release_bin_6="$release_str/$os-${arch}6vl/$(basename $package).$release_tag"
|
|
|
|
## Support building for ARM6vl
|
|
|
|
GOARM=6 GOOS=$os GOARCH=$arch go build --ldflags "${LDFLAGS}" -o $release_bin_6
|
|
|
|
|
|
|
|
## Copy
|
|
|
|
$CP -p $release_bin_6 $release_real_bin_6
|
|
|
|
|
|
|
|
# Release shasum name
|
|
|
|
release_shasum_6="$release_str/$os-${arch}6vl/$(basename $package).shasum"
|
|
|
|
|
|
|
|
# Calculate shasum
|
|
|
|
shasum_str=$(${SHASUM} ${release_bin_6})
|
|
|
|
echo ${shasum_str} | $SED "s/$release_str\/$os-${arch}6vl\///g" > $release_shasum_6
|
|
|
|
|
|
|
|
# Release binary downloadable name
|
|
|
|
release_real_bin_7="$release_str/$os-$arch/$(basename $package)"
|
|
|
|
|
|
|
|
release_bin_7="$release_str/$os-$arch/$(basename $package).$release_tag"
|
|
|
|
## Support building for ARM7vl
|
|
|
|
GOARM=7 GOOS=$os GOARCH=$arch go build --ldflags "${LDFLAGS}" -o $release_bin_7
|
|
|
|
|
|
|
|
## Copy
|
|
|
|
$CP -p $release_bin_7 $release_real_bin_7
|
|
|
|
|
|
|
|
# Release shasum name
|
|
|
|
release_shasum_7="$release_str/$os-$arch/$(basename $package).shasum"
|
|
|
|
|
|
|
|
# Calculate shasum
|
|
|
|
shasum_str=$(${SHASUM} ${release_bin_7})
|
|
|
|
echo ${shasum_str} | $SED "s/$release_str\/$os-$arch\///g" > $release_shasum_7
|
2016-03-21 23:47:43 +01:00
|
|
|
else
|
2017-01-14 03:51:17 +01:00
|
|
|
GOOS=$os GOARCH=$arch go build --ldflags "${LDFLAGS}" -o $release_bin
|
|
|
|
|
|
|
|
# Create copy
|
|
|
|
if [ $os == "windows" ]; then
|
|
|
|
$CP -p $release_bin ${release_real_bin}.exe
|
|
|
|
else
|
|
|
|
$CP -p $release_bin $release_real_bin
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Calculate shasum
|
|
|
|
shasum_str=$(${SHASUM} ${release_bin})
|
|
|
|
echo ${shasum_str} | $SED "s/$release_str\/$os-$arch\///g" > $release_shasum
|
2016-03-21 23:47:43 +01:00
|
|
|
fi
|
2016-02-23 23:57:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
main() {
|
|
|
|
# Build releases.
|
|
|
|
echo "Executing $release_str builds for OS: ${SUPPORTED_OSARCH}"
|
2016-03-11 05:47:56 +01:00
|
|
|
echo "Choose an OS Arch from the below"
|
2016-02-23 23:57:14 +01:00
|
|
|
for osarch in ${SUPPORTED_OSARCH}; do
|
2016-03-11 05:47:56 +01:00
|
|
|
echo ${osarch}
|
2016-02-23 23:57:14 +01:00
|
|
|
done
|
2016-03-11 05:47:56 +01:00
|
|
|
|
|
|
|
read -p "If you want to build for all, Just press Enter: " chosen_osarch
|
2016-12-28 02:52:24 +01:00
|
|
|
if [ "$chosen_osarch" = "" ] || [ "$chosen_osarch" = "all" ]; then
|
2016-03-11 05:47:56 +01:00
|
|
|
for each_osarch in ${SUPPORTED_OSARCH}; do
|
|
|
|
go_build ${each_osarch}
|
|
|
|
done
|
|
|
|
else
|
2016-12-28 02:52:24 +01:00
|
|
|
for each_osarch in $(echo $chosen_osarch | sed 's/,/ /g'); do
|
|
|
|
go_build ${each_osarch}
|
|
|
|
done
|
2016-03-11 05:47:56 +01:00
|
|
|
fi
|
|
|
|
|
2016-02-23 23:57:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
# Run main.
|
|
|
|
_init && main
|