-
Notifications
You must be signed in to change notification settings - Fork 37
/
makebindist
executable file
·127 lines (105 loc) · 2.99 KB
/
makebindist
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
#!/bin/sh
if [ $# -eq 1 ]; then
SNAPSHOT_DATE=""
VERSION="$1"
elif ( [ $# -eq 3 ] && [ "$1" == "-s" ] ); then
SNAPSHOT_DATE="$2"
VERSION="$3"
else
echo "usage: makebindist [-s <snapshot date>] <version>" 1>&2
exit 1
fi
BASEDIR="`dirname "$0"`"
if [ $? -ne 0 ]; then
echo "WARNING: No dirname utility found!"
echo " Script will only work if invoked from its parent directory."
BASEDIR="."
fi
cd "${BASEDIR}"
GIT_CLEAN_OUTPUT="$(git clean -n -d dist)"
if [ $? -ne 0 ]; then
echo "Error value returned from \"git clean -n -d dist\". Cannot check for untracked files."
exit 1
fi
if [ ! -z "${GIT_CLEAN_OUTPUT}" ]; then
echo "Directory \"dist\" is not clean. Please stash all untracked files:"
echo "${GIT_CLEAN_OUTPUT}" | while read GIT_CLEAN_LINE; do echo " $(echo "${GIT_CLEAN_LINE}" | sed 's/^Would remove //g')"; done
exit 1
fi
GIT_STATUS_OUTPUT="$(git status -s dist)"
if [ $? -ne 0 ]; then
echo "Error value returned from \"git status -s dist\". Cannot check for modifications."
exit 1
fi
if [ ! -z "${GIT_STATUS_OUTPUT}" ]; then
echo "Directory \"dist\" is not clean. Please stash all modifications:"
echo "${GIT_STATUS_OUTPUT}" | while read GIT_STATUS_LINE; do echo " ${GIT_STATUS_LINE}"; done
exit 1
fi
if [ ! -f "dist/lib/hfsx.jar" ]; then
echo "No hfsx.jar binary in \"dist/lib\". Did you forget to build it?"
exit 1
fi
RELEASE_DIR="releases/${VERSION}${SNAPSHOT_DATE:+-snapshot_${SNAPSHOT_DATE}}"
ZIPFILE="hfsexplorer-${VERSION}${SNAPSHOT_DATE:+-snapshot_${SNAPSHOT_DATE}}-bin.zip"
match () {
local SUBFILE="$1"
local DIRNAME="$2"
CMPRES=`expr "${SUBFILE}" : "${DIRNAME}"`
RETVAL="$?"
if [ "${RETVAL}" -eq 0 ]; then
if [ -d "${SUBFILE}" ]; then
echo "`pwd`/${SUBFILE}/"
rm -r "${SUBFILE}"
else
echo "`pwd`/${SUBFILE}"
rm "${SUBFILE}"
fi
elif [ "${RETVAL}" -eq 1 ]; then
if [ -d "${SUBFILE}" ]; then
recursiveRmdir "${DIRNAME}" "${SUBFILE}"
fi
fi
}
recursiveRmdir () {
local DIRNAME="$1"
#local DIRNAMELEN="${#DIRNAME}"
shift 1
while [ ! $# -eq 0 ]; do
local FILE="$1"
shift 1
if [ -d "${FILE}" ]; then
pushd "${FILE}" > /dev/null
for SUBFILE in .*; do
if [ ! "${SUBFILE}" = ".." ] && [ ! "${SUBFILE}" = "." ]; then
match "${SUBFILE}" "${DIRNAME}"
fi
done
for SUBFILE in *; do
if [ ! "${SUBFILE}" = "*" ]; then
match "${SUBFILE}" "${DIRNAME}"
fi
done
popd > /dev/null
else
match "${FILE}" "${DIRNAME}"
fi
done
}
TEMPDIR=disttemp.~
echo "Cleaning temp dir..."
rm -r $TEMPDIR
mkdir $TEMPDIR
echo "Copying files..."
cp -r dist/* $TEMPDIR
echo "Removing CVS directories..."
recursiveRmdir "^CVS$" "$TEMPDIR"
echo "Building zip file..."
cd $TEMPDIR
if [ ! -d "../${RELEASE_DIR}" ]; then
mkdir -p "../${RELEASE_DIR}"
fi
rm -fv "../${RELEASE_DIR}/${ZIPFILE}"
zip -9 -r "../${RELEASE_DIR}/${ZIPFILE}" *
cd ..
echo "Done! Zip file generated at: ${RELEASE_DIR}/${ZIPFILE}"