-
Notifications
You must be signed in to change notification settings - Fork 8
/
ake
executable file
·138 lines (114 loc) · 2.65 KB
/
ake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
#
# Usage
#
# ./ake release # build, package, and upload
APP="aliyundns"
EXTRA_FILES=""
HOST="root@box"
GITHUB_USER="gutenye"
GITHUB_REPO="aliyundns"
RELEASE="linux/amd64"
VERSION=$(cat VERSION)
DESTDIR=".tmp/$APP-$VERSION"
declare -A OS_MAP=(
[homebrew]="darwin"
)
declare -A DIR_MAP=(
[homebrew]="/usr/share/$APP"
)
platform=""
os=""
arch=""
assets_dir=""
cgo_enabled() { [ "$1" == "$GOHOSTOS" ] && echo 1 || echo 0; }
ext() { [ $1 == "windows" ] && echo .exe || echo ""; }
main() {
go run *.go "$@"
}
release() {
GOROOT="/home/guten/dev/src/go/go"
rm *.zip *.tar.gz 2>/dev/null
for release in $RELEASE; do
platform=${release%/*}; arch=${release#*/}; os=${OS_MAP[$platform]-$platform}
assets_dir=${DIR_MAP[$platform]-$o_assets_dir}
build
package
done
upload *.zip *.tar.gz
}
######
# lib
#####
get_deps() {
go get -v ./...
}
update-version() {
sed -i "s/app.Version.*/app.Version = \"$VERSION\"/" main.go
}
# dist{platform, os, arch, assets_dir}
prepare() {
rm -r .tmp 2>/dev/null
mkdir -p $DESTDIR
mkdir -p dist
if [ ! -z $EXTRA_FILES ]; then
cp -r $EXTRA_FILES $DESTDIR
fi
}
# build{platform, os, arch, assets_dir}
build() {
prepare
update-version
#rsync -a --del --exclude '.*' . /tmp/$APP/
echo -e "\nBuilding $platform/$arch"
#CGO_ENABLED=$(cgo_enabled $os) GOOS=$os GOARCH=$arch $GOROOT/bin/go build -o "$DESTDIR/$APP$(ext $os)"
GOOS=$os GOARCH=$arch $GOROOT/bin/go build -o "$DESTDIR/$APP$(ext $os)"
#rsync -a /tmp/$APP/ .
}
# package{platform, os, arch}
package() {
echo "Packing $platform/$arch"
case $os in
linux | darwin ) tar jcvf dist/$APP.$platform.$arch-$VERSION.tar.bz2 -C .tmp $APP-$VERSION;;
windows ) cd .tmp && zip -r ../dist/$APP.$platform.$arch-$VERSION.zip $APP-$VERSION && cd .. ;;
esac
}
upload() {
github-release release --user $GITHUB_USER --repo $GITHUB_REPO --tag $VERSION
for file in dist/*$VERSION*; do
github-release upload --user $GITHUB_USER --repo $GITHUB_REPO --tag $VERSION --name ${file#*/} --file $file
done
}
clean() {
rm -r dist/*
}
deploy() {
platform="linux"; arch="amd64" os="linux"
build
scp misc/aliyundns.service "$HOST:/etc/systemd/system"
scp $DESTDIR/aliyundns "$HOST:/usr/bin"
}
############
# main
############
eval "$(go env)"
o_assets_dir="runtime"
o_package=false
while getopts "d:p" opt; do
case $opt in
d ) o_assets_dir=$OPTARG ;;
p ) o_package=true ;;
esac
done
shift $(( OPTIND - 1 ))
run() {
go run *.go "$@"
}
case $1 in
run ) run "$@" ;;
release ) shift && release "$@" ;;
u | upload ) shift && upload "$@";;
c | clean ) shift && clean "$@" ;;
d | deploy) shift && deploy"$@" ;;
* ) main "$@";;
esac