-
Notifications
You must be signed in to change notification settings - Fork 37
/
makesrcdist
executable file
·144 lines (122 loc) · 3.55 KB
/
makesrcdist
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
#!/bin/bash
if [ $# -eq 1 ]; then
SNAPSHOT_DATE=""
VERSION="$1"
elif ( [ $# -eq 3 ] && [ "$1" == "-s" ] ); then
SNAPSHOT_DATE="$2"
VERSION="$3"
else
echo "usage: makesrcdist [-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)"
if [ $? -ne 0 ]; then
echo "Error value returned from \"git clean -n -d\". Cannot check for untracked files."
exit 1
fi
if [ ! -z "${GIT_CLEAN_OUTPUT}" ]; then
echo "Source tree 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)"
if [ $? -ne 0 ]; then
echo "Error value returned from \"git status -s\". Cannot check for modifications."
exit 1
fi
if [ ! -z "${GIT_STATUS_OUTPUT}" ]; then
echo "Source tree 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 "Found an hfsx.jar binary in \"dist/lib\". This should not be present when building the source distribution."
exit 1
fi
RELEASE_DIR="releases/${VERSION}${SNAPSHOT_DATE:+-snapshot_${SNAPSHOT_DATE}}"
ZIPFILE="hfsexplorer-${VERSION}${SNAPSHOT_DATE:+-snapshot_${SNAPSHOT_DATE}}-src.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=srcdisttemp.~
echo "Cleaning temp dir..."
rm -r $TEMPDIR
mkdir $TEMPDIR
echo "Copying files..."
cp * $TEMPDIR
cp -r dist $TEMPDIR
cp -r lib $TEMPDIR
cp -r resource $TEMPDIR
cp -r src $TEMPDIR
echo "Removing CVS directories..."
recursiveRmdir "^CVS$" "$TEMPDIR"
echo "Removing emacs backup files (*~)..."
recursiveRmdir ".*~$" "$TEMPDIR"
echo "Removing emacs temporary files (#*#)..."
recursiveRmdir "^#.*#$" "$TEMPDIR"
echo "Removing Thumbs.db files..."
recursiveRmdir "^Thumbs\.db$" "$TEMPDIR"
echo "Removing .DS_Store files..."
recursiveRmdir "^\.DS_Store$" "$TEMPDIR"
echo "Removing .cvsignore files..."
recursiveRmdir "^\.cvsignore$" "$TEMPDIR"
echo "Removing dist build scripts..."
rm -v "${TEMPDIR}/makebindist"
rm -v "${TEMPDIR}/makesrcdist"
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}"