-
Notifications
You must be signed in to change notification settings - Fork 20
/
build-oneclick.sh
executable file
·178 lines (147 loc) · 4.54 KB
/
build-oneclick.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
#!/bin/bash
#
# build-oneclick.sh -- Builds Pharo based One-Click images
#
# Copyright (c) 2010-2011 Lukas Renggli <[email protected]>
#
# directory configuration
BASE_PATH="$(cd "$(dirname "$0")" && pwd)"
BUILD_PATH="${WORKSPACE:=$BASE_PATH/builds}"
IMAGES_PATH="$BASE_PATH/images"
TEMPLATE_PATH="$BASE_PATH/oneclick"
ICONS_PATH="$BASE_PATH/oneclick-icons"
# help function
function display_help() {
echo "$(basename $0) -i input -o output [-n name] [-t title] [-v version] [-c icon] [-w timestamp]"
echo " -i input product name, image from images-directory, or successful jenkins build"
echo " -o output product name (e.g. pharo1.0)"
echo " -n the name of the executable (e.g. pharo)"
echo " -t the title of the application (e.g. Pharo)"
echo " -v the version of the application (e.g. 1.0)"
echo " -c the icon of the application (e.g. Pharo)"
echo " -w a timestamp string (e.g. `date +'%B %d, %Y'`)"
}
# parse options
while getopts ":i:o:n:t:v:c:w:?" OPT ; do
case "$OPT" in
# input
i) if [ -f "$BUILD_PATH/$OPTARG/$OPTARG.image" ] ; then
INPUT_IMAGE="$BUILD_PATH/$OPTARG/$OPTARG.image"
elif [ -f "$BUILD_PATH/$OPTARG.image" ] ; then
INPUT_IMAGE="$BUILD_PATH/$OPTARG.image"
elif [ -f "$IMAGES_PATH/$OPTARG/$OPTARG.image" ] ; then
INPUT_IMAGE="$IMAGES_PATH/$OPTARG/$OPTARG.image"
elif [ -f "$IMAGES_PATH/$OPTARG.image" ] ; then
INPUT_IMAGE="$IMAGES_PATH/$OPTARG.image"
elif [ -n "$WORKSPACE" ] ; then
INPUT_IMAGE=`find -L "$WORKSPACE/../.." -name "$OPTARG.image" | grep "/lastSuccessful/" | head -n 1`
fi
if [ ! -f "$INPUT_IMAGE" ] ; then
echo "$(basename $0): input image not found ($OPTARG)"
exit 1
fi
INPUT_CHANGES="${INPUT_IMAGE%.*}.changes"
if [ ! -f "$INPUT_CHANGES" ] ; then
echo "$(basename $0): input changes not found ($INPUT_CHANGES)"
exit 1
fi
INPUT_PATH=`dirname "$INPUT_IMAGE"`
if [ ! -d "$INPUT_PATH" ] ; then
echo "$(basename $0): input directory not found ($INPUT_PATH)"
exit 1
fi
;;
# output
o) OUTPUT_NAME="$OPTARG" ;;
# settings
n) OPTION_NAME="$OPTARG" ;;
t) OPTION_TITLE="$OPTARG" ;;
v) OPTION_VERSION="$OPTARG" ;;
c) OPTION_ICON="$OPTARG" ;;
w) OPTION_WHEN="$OPTARG" ;;
# show help
\?) display_help
exit 1
;;
esac
done
# check required parameters
if [ -z "$INPUT_IMAGE" ] ; then
echo "$(basename $0): no input product name given"
exit 1
fi
if [ -z "$OUTPUT_NAME" ] ; then
echo "$(basename $0): no output product name given"
exit 1
fi
# check the default paramaters
if [ -z "$OPTION_NAME" ] ; then
OPTION_NAME="$OUTPUT_NAME"
fi
if [ -z "$OPTION_TITLE" ] ; then
OPTION_TITLE="$OUTPUT_NAME"
fi
if [ -z "$OPTION_VERSION" ] ; then
OPTION_VERSION="1.0"
fi
if [ -z "$OPTION_ICON" ] ; then
OPTION_ICON="Pharo"
fi
if [ -z "$OPTION_WHEN" ] ; then
OPTION_WHEN=`date +"%B %d, %Y"`
fi
# prepare output
OUTPUT_PATH="$BUILD_PATH/$OPTION_NAME.app"
OUTPUT_ARCH="$BUILD_PATH/$OUTPUT_NAME.zip"
if [ -f "$OUTPUT_ARCH" ] ; then
rm -rf "$OUTPUT_ARCH"
fi
if [ -d "$OUTPUT_PATH" ] ; then
rm -rf "$OUTPUT_PATH"
fi
# copy over the template
cp -R "$TEMPLATE_PATH" "$OUTPUT_PATH"
# expand all the templates
find "$OUTPUT_PATH" -name "*.template" | while read FILE ; do
sed \
-e "s/%{NAME}/$OPTION_NAME/g" \
-e "s/%{TITLE}/$OPTION_TITLE/g" \
-e "s/%{VERSION}/$OPTION_VERSION/g" \
-e "s/%{WHEN}/$OPTION_WHEN/g" \
"$FILE" > "${FILE%.*}"
chmod --reference="$FILE" "${FILE%.*}"
rm -f "$FILE"
done
# expand all the filenames
find "$OUTPUT_PATH" | while read FILE ; do
TRANSFORMED_FILE=`echo "$FILE" | sed \
-e "s/%{NAME}/$OPTION_NAME/g" \
-e "s/%{TITLE}/$OPTION_TITLE/g" \
-e "s/%{VERSION}/$OPTION_VERSION/g" \
-e "s/%{WHEN}/$OPTION_WHEN/g"`
if [ "$FILE" != "$TRANSFORMED_FILE" ] ; then
mv "$FILE" "$TRANSFORMED_FILE"
fi
done
# copy over the build contents
ls -1 "$INPUT_PATH" | while read FILE ; do
if [ "${FILE##*.}" != "image" ] ; then
if [ "${FILE##*.}" != "changes" ] ; then
cp -R "$INPUT_PATH/$FILE" "$OUTPUT_PATH/Contents/Resources/"
fi
fi
done
# copy over specific files
cp "$INPUT_IMAGE" "$OUTPUT_PATH/Contents/Resources/$OPTION_NAME.image"
cp "$INPUT_CHANGES" "$OUTPUT_PATH/Contents/Resources/$OPTION_NAME.changes"
cp "$ICONS_PATH/$OPTION_ICON.png" "$OUTPUT_PATH/Contents/Resources/Squeak.png"
cp "$ICONS_PATH/$OPTION_ICON.ico" "$OUTPUT_PATH/Contents/Resources/Squeak.ico"
cp "$ICONS_PATH/$OPTION_ICON.icns" "$OUTPUT_PATH/Contents/Resources/Squeak.icns"
# zip up the application
cd "$BUILD_PATH"
zip --quiet --recurse-paths -9 "$OUTPUT_ARCH" "$OPTION_NAME.app"
cd - > /dev/null
# remove the build directory
rm -rf "$OUTPUT_PATH"
# success
exit 0