-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild-oneclick.sh
executable file
·222 lines (186 loc) · 6.04 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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/bin/bash
#
# build-oneclick.sh -- Builds Pharo based One-Click images
#
# Copyright (c) 2010-2011 Lukas Renggli <[email protected]>
# 2012 Christophe Demarey
#
# directory configuration
BASE_PATH="$(cd "$(dirname "$0")" && pwd)"
BUILD_PATH="${WORKSPACE:=$BASE_PATH/builds}"
IMAGES_PATH="$BASE_PATH/images"
TEMPLATE_PATH="$BASE_PATH/one-click/templates"
ICONS_PATH="$BASE_PATH/one-click/icons"
VM_PATH="$BUILD_PATH/vm"
# 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 [ -f "$WORKSPACE/$OPTARG.zip" ] ; then
unzip -q "$WORKSPACE/$OPTARG.zip"
rm -rf "$WORKSPACE/$OPTARG.zip"
INPUT_IMAGE=`find "$WORKSPACE" -name "$OPTARG.image"`
elif [ -n "$WORKSPACE" ] ; then
INPUT_IMAGE=`find "$WORKSPACE" -name "$OPTARG.image"`
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
if [ ! -e "$BUILD_PATH" ] ; then
mkdir "$BUILD_PATH"
fi
PATH_VERSION=`echo "$OPTION_VERSION" | sed 's/\.//'`
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
mkdir -p "$OUTPUT_PATH/Contents/Resources/"
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 Linux VM files
LINUX_VM_PATH="pharo-linux-stable.zip"
wget http://files.pharo.org/get-files/$PATH_VERSION/$LINUX_VM_PATH
if [ -f "$LINUX_VM_PATH" ] ; then
unzip -q "$LINUX_VM_PATH" -d "$OUTPUT_PATH/tmp"
mv "$OUTPUT_PATH/tmp/" "$OUTPUT_PATH/Contents/Linux/"
else
echo "Warning: Cannot find Linux VM!"
fi
# copy over Mac OS VM files
MAC_VM_PATH="pharo-mac-stable.zip"
wget http://files.pharo.org/get-files/$PATH_VERSION/$MAC_VM_PATH
if [ -f "$MAC_VM_PATH" ] ; then
unzip -q "$MAC_VM_PATH" -d "$OUTPUT_PATH/tmp"
#Ensuring bin and plugins
mv "$OUTPUT_PATH/tmp/Pharo.app/Contents/MacOS" "$OUTPUT_PATH/Contents"
# Need to add this ugly '*' outside double-quotes to be able to copy the content of the folder (and not the folder itself) on linux
cp -R "$OUTPUT_PATH/tmp/Pharo.app/Contents/Resources/"* "$OUTPUT_PATH/Contents/Resources"
rm -rf "$OUTPUT_PATH/tmp"
else
echo "Warning: Cannot find Mac OS VM!"
fi
# copy over Windows VM files
WIN_VM_PATH="pharo-win-stable.zip"
wget http://files.pharo.org/get-files/$PATH_VERSION/$WIN_VM_PATH
if [ -f "$WIN_VM_PATH" ] ; then
unzip -q "$WIN_VM_PATH" -d "$OUTPUT_PATH"
else
echo "Warning: Cannot find Windows VM!"
fi
# 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 -R "$ICONS_PATH/"* "$OUTPUT_PATH/Contents/Resources" # Need to add this ugly '*' outside double-quotes to be able to copy the content of the folder (and not the folder itself) on linux
# zip up the application
cd "$BUILD_PATH"
zip -q -r -9 "$OUTPUT_ARCH" "$OPTION_NAME.app"
cd - > /dev/null
# remove the build directory
rm -rf "$OUTPUT_PATH"
# success
exit 0