|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | + |
| 5 | +TOOL_NAME=$(basename $1) |
| 6 | +VERSION=$2 |
| 7 | + |
| 8 | +BASE_DIR=$(readlink -f $(dirname $0)/..) |
| 9 | +TOOL_DIR="$BASE_DIR/extra/$TOOL_NAME" |
| 10 | +if ! [ -d "$TOOL_DIR" ] || [ -z "$VERSION" ] ; then |
| 11 | + echo "Usage: $0 <tool_name> <version>" |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +DIR=${BASE_DIR}/distrib |
| 16 | + |
| 17 | +hash_file() { |
| 18 | + plat=$1 |
| 19 | + file=$2 |
| 20 | + name=$(basename $file) |
| 21 | + hash=$(sha256sum $file | cut -d ' ' -f 1) |
| 22 | + len=$(stat -c %s $file) |
| 23 | + cat << EOF |
| 24 | +{ |
| 25 | + "host": "$plat", |
| 26 | + "url": "https://downloads.arduino.cc/tools/$name", |
| 27 | + "archiveFileName": "$name", |
| 28 | + "checksum": "SHA-256:$hash", |
| 29 | + "size": "$len" |
| 30 | +} |
| 31 | +EOF |
| 32 | +} |
| 33 | + |
| 34 | +build_for_arch() { |
| 35 | + local os=$1 |
| 36 | + local arch=$2 |
| 37 | + local plat=$3 |
| 38 | + |
| 39 | + if [ "$os" == "windows" ]; then |
| 40 | + app_ext=".exe" |
| 41 | + pkg_ext=".zip" |
| 42 | + pkg_cmd="zip -qr" |
| 43 | + else |
| 44 | + app_ext="" |
| 45 | + pkg_ext=".tar.gz" |
| 46 | + pkg_cmd="tar -czf" |
| 47 | + fi |
| 48 | + |
| 49 | + local tool_stem="$DIR/$TOOL_NAME-$VERSION" |
| 50 | + local build_dir="$tool_stem/$plat" |
| 51 | + local build_file="$TOOL_NAME$app_ext" |
| 52 | + local package_file="$tool_stem-$plat$pkg_ext" |
| 53 | + |
| 54 | + echo "Building $TOOL_NAME for $os/$arch ($plat)" |
| 55 | + mkdir -p "$build_dir" |
| 56 | + (cd $BASE_DIR/extra/$TOOL_NAME && GOOS="$os" GOARCH="$arch" go build -o "$build_dir/$build_file") |
| 57 | + (cd "$tool_stem" && $pkg_cmd "$package_file" $plat/) |
| 58 | + hash_file $plat "$package_file" > $build_dir.json |
| 59 | +} |
| 60 | + |
| 61 | +build_json() { |
| 62 | + temp_file=$(mktemp) |
| 63 | + echo "{ \"packages\": [ { \"tools\": [ { \"name\": \"$TOOL_NAME\", \"version\": \"$VERSION\", \"systems\":" > $temp_file |
| 64 | + ls $DIR/$TOOL_NAME-$VERSION/*.json | sort | xargs cat | jq -s . >> $temp_file |
| 65 | + echo "} ] } ] }" >> $temp_file |
| 66 | + jq . $temp_file > $DIR/$TOOL_NAME-$VERSION.json |
| 67 | + rm -f $temp_file $DIR/$TOOL_NAME-$VERSION/*.json |
| 68 | +} |
| 69 | + |
| 70 | +build_for_arch "linux" "amd64" "x86_64-linux-gnu" |
| 71 | +build_for_arch "linux" "arm64" "aarch64-linux-gnu" |
| 72 | +build_for_arch "darwin" "amd64" "i386-apple-darwin11" |
| 73 | +build_for_arch "windows" "386" "i686-mingw32" |
| 74 | +build_json |
| 75 | +echo "Build completed for $TOOL_NAME $VERSION: $DIR/$TOOL_NAME-$VERSION.json" |
0 commit comments