Skip to content

Commit 6f2286d

Browse files
committed
implement a more efficient dist
1 parent 96a5043 commit 6f2286d

File tree

3 files changed

+92
-7
lines changed

3 files changed

+92
-7
lines changed

Makefile

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
GOCC := go
88

99
# Program version
10-
VERSION := $(shell git describe --always --tags)
10+
VERSION ?= $(shell git describe --always --tags)
1111

1212
# Binary name for bintray
1313
BIN_NAME=git-user
@@ -36,6 +36,8 @@ INSTALL_PATH=$(GOPATH)/${REPO_HOST_URL}/${OWNER}/${PROJECT_NAME}
3636

3737
FIND_DIST:=find * -type d -exec
3838

39+
BUILD_DIR=dist
40+
3941
default: build
4042

4143
help:
@@ -88,12 +90,12 @@ build-all: bootstrap-dist
8890
-output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" .
8991

9092
dist: build-all
91-
cd dist && \
92-
$(FIND_DIST) cp ../LICENSE {} \; && \
93-
$(FIND_DIST) cp ../README.md {} \; && \
94-
$(FIND_DIST) tar -zcf ${PROJECT_NAME}-${VERSION}-{}.tar.gz {} \; && \
95-
$(FIND_DIST) zip -r ${PROJECT_NAME}-${VERSION}-{}.zip {} \; && \
96-
cd ..
93+
install/dist.sh "linux-386" "${PROJECT_NAME}-${VERSION}-linux-x32"
94+
install/dist.sh "linux-amd64" "${PROJECT_NAME}-${VERSION}-linux-x64"
95+
install/dist.sh "darwin-386" "${PROJECT_NAME}-${VERSION}-osx-x32"
96+
install/dist.sh "darwin-amd64" "${PROJECT_NAME}-${VERSION}-osx-x64"
97+
install/dist.sh "windows-386" "${PROJECT_NAME}-${VERSION}-windows-x32"
98+
install/dist.sh "windows-amd64" "${PROJECT_NAME}-${VERSION}-windows-x64"
9799

98100
docs:
99101
cd genman && ${GOCC} build -ldflags "-X main.version=${VERSION}"

install/dist.sh

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
3+
pushd () {
4+
command pushd "$@" > /dev/null
5+
}
6+
7+
popd () {
8+
command popd > /dev/null
9+
}
10+
11+
12+
if [ "$#" -ne 2 ]; then
13+
echo "Usage: $0 SRCDIRNAME DISTNAME" >&2
14+
exit 1
15+
fi
16+
17+
SRCNAME="$1"
18+
DSTNAME="$2"
19+
20+
SRC="dist/${SRCNAME}"
21+
DST="dist/${DSTNAME}"
22+
23+
if [ ! -d "${SRC}" ]; then
24+
echo "Source directory \"${SRC}\" does not exist"
25+
exit 1
26+
fi
27+
28+
# Remove target if it exists
29+
rm -rf "${DST}"
30+
# Setup target
31+
cp -r "${SRC}" "${DST}"
32+
33+
# echo "Packaging distribution"
34+
# Copy dist files
35+
cp LICENSE "${DST}"
36+
cp README.md "${DST}"
37+
38+
if [[ "${DST}" != *"windows"* ]]; then
39+
cp -r man "${DST}"
40+
cp install/install-nix.sh "${DST}/install.sh"
41+
# echo "Compressing tarbell"
42+
pushd dist || exit
43+
rm -f "${DSTNAME}.tar.gz"
44+
tar -zcf "${DSTNAME}.tar.gz" "${DSTNAME}"
45+
popd
46+
else
47+
# echo "Compressing zip file"
48+
pushd dist || exit
49+
rm -f "${DSTNAME}.zip"
50+
zip -qr "${DSTNAME}.zip" "${DSTNAME}"
51+
popd
52+
fi
53+
54+
rm -rf ${DST}

install/install-nix.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/bin/bash
2+
3+
# Check we have permissions
4+
# if [[ $EUID -ne 0 ]]; then
5+
# echo "This script must be run as root" 1>&2
6+
# exit 1
7+
# fi
8+
9+
if [ "$1" == "-u" ]||[ "$1" == "--uninstall" ]; then
10+
echo "Uninstalling application"
11+
rm -f "/usr/local/bin/git-user"
12+
rm -f "/usr/local/share/man/man1/git-user*"
13+
exit 0;
14+
fi
15+
16+
# Remove the app if it already exists
17+
APP="/usr/local/bin/git-user"
18+
if [ -d "$APP" ]; then
19+
echo "Removing existing application"
20+
rm -rf "${APP}"
21+
fi
22+
23+
# Copy our executable to /usr/local/bin
24+
echo "Installing git-user"
25+
cp -f git-user /usr/local/bin
26+
27+
# Copy our man files
28+
mkdir -p /usr/local/share/man/man1
29+
cp man/*.1 /usr/local/share/man/man1

0 commit comments

Comments
 (0)