Skip to content

Commit

Permalink
Load environmental variables instead of flags
Browse files Browse the repository at this point in the history
  • Loading branch information
aerth committed Jun 16, 2016
1 parent 0f05c5c commit 285529f
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
15 changes: 13 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ build:
set -e
go fmt
mkdir -p bin
go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE} && echo Built ${NAME}-${RELEASE}
go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}
@echo Built ${NAME}-${RELEASE}
chmod 755 bin/${NAME}-v${RELEASE}

install:
@echo installing to /usr/local/bin/
@echo installing to ${PREFIX}
mkdir -p ${PREFIX}
mv -v ./bin/${NAME}-v${RELEASE} ${PREFIX}/bin/${NAME}
chmod 755 ${PREFIX}/bin/${NAME}

Expand All @@ -40,17 +42,23 @@ run:

cross:
mkdir -p bin
@echo "Building for target: Windows"
GOOS=windows GOARCH=386 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-WIN32.exe
GOOS=windows GOARCH=amd64 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-WIN64.exe
@echo "Building for target: OS X"
GOOS=darwin GOARCH=386 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-OSX-x86
GOOS=darwin GOARCH=amd64 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-OSX-amd64
@echo "Building for target: Linux"
GOOS=linux GOARCH=amd64 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-linux-amd64
GOOS=linux GOARCH=386 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-linux-x86
GOOS=linux GOARCH=arm go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-linux-arm
@echo "Building for target: FreeBSD"
GOOS=freebsd GOARCH=amd64 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-freebsd-amd64
GOOS=freebsd GOARCH=386 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-freebsd-x86
@echo "Building for target: OpenBSD"
GOOS=openbsd GOARCH=amd64 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-openbsd-amd64
GOOS=openbsd GOARCH=386 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-openbsd-x86
@echo "Building for target: NetBSD"
GOOS=netbsd GOARCH=amd64 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-netbsd-amd64
GOOS=netbsd GOARCH=386 go build -v ${GO_LDFLAGS} -o bin/${NAME}-v${RELEASE}-netbsd-x86
@echo ${RELEASE} > bin/VERSION
Expand All @@ -59,3 +67,6 @@ cross:
# package target is not working out, moved to a shell script named "pack.bash"
package:
@echo "Run ./pack.bash"

clean:
rm -Rf bin pkg
19 changes: 18 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ import (
)

var (
version = "0.9.G"
version = "0.9.G" // Use makefile for version hash
destinationEmail = "cosgo@localhost"
antiCSRFkey = []byte("LI80PNK1xcT01jmQBsEyxyrNCrbyyFPjPU8CKnxwmCruxNijgnyb3hXXD3p1RBc0+LIRQUUbTtis6hc6LD4I/A==")
cosgoRefresh = 42 * time.Minute
Expand Down Expand Up @@ -242,6 +242,23 @@ func openLogFile() {
}

func initialize() (time.Time, string, string, string) {

// Load environmental variables as flags
if os.Getenv("COSGO_PORT") == "" {
*port = os.Getenv("COSGO_PORT")
}

if os.Getenv("COSGO_BIND") == "" {
*bind = os.Getenv("COSGO_BIND")
}

if os.Getenv("COSGO_REFRESH") == "" {
cosgoRefresh = os.Getenv("COSGO_REFRESH")
}

if os.Getenv("COSGO_GPG") == "" {
*gpg = os.Getenv("COSGO_GPG")
}
if *gpg != "" {
log.Println("\t[gpg pubkey: " + *gpg + "]")
publicKey = read2mem(rel2real(*gpg))
Expand Down

0 comments on commit 285529f

Please sign in to comment.