forked from unsound/hfsexplorer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
makesrcdist.sh
executable file
·136 lines (114 loc) · 3.27 KB
/
makesrcdist.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
#!/bin/bash
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
ZIPFILE=hfsexplorer-current-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.sh"
rm -v "${TEMPDIR}/makesrcdist.sh"
echo "Setting execute permissions for shell scripts..."
chmod a+x $TEMPDIR/*.sh
chmod a+x $TEMPDIR/dist/*.sh
echo "Building zip file..."
cd $TEMPDIR
if [ ! -d ../releases ]; then
mkdir ../releases
fi
rm -fv ../releases/${ZIPFILE}
zip -9 -r ../releases/${ZIPFILE} *
cd ..
echo "Done! Zip file generated in releases/${ZIPFILE}"