diff --git a/.gitignore b/.gitignore index bc2faa1..b64170f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor /bin -/.env \ No newline at end of file +/.env +/release \ No newline at end of file diff --git a/Makefile b/Makefile index b2899d7..0288d94 100644 --- a/Makefile +++ b/Makefile @@ -29,11 +29,14 @@ install-devtools: vendor GO111MODULE=off go get -u github.com/golangci/golangci-lint/cmd/golangci-lint clean: - rm -rf ./bin + rm -rf ./bin ./release go clean -i -x -r -modcache doc: @echo "Open your browser to http://localhost:6060/pkg/forge.cadoles.com/Pyxis/orion/ to see the documentation" @godoc -http=:6060 -.PHONY: test clean generate vendor install-devtools lint watch tidy doc \ No newline at end of file +release: + scripts/release + +.PHONY: test clean generate vendor install-devtools lint watch tidy doc release \ No newline at end of file diff --git a/example/reachview/README.md b/cmd/configurator/README.md similarity index 79% rename from example/reachview/README.md rename to cmd/configurator/README.md index 3ae3a72..79c4f9e 100644 --- a/example/reachview/README.md +++ b/cmd/configurator/README.md @@ -1,4 +1,4 @@ -# Example: ReachView +# Example: Configurator A simple example of a ReachView client that can: @@ -10,7 +10,7 @@ A simple example of a ReachView client that can: 2. Launch the example: ```shell - go run example/reachview/main.go \ + go run cmd/configurator/main.go \ -mode 'rover|base'\ -host ''\ @@ -21,7 +21,7 @@ A simple example of an updater client wich can: 3. The device will switch to the provided WiFi network, as you should do. 4. Launch the example in `update-then-reboot` phase. ```shell - go run example/updater/main.go \ + go run cmd/updater/main.go \ -phase 'update-and-reboot'\ -host '/dev/null && pwd )" + +function build { + + local name=$1 + local srcdir=$2 + local os=$3 + local arch=$4 + + local dirname="$name-$os-$arch" + local destdir="$DIR/../release/$dirname" + + local ext= + [ "$os" == "windows" ] && ext=.exe + + rm -rf "$destdir" + mkdir -p "$destdir" + + echo "building $dirname..." + + CGO_ENABLED=0 GOOS="$os" GOARCH="$arch" go build \ + -v \ + -mod=vendor \ + -ldflags="-s -w" \ + -gcflags=-trimpath="${PWD}" \ + -asmflags=-trimpath="${PWD}" \ + -o "$destdir/$name$ext" \ + "$srcdir" + + if [ ! -z "$(which upx)" ]; then + upx --best "$destdir/$name$ext" + fi + +} + +function copy { + + local name=$1 + local os=$2 + local arch=$3 + local src=$4 + local dest=$5 + + local dirname="$name-$os-$arch" + local destdir="$DIR/../release/$dirname" + + echo "copying '$src' to '$destdir/$dest'..." + + mkdir -p "$(dirname $destdir/$dest)" + + cp -rfL $src "$destdir/$dest" + +} + +function compress { + + local name=$1 + local os=$2 + local arch=$3 + + local dirname="$name-$os-$arch" + local destdir="$DIR/../release/$dirname" + + echo "compressing $dirname..." + tar -czf "$destdir.tar.gz" -C "$destdir/../" "$dirname" +} + +function release_updater { + + local os=$1 + local arch=$2 + + build 'updater' "$DIR/../cmd/updater" $os $arch + compress 'updater' $os $arch + +} + +function release_discovery { + + local os=$1 + local arch=$2 + + build 'discovery' "$DIR/../cmd/discovery" $os $arch + compress 'discovery' $os $arch + +} + +function release_configurator { + + local os=$1 + local arch=$2 + + build 'configurator' "$DIR/../cmd/configurator" $os $arch + compress 'configurator' $os $arch + +} + + +function main { + for os in ${OS_TARGETS[@]}; do + for arch in ${ARCH_TARGETS[@]}; do + release_configurator $os $arch + release_updater $os $arch + release_discovery $os $arch + done + done +} + +main \ No newline at end of file