Skip to content
This repository was archived by the owner on Mar 23, 2020. It is now read-only.

Commit 00cfb86

Browse files
committed
upgrade build.sh; update main.go
1 parent 6c99eff commit 00cfb86

4 files changed

Lines changed: 173 additions & 107 deletions

File tree

build.sh

100644100755
Lines changed: 158 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,188 @@
11
#!/usr/bin/env bash
22
set +e +x
3-
cat << EOF
4-
GO Cross Platform Compilation
5-
The valid combinations of \$GOOS and \$GOARCH are:
6-
https://golang.org/doc/install/source#environment
7-
https://golang.google.cn/doc/install/source#environment
8-
9-
EOF
10-
11-
GOOS_GOARCH_array=( aix_ppc64 android_386 android_amd64 android_arm android_arm64 darwin_386 darwin_amd64 darwin_arm darwin_arm64 dragonfly_amd64 freebsd_386 freebsd_amd64 freebsd_arm illumos_amd64 js_wasm linux_386 linux_amd64 linux_arm linux_arm64 linux_ppc64 linux_ppc64le linux_mips linux_mipsle linux_mips64 linux_mips64le linux_s390x netbsd_386 netbsd_amd64 netbsd_arm openbsd_386 openbsd_amd64 openbsd_arm openbsd_arm64 plan9_386 plan9_amd64 plan9_arm solaris_amd64 windows_386 windows_amd64 )
12-
appname=`\basename $(\pwd)`
13-
outputpath=./bin
14-
package=''
3+
myversion='GO Cross Platform Compilation v2020.1.6'
4+
targets=(aix_ppc64 android_386 android_amd64 android_arm android_arm64 darwin_386 darwin_amd64 darwin_arm darwin_arm64 dragonfly_amd64 freebsd_386 freebsd_amd64 freebsd_arm illumos_amd64 js_wasm linux_386 linux_amd64 linux_arm linux_arm64 linux_ppc64 linux_ppc64le linux_mips linux_mipsle linux_mips64 linux_mips64le linux_s390x netbsd_386 netbsd_amd64 netbsd_arm openbsd_386 openbsd_amd64 openbsd_arm openbsd_arm64 plan9_386 plan9_amd64 plan9_arm solaris_amd64 windows_386 windows_amd64)
5+
appname=$(\basename $(\pwd))
6+
outputpath=bin
7+
packages=''
8+
tags=''
159
declare -i verbose=0
10+
declare -i nopause=0
11+
declare -i succeeded=0
12+
declare -i failed=0
1613

1714
until [ $# -eq 0 ]; do
18-
case "$1" in
19-
--help|-h)
20-
printf "usage: bash ${0##*/} [--verbose|-v] [--package|-p <package-name>] [--name|-n <app-name>] [--output|-o <output-path>]\n"
21-
exit 0
22-
;;
23-
--verbose|-v)
24-
verbose=1
25-
;;
26-
--package|-n)
27-
shift
28-
if [ -z "$1" ] || [[ "$1" =~ ^\- ]]; then
29-
printf "ERROR: package argument error: $1\n"
30-
exit 1
31-
fi
32-
package=$1
33-
;;
34-
--name|-n)
35-
shift
36-
if [ -z "$1" ] || [[ "$1" =~ ^\- ]]; then
37-
printf "ERROR: name argument error: $1\n"
38-
exit 1
39-
fi
40-
appname=$1
41-
;;
42-
--output|-o)
43-
shift
44-
if [ -z "$1" ] || [[ "$1" =~ ^\- ]]; then
45-
printf "ERROR: output argument error: $1\n"
46-
exit 1
47-
fi
48-
outputpath=$1
49-
;;
50-
*)
51-
printf "ERROR: arguments error. please run \"bash ${0##*/} --help\" to get usage\n"
52-
exit 1
53-
;;
54-
esac
15+
case "$1" in
16+
--help | -h)
17+
cat <<EOF
18+
usage: bash ${0##*/} [options] [packages]
19+
20+
packages
21+
will append to "go build" command
22+
23+
options
24+
-v, --verbose print verbose text
25+
-n, --name <app-name> the name for format the executable file name
26+
like "name_os_arch", default is the directory name
27+
-o, --output <output-path> the output path, default is "bin"
28+
-t, --targets "OS_ARCH ..." the target OS_ARCH list.
29+
like "linux_amd64 darwin_amd64 windows_amd64 windows_386"
30+
default is all OS_ARCH
31+
from https://golang.org/doc/install/source#environment
32+
--tags tag,list the tags for "go build" command
33+
--no-pause do not pause when finish
34+
-h, --help display this help and exit
35+
--version display this script version and exit
36+
EOF
37+
exit 0
38+
;;
39+
--verbose | -v)
40+
verbose=1
41+
;;
42+
--name | -n)
43+
shift
44+
if [ -z "$1" ] || [[ "$1" =~ ^\- ]]; then
45+
printf "ERROR: name argument error: $1\n"
46+
exit 1
47+
fi
48+
appname=$1
49+
;;
50+
--output | -o)
51+
shift
52+
if [ -z "$1" ] || [[ "$1" =~ ^\- ]]; then
53+
printf "ERROR: output argument error: $1\n"
54+
exit 1
55+
fi
56+
outputpath=$1
57+
;;
58+
--targets | -t)
59+
shift
60+
if [ -z "$1" ] || [[ "$1" =~ ^\- ]]; then
61+
printf "ERROR: targets argument error: $1\n"
62+
exit 1
63+
fi
64+
targets=()
65+
while IFS= read -r -d '' arg; do
66+
targets+=("$arg")
67+
done < <(xargs printf '%s\0' <<<"$1")
68+
;;
69+
--tags)
5570
shift
71+
if [ -z "$1" ] || [[ "$1" =~ ^\- ]]; then
72+
printf "ERROR: tags argument error: $1\n"
73+
exit 1
74+
fi
75+
tags="-tags $1"
76+
;;
77+
--no-pause)
78+
nopause=1
79+
;;
80+
--version)
81+
printf "$myversion\n"
82+
exit 1
83+
;;
84+
--)
85+
shift
86+
packages="$@"
87+
break
88+
;;
89+
-)
90+
printf "ERROR: arguments error. please run \"bash ${0##*/} --help\" to get usage\n"
91+
exit 1
92+
;;
93+
*)
94+
packages+=" $1"
95+
;;
96+
esac
97+
shift
5698
done
5799

58-
if [ -z "$appname" ]; then
59-
printf "ERROR: please input an app-name by --name\n"
100+
if [ ! -z "$packages" ]; then
101+
declare -i err=0
102+
while IFS= read -r -d '' arg; do
103+
if [ ! -e "$arg" ]; then
104+
let err+=1
105+
printf "ERROR $err: cannot find the file $arg\n"
106+
fi
107+
done < <(xargs printf '%s\0' <<<"$packages")
108+
if [ $err -gt 0 ]; then
60109
exit 2
110+
fi
111+
# remove left 1 space, this space from first call packages+=" $1"
112+
packages=${packages:1}
113+
fi
114+
115+
if [ -z "$appname" ]; then
116+
printf "ERROR: please input an app-name by --name\n"
117+
exit 2
61118
fi
62119

63120
if [ -z "$outputpath" ]; then
64-
printf "ERROR: please input an output-path by --output\n"
65-
exit 2
121+
printf "ERROR: please input an output-path by --output\n"
122+
exit 2
66123
fi
67124

68125
mkdir -p "$outputpath"
69126
if [ $? -ne 0 ]; then
70-
printf "ERROR: create $outputpath failed: $?\n"
71-
exit 2
127+
printf "ERROR: create $outputpath failed: $?\n"
128+
exit 2
72129
fi
73130

74-
cat << EOF
75-
Package: $package
131+
cat <<EOF
132+
$myversion
133+
The valid combinations of \$GOOS and \$GOARCH are:
134+
https://golang.org/doc/install/source#environment
135+
https://golang.google.cn/doc/install/source#environment
136+
137+
Packages: $packages
76138
AppName: $appname
77139
Output: $outputpath
140+
Targets: ${targets[@]}
141+
Tags: $tags
78142
EOF
79143

80144
if [ ! -f go.mod ]; then
81-
printf "\nCreating go.mod ...\n"
82-
go mod init $appname
83-
if [ $? -ne 0 ]; then
84-
printf "Error: $?\n"
85-
exit 2
86-
fi
145+
printf "\nCreating go.mod ...\n"
146+
go mod init $appname
147+
if [ $? -ne 0 ]; then
148+
printf "Error: $?\n"
149+
exit 2
150+
fi
87151
fi
88152

89-
declare -i count=${#GOOS_GOARCH_array[*]}
153+
declare -i count=${#targets[*]}
90154
declare -i num=0
91-
for target in "${GOOS_GOARCH_array[@]}"; do
92-
let num+=1
93-
output=$outputpath/${appname}_${target}
94-
mygoos=${target%%_*}
95-
mygoarch=${target##*_}
96-
myverbose=''
97-
mycgo=''
98-
if [ $verbose -eq 1 ]; then
99-
myverbose='-v'
100-
fi
101-
case "$mygoos" in
102-
windows)
103-
output="$output.exe"
104-
;;
105-
android)
106-
mycgo='CGO_ENABLED=1'
107-
;;
108-
esac
109-
printf "\n($num/$count) Building $output ...\n"
110-
env GOOS=$mygoos GOARCH=$mygoarch `printf "$mycgo"` go build $myverbose -ldflags "-s -w" -o $output $package
155+
for target in "${targets[@]}"; do
156+
let num+=1
157+
output=$outputpath/${appname}_${target}
158+
mygoos=${target%%_*}
159+
mygoarch=${target##*_}
160+
myverbose=''
161+
mycgo=''
162+
if [ $verbose -eq 1 ]; then
163+
myverbose='-v'
164+
fi
165+
case "$mygoos" in
166+
windows)
167+
output="$output.exe"
168+
;;
169+
android)
170+
mycgo='CGO_ENABLED=1'
171+
;;
172+
esac
173+
printf "\n($num/$count) Building $output ...\n"
174+
env GOOS=$mygoos GOARCH=$mygoarch $(printf "$mycgo") go build $myverbose $tags -ldflags "-s -w" -o $output $packages
175+
if [ $? -eq 0 ]; then
176+
let succeeded+=1
111177
file $output
178+
else
179+
let failed+=1
180+
fi
112181
done
113182

114-
if [ -t 1 ]; then
115-
printf "\nDone. Press any key to exit..."
116-
read -n1
117-
printf "\n"
183+
printf "\nDone. $succeeded succeeded, $failed failed, $(ls -1q $outputpath | wc -l | xargs echo) files in $outputpath\n"
184+
if [[ -t 1 && $nopause -eq 0 ]]; then
185+
printf 'Press any key to exit...'
186+
read -n1
187+
printf "\n"
118188
fi

go.mod

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ module simplehttpserver
33
go 1.13
44

55
require (
6-
github.com/fatih/color v1.7.0
7-
github.com/mattn/go-colorable v0.1.4 // indirect
8-
github.com/mattn/go-isatty v0.0.11 // indirect
9-
github.com/valyala/fasthttp v1.7.0
6+
github.com/fatih/color v1.8.0
7+
github.com/valyala/fasthttp v1.7.1
108
gopkg.in/yaml.v2 v2.2.7
119
)

go.sum

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
2-
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
1+
github.com/fatih/color v1.8.0 h1:5bzFgL+oy7JITMTxUPJ00n7VxmYd/PdMp5mHFX40/RY=
2+
github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8=
33
github.com/klauspost/compress v1.8.2 h1:Bx0qjetmNjdFXASH02NSAREKpiaDwkO1DRZ3dV2KCcs=
44
github.com/klauspost/compress v1.8.2/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
55
github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
66
github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
7-
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
8-
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
9-
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
10-
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
11-
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
7+
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
8+
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
9+
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
10+
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
1211
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
1312
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
14-
github.com/valyala/fasthttp v1.7.0 h1:r0Z/fzm2Euss3K0hhkPtt41TigAr9bXueavuXgrThi4=
15-
github.com/valyala/fasthttp v1.7.0/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
13+
github.com/valyala/fasthttp v1.7.1 h1:UHtt5/7O70RSUZTR/hSu0PNWMAfWx5AtsPp9Jk+g17M=
14+
github.com/valyala/fasthttp v1.7.1/go.mod h1:FstJa9V+Pj9vQ7OJie2qMHdwemEDaDiSdBnvPM1Su9w=
1615
github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio=
1716
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
1817
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
18+
golang.org/x/sys v0.0.0-20180202135801-37707fdb30a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
19+
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
1920
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
20-
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
21-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
22-
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
2321
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
2422
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
2523
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=

main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
const (
2222
// Version information
23-
Version = "SimpleHttpServer v1.3-beta.3"
23+
Version = "SimpleHttpServer v1.3-beta.4"
2424
// HTTPProxy returns HTTP_PROXY
2525
HTTPProxy = "HTTP_PROXY"
2626
// HTTPSProxy returns HTTPS_PROXY
@@ -700,8 +700,8 @@ verbose: true
700700
enablecolor: true
701701
enableupload: true
702702
## maxrequestbodysize:0 to default size
703-
#maxrequestbodysize: %d
704-
#logfile: ./simplehttpserver.log
703+
maxrequestbodysize: %d
704+
logfile: ./simplehttpserver.log
705705
#fallback: ./index.html
706706
#HTTP_PROXY:
707707
#HTTPS_PROXY:

0 commit comments

Comments
 (0)