Add packaging script

This commit is contained in:
2016-08-22 02:49:22 +01:00
parent 322cb207c7
commit eba8b1e69c
5 changed files with 79 additions and 1 deletions

2
.gitignore vendored
View File

@@ -1 +1,3 @@
bin/*
build/*
pkg/*

View File

@@ -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

1
README.md Normal file
View File

@@ -0,0 +1 @@
# cloudflare-dyndns

1
VERSION Normal file
View File

@@ -0,0 +1 @@
0.0.1

71
package.sh Executable file
View File

@@ -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