diff --git a/.gitignore b/.gitignore index 36f971e..034cac5 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,3 @@ bin/* +build/* +pkg/* diff --git a/Makefile b/Makefile index 922262d..84415ef 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,9 @@ install: dev-deps build: mkdir -p bin && go build -o $(BIN_PATH) +package: + ./package.sh + run: build $(BIN_PATH) @@ -27,5 +30,5 @@ dev-deps: update-dev-deps: @$(foreach DEP,$(DEV_DEPS),go get -u $(DEP);) -.PHONY: test install build run fetch-vendor install-vendor dev-deps \ +.PHONY: test install build package run fetch-vendor install-vendor dev-deps \ update-dev-deps diff --git a/README.md b/README.md new file mode 100644 index 0000000..02def6d --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# cloudflare-dyndns diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..8acdd82 --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +0.0.1 diff --git a/package.sh b/package.sh new file mode 100755 index 0000000..c96834d --- /dev/null +++ b/package.sh @@ -0,0 +1,71 @@ +#! /usr/bin/env bash +set -e +shopt -s extglob + +main() { + local name="cloudflare-dyndns" + local platforms=( + darwin-386 darwin-amd64 + freebsd-386 freebsd-amd64 freebsd-arm + linux-386 linux-amd64 linux-arm + netbsd-386 netbsd-amd64 netbsd-arm + openbsd-386 openbsd-amd64 + solaris-amd64 + windows-386 windows-amd64 + ) + local builddir="build" + local outputdir="pkg" + + local version + version="$(get-version)" + + local workdir="${builddir}/${version}" + mkdir -p "$workdir" + + for platform in "${platforms[@]}"; do + if [[ "$platform" =~ ^(.+)-(.+)$ ]]; then + local os="${BASH_REMATCH[1]}" + local arch="${BASH_REMATCH[2]}" + local pkg="${name}_${version}_${os}_${arch}" + local pkgdir="${workdir}/${pkg}" + local binary="${pkgdir}/${name}" + + if [ "$os" == "windows" ]; then + binary="${binary}.exe" + fi + + echo "building $pkg" + GOOS="$os" GOARCH="$arch" go build -o "$binary" + + cp "README.md" "${pkgdir}/" + + mkdir -p "${outputdir}/${version}" + + if [ "$os" == "windows" ]; then + local archive="${outputdir}/${version}/${pkg}.zip" + echo "creating ${archive}" + local cwd="$(pwd)" + cd "$workdir" + zip -r "../../$archive" "$pkg" + cd "$cwd" + else + local archive="${outputdir}/${version}/${pkg}.tar.gz" + echo "creating ${archive}" + tar -C "$workdir" -czf "$archive" "$pkg" + fi + fi + done +} + +get-version() { + trim "$(cat "VERSION")" +} + +trim() { + local string="$@" + string="${string#"${string%%[![:space:]]*}"}" + string="${string%"${string##*[![:space:]]}"}" + echo -n "$string" +} + +main