-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.sh
executable file
·149 lines (137 loc) · 5.24 KB
/
package.sh
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
139
140
141
142
143
144
145
146
147
148
#!/bin/bash
#
# Package Fitplot for various operating systems.
# Usage package {help|windows|linux|osx|all}
#
#
#
# Useful packaging tools assumed available:
#
# asciidoctor - apt-get install asciidoctor
# iconify2 gimp plugin http://registry.gimp.org/node/27989 png->.ico
# github.com/akavel/rsrc/ - embed windows icons - go get github.com/akavel/rsrc
# nsis - windows installer utility - apt-get install nsis
# cross-compilers for C language programs (e.g. sqlite3 dependency is cgo )
# x86_64-w64-mingw32-gcc and o64-clang
# musl - C-library apt-get install musl
# see: https://www.limitlessfx.com/cross-compile-golang-app-for-windows-from-linux.html
# Configure these to match your system
BIN_DIR=/home/craig/go/bin
SOURCE_DIR=/home/craig/go/src/github.com/cprevallet/fitplot
PKG_DIR=/home/craig/go/packaging
MOUNT_DIR=/mnt/fitplot
NWJS_DIR=/home/craig/Downloads/
function build() {
local os="$1"
local arch="$2"
cd $SOURCE_DIR/static
asciidoctor -a toc -a icons=font -a icon-set=fa help.asc
asciidoctor-pdf -a toc -a icons=font -a icon-set=fa help.asc
# The following must be done manually:
# In gimp open fitplot.xcf and use iconify plugin to create windows object file.
cd $SOURCE_DIR
echo -e '\nbuilding:'$os, $arch
go clean
if [ "$os" == "windows" ] ; then
# env GOOS=$1 GOARCH=$2 go build -ldflags "-X main.Buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.Githash=`git rev-parse HEAD` -H windowsgui" -v
env CGO_ENABLED=1 GOOS=$1 GOARCH=$2 CC=x86_64-w64-mingw32-gcc go install -ldflags "-X main.Buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.Githash=`git rev-parse HEAD` -H windowsgui" -v
fi
if [ "$os" == "linux" ] ; then
# env CGO_ENABLED=1 GOOS=$1 GOARCH=$2 go install -ldflags "-X main.Buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.Githash=`git rev-parse HEAD`" -v
# Use the musl C library to statically link in libc
env CGO_ENABLED=1 GOOS=$1 GOARCH=$2 CC=/usr/bin/musl-gcc go install -ldflags "-linkmode external -extldflags "-static" -X main.Buildstamp=`date -u '+%Y-%m-%d_%I:%M:%S%p'` -X main.Githash=`git rev-parse HEAD`" -v
fi
}
function package_windows {
echo -e 'Packaging for Windows'
cd $PKG_DIR
# make a backup of previous package
sudo cp -r windows_dist/ windows_dist_old
sudo rm -rf windows_dist
sudo mkdir windows_dist
cd windows_dist
# Have replaced nw.exe icon using resource hacker. Copy into the package.
# Could just unzip the official version if the default icon's okay.
# sudo unzip -q $NWJS_DIR/nwjs-v0.36.0-win-x64.zip
sudo cp -r $NWJS_DIR/nwjs-v0.36.0-win-x64/ fitplot
cd fitplot
sudo mkdir nw.package
sudo cp $BIN_DIR/windows_amd64/fitplot.exe ./nw.package/
sudo cp $SOURCE_DIR/package.json ./nw.package/
sudo cp $SOURCE_DIR/main.js ./nw.package/
sudo cp $SOURCE_DIR/LICENSE.txt ./nw.package/
sudo cp -r $SOURCE_DIR/static/ ./nw.package/
sudo cp -r $SOURCE_DIR/tmpl/ ./nw.package/
sudo cp -r $SOURCE_DIR/samples/ ./nw.package/
sudo cp -r $SOURCE_DIR/db/ ./nw.package/
sudo cp -r $SOURCE_DIR/export/ ./nw.package/
cd ..
sudo cp $SOURCE_DIR/static/help.pdf .
sudo cp $SOURCE_DIR/'Fitplot Windows x64 Setup.nsi' .
sudo makensis Fitplot\ Windows\ x64\ Setup.nsi
sudo rm Fitplot\ Windows\ x64\ Setup.nsi
sudo rm -rf ./fitplot
sudo sh -c "md5sum Fitplot\ Windows\ x64\ Setup.exe > md_windows.txt"
cd $PKG_DIR
}
function package_linux {
echo -e 'Packaging for Linux'
cd $PKG_DIR
# make a backup of previous package
sudo cp -r linux_dist/ linux_dist_old
sudo rm -rf linux_dist
sudo mkdir linux_dist
cd linux_dist
sudo tar -oxzf $NWJS_DIR/nwjs-v0.36.0-linux-x64.tar.gz
sudo mv nwjs-v0.36.0-linux-x64 fitplot
cd fitplot
sudo cp $SOURCE_DIR/setup.sh .
sudo mkdir nw.package
sudo cp $BIN_DIR/fitplot ./nw.package/
sudo cp $SOURCE_DIR/package.json ./nw.package/
sudo cp $SOURCE_DIR/main.js ./nw.package/
sudo cp $SOURCE_DIR/fitplot.desktop ./nw.package/
sudo cp -r $SOURCE_DIR/static/ ./nw.package/
sudo cp -r $SOURCE_DIR/tmpl/ ./nw.package/
sudo cp -r $SOURCE_DIR/samples/ ./nw.package/
sudo cp -r $SOURCE_DIR/db/ ./nw.package/
sudo cp -r $SOURCE_DIR/icons/ ./nw.package/
sudo cp -r $SOURCE_DIR/export/ ./nw.package/
cd ..
sudo cp $SOURCE_DIR/static/help.pdf .
sudo makeself fitplot fitplot.run "Fitplot by Craig Prevallet" ./setup.sh
sudo rm -r ./fitplot/
sudo sh -c "md5sum fitplot.run > md_linux.txt"
cd $PKG_DIR
# Install using: sudo ./fitplot.run --target /opt/fitplot
}
function build_and_package {
echo -e "$1"
if [ "$1" = 'windows' ]; then
build "windows" "amd64"
package_windows
fi
if [ "$1" = 'linux' ]; then
build "linux" "amd64"
package_linux
fi
if [ "$1" = 'all' ]; then
build "windows" "amd64"
package_windows
build "linux" "amd64"
package_linux
fi
}
# Main entry point
# First arg is help or no args passed.
if [ "$1" = 'help' ] || [ $# -eq 0 ]; then
echo -e '\nUsage: package {help|windows|linux|all}'
else
date "+%nPackage started on date: %m-%d-%Y at %H:%M:%S"
until [ -z "$1" ] # Until all parameters used up . . .
do
build_and_package $1
shift
done
date "+%nPackage ended on date: %m-%d-%Y at %H:%M:%S"
fi