-
Notifications
You must be signed in to change notification settings - Fork 61
/
build.sh
executable file
·101 lines (93 loc) · 3.06 KB
/
build.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
#!/bin/bash
#
# Builds executable and downloadable bundle for 3 platforms
#
# For OSX and Linux:
# * builds pgdiff
# * downloads pgrun
# * combines them, a README, and pgdiff.sh into a tgz file
#
# For Windows:
# * builds pgdiff.exe
# * downloads pgrun.exe
# * combines them, a README, and pgdiff.sh into a zip file
#
SCRIPT_DIR="$(dirname `ls -l $0 | awk '{ print $NF }'`)"
[[ -z $APPNAME ]] && APPNAME=pgdiff
[[ -z $VERSION ]] && read -p "Enter version number: " VERSION
LINUX_README=README-linux.md
LINUX_FILE="${APPNAME}-linux-${VERSION}.tar.gz"
OSX_README=README-osx.md
OSX_FILE="${APPNAME}-osx-${VERSION}.tar.gz"
WIN_README=README-win.md
WIN_FILE="${APPNAME}-win-${VERSION}.zip"
if [[ -f $LINUX_README ]]; then
echo " ==== Building Linux ===="
tempdir="$(mktemp -d)"
workdir="$tempdir/$APPNAME"
echo $workdir
mkdir -p $workdir
# Build the executable
GOOS=linux GOARCH=386 go build -o "$workdir/$APPNAME"
# Download pgrun to the temp directory
wget -O "$workdir/pgrun" "https://github.com/joncrlsn/pgrun/raw/master/bin-linux/pgrun"
# Copy the bash runtime script to the temp directory
cp pgdiff.sh "$workdir/"
cp "${SCRIPT_DIR}/${LINUX_README}" "$workdir/README.md"
cd "$tempdir"
# Make everything executable
chmod -v ugo+x $APPNAME/*
tarName="${tempdir}/${LINUX_FILE}"
COPYFILE_DISABLE=true tar -cvzf "$tarName" $APPNAME
cd -
mv "$tarName" "${SCRIPT_DIR}/"
echo "Built linux."
else
echo "Skipping linux. No $LINUX_README file."
fi
if [[ -f $OSX_README ]]; then
echo " ==== Building OSX ===="
tempdir="$(mktemp -d)"
workdir="$tempdir/$APPNAME"
echo $workdir
mkdir -p $workdir
# Build the executable
GOOS=darwin GOARCH=386 go build -o "$workdir/$APPNAME"
# Download pgrun to the work directory
wget -O "$workdir/pgrun" "https://github.com/joncrlsn/pgrun/raw/master/bin-osx/pgrun"
# Copy the bash runtime script to the temp directory
cp pgdiff.sh "$workdir/"
cp "${SCRIPT_DIR}/${OSX_README}" "$workdir/README.md"
cd "$tempdir"
# Make everything executable
chmod -v ugo+x $APPNAME/*
tarName="${tempdir}/${OSX_FILE}"
COPYFILE_DISABLE=true tar -cvzf "$tarName" $APPNAME
cd -
mv "$tarName" "${SCRIPT_DIR}/"
echo "Built osx."
else
echo "Skipping osx. No $OSX_README file."
fi
if [[ -f $WIN_README ]]; then
echo " ==== Building Windows ===="
tempdir="$(mktemp -d)"
workdir="$tempdir/$APPNAME"
echo $workdir
mkdir -p $workdir
GOOS=windows GOARCH=386 go build -o "${workdir}/${APPNAME}.exe"
# Download pgrun to the work directory
# Copy the bash runtime script to the temp directory
cp "${SCRIPT_DIR}/${WIN_README}" "$workdir/README.md"
cd "$tempdir"
# Make everything executable
chmod -v ugo+x $APPNAME/*
wget -O "${workdir}/pgrun.exe" "https://github.com/joncrlsn/pgrun/raw/master/bin-win/pgrun.exe"
zipName="${tempdir}/${WIN_FILE}"
zip -r "$zipName" $APPNAME
cd -
mv "$zipName" "${SCRIPT_DIR}/"
echo "Built win."
else
echo "Skipping win. No $WIN_README file."
fi