Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 327 lines (278 sloc) 10.347 kb
22b433a Don't assume that bash is in /bin
Frédéric Perrin authored
1 #!/usr/bin/env bash
2
3 set -e
4 set -u
fccc685 Initial open-source release
MLstate authored
5
6 #PREFIX=/usr
7 INSTALLDIR=$PWD/release_install_root
8
9 # VERSION_MAJOR must be a version number, not text !!
10 VERSION_MAJOR=1.0
11 # VERSION_NAME shall be a string of alphanumeric characters or . + ~ (Debian guidelines)
12 VERSION_NAME=$(tr '[:upper:]' '[:lower:]' <buildinfos/version.txt)
13 VERSION_BUILD=build
14
15 # the version string will be MAJORNAME+BUILDnnnn with nnnn the build number
16 # (MAJORNAME if BUILD is empty)
17
18 msg () {
19 case "$1" in
20 -n) shift; echo -n "$*";;
21 *) echo "$*";;
22 esac
23 }
24
25 . platform_helper.sh
26
27 MYDIR=$PWD
28
29 OPAGENERAL=$(dirname $0)
30
31 TBZ2=""
32 AUTOINSTALL=""
33 DEB="false"
34 PKG="false"
35 WINPKG="false"
36
37 help() {
38 echo "Makes an installation package from an installed OPA (installation"
39 echo "should be done through install_release.sh)."
40 echo "Options"
41 # echo " -prefix <dir> Prefix where the package should install opa by"
42 # echo " default (default $PREFIX)"
43 echo " -dir <dir> Where to get the installed tree (as specified"
44 echo " to install_release.sh; default $INSTALLDIR)"
45 echo " -make-autoinstall <filename> builds an auto-installing archive (you will need"
46 echo " MakeSelf installed). {} in filename is replaced by"
47 echo " the version string"
48 echo " -make-tbz2 <filename.tar.bz2>"
49 echo " -make-deb Build a debian package"
50 echo " -make-pkg Build a Macintosh .pkg"
51 echo " -make-winpkg Build a pakage for ms-windows (need nsis)"
52 echo
53 }
54
55 while [ $# -gt 0 ]; do
56 case $1 in
57 -make-tbz2)
58 if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
59 shift
60 TBZ2="$1";;
61 -make-autoinstall)
62 if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
63 shift
64 AUTOINSTALL="$1";;
65 -make-deb)
66 DEB=true;;
67 -make-pkg)
68 if [ -z "$OPAGENERAL" ]; then
69 echo "Error: you need to define \$OPAGENERAL to build a mac package"
70 exit 1
71 fi
72 PKG=true;;
73 -make-winpkg)
74 if [ -z "$OPAGENERAL" ]; then
75 echo "Error: you need to define \$OPAGENERAL to build a windows package"
76 exit 1
77 fi
78 WINPKG=true;;
79 # -prefix)
80 # if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
81 # shift
82 # PREFIX="$1";;
83 -dir)
84 if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
85 shift
86 INSTALLDIR="$1";;
87 -help|--help|-h)
88 help
89 exit 0;;
90 *)
91 echo "Unknown option $1."
92 help
93 exit 1;;
94 esac
95 shift
96 done
97
98 if [ $(id -u) -ne 0 ] && [[ -z "$IS_MAC" ]] || [ -n "${MAKE_PACKAGE_NON_ROOT:-""}" ]; then
99 msg "Error: running as user."
100 msg "This would generate wrong packages, please run within fakeroot."
101 exit 3
102 fi
103
104 if [ ${INSTALLDIR:0:1} != "/" ]; then
105 msg "Error: please specify an absolute dir"
106 exit 1
107 fi
108
109 BUILDNUM=$($INSTALLDIR/lib/opa/bin/opa-bin --version 2>&1 | sed 's/.*build \([0-9]\+\).*/\1/')
110 VERSION_STRING=${VERSION_MAJOR}${VERSION_NAME}$(if [ -n "$VERSION_BUILD" ]; then echo "+$VERSION_BUILD$BUILDNUM"; fi)
111
112 msg "Making package from installation in $INSTALLDIR, with OPA version $VERSION_STRING."
113
114 if [ -n "$TBZ2" ]; then
115 msg "Making $TBZ2 (to be decompressed at the installation prefix)"
116 msg "(after decompression in <prefix> (eg. /usr/local), the user will"
117 msg "need to run <prefix>/share/opa/install/sh --dir <prefix>)"
118 tar -C $INSTALLDIR -cj * -f $MYDIR/$TBZ2
119 fi
120
121 ###################################
122 # auto-extract package generation #
123 ###################################
124
125 if [ -n "$AUTOINSTALL" ]; then
126 AUTOINSTALL=${AUTOINSTALL//\{\}/$VERSION_STRING}
127 msg "Making $AUTOINSTALL"
128 cat >"$INSTALLDIR/install.sh" <<EOF
22b433a Don't assume that bash is in /bin
Frédéric Perrin authored
129 #!/usr/bin/env bash
130
131 set -e
132 set -u
fccc685 Initial open-source release
MLstate authored
133
134 if [ -n "\${1:-}" ]; then
135 echo "Installing in \$1"
136 INSTALL="\$1"
137 else
138 PREFIX=\$HOME/mlstate-opa
139 if [ "\$(id -u)" -eq 0 ]; then PREFIX=/usr/local; fi
140 echo "Please specify install prefix. (default \$PREFIX)"
141 INSTALL=""
142 while [ -z "\$INSTALL" ]; do
143 read INSTALL
144 if [ -z "\$INSTALL" ]; then INSTALL="\$PREFIX"
145 elif [ "\${INSTALL:0:1}" != "/" ]; then
146 echo "Please provide an absolute directory"
147 INSTALL=""
148 else
149 mkdir -p "\$INSTALL" || {
150 echo "Could not create directory \$INSTALL. Please specify another install prefix"
151 INSTALL=""
152 }
153 fi
154 done
155 fi
156
157 echo "Installing, please wait..."
158
159 mkdir -p "\$INSTALL"
160 GLOBIGNORE=install.sh
161 cp -a * "\$INSTALL"
162
163 \$INSTALL/share/opa/install.sh --quiet --dir "\$INSTALL"
164
165 echo
166 echo "Done !"
167 echo "Documentation is in \$INSTALL/share/doc/opa"
168 echo "If you want to uninstall, run \$INSTALL/share/opa/uninstall.sh"
169 EOF
170 chmod a+x "$INSTALLDIR/install.sh"
171
172 cat >"$INSTALLDIR/share/opa/uninstall.sh" <<"EOF"
22b433a Don't assume that bash is in /bin
Frédéric Perrin authored
173 #!/usr/bin/env bash
174
175 set -e
176 set -u
fccc685 Initial open-source release
MLstate authored
177
178 SCRIPT="$0"
179 if [ "${SCRIPT:0:1}" != "/" ]; then
180 SCRIPT=$PWD/$SCRIPT
181 fi
182
183 # Always run from /tmp
184 TMPDIR="${TMPDIR:-/tmp}"
185 if [ $# -eq 0 ] || [ "${SCRIPT:0:${#TMPDIR}}" != "$TMPDIR" ]; then
186 INSTALLDIR=${SCRIPT%/share/opa/*}
187 X=$(mktemp $TMPDIR/uninstall_opa.XXXXX)
188 cp --preserve=mode "$0" "$X"
189 exec "$X" "$INSTALLDIR" "$@"
190 else
191 if [ $# -ne 1 ]; then echo "Error: bad number of arguments"; exit 1; fi
192 INSTALLDIR="$1"
193 trap "rm -f $0" EXIT
194 fi
195
196 echo -n "Going to remove OPA from $INSTALLDIR. Proceed ? "
197 read yesno
198 if [ "${yesno:0:1}" != "y" ]; then exit 0; fi
199
200 "$INSTALLDIR"/share/opa/install.sh --dir "$INSTALLDIR" --uninstall
201
202 P=$PWD; cd "$INSTALLDIR"
203 rm -f \
204 EOF
205 ( cd $INSTALLDIR; find . ! -type d | sed 's/^\(.*\)$/ "\1" \\/' ) >>$INSTALLDIR/share/opa/uninstall.sh
206 echo >>"$INSTALLDIR/share/opa/uninstall.sh"
207 cat >>"$INSTALLDIR/share/opa/uninstall.sh" <<"EOF"
208 cd $P
209
210 for DIR in "$INSTALLDIR/share/opa" "$INSTALLDIR/share/doc/opa" "$INSTALLDIR/lib/opa"; do
211 R=0
212 find $DIR \( -type d -empty \) -delete || R=$?
213 if [ $R -ne 0 ] || [ -d $DIR ]; then
214 echo "Warning: some files left in $DIR"
215 fi
216 done
217
218 set +e
219 rmdir "$INSTALLDIR/share/doc" 2>/dev/null
220 rmdir "$INSTALLDIR/share" 2>/dev/null
221 rmdir "$INSTALLDIR/lib" 2>/dev/null
222 rmdir "$INSTALLDIR/bin" 2>/dev/null
223 rmdir "$INSTALLDIR" 2>/dev/null
224
225 echo "Done."
226 EOF
227 chmod a+x "$INSTALLDIR/share/opa/uninstall.sh"
228
229 makeself --bzip2 $INSTALLDIR "$MYDIR/$AUTOINSTALL" "$AUTOINSTALL" ./install.sh
230 msg "Generated $AUTOINSTALL"
231 fi
232
233 #############################
234 # MacOSX package generation #
235 #############################
236 if [ "$PKG" = "true" ]; then
237 OS_VARIANT=`sw_vers -productVersion`
238 PKG_NAME="OPA $VERSION_MAJOR $VERSION_NAME Build $BUILDNUM for MacOS $OS_VARIANT"
239 echo "Making package '$MYDIR/$PKG_NAME.pkg'"
240 /Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker --root $INSTALLDIR --resources $OPAGENERAL/installer/Mac/Resources/ --scripts $OPAGENERAL/installer/Mac/Scripts --info $OPAGENERAL/installer/Mac/Info.plist --id com.mlstate.opa.pkg -o "$MYDIR/$PKG_NAME.pkg" -n $BUILDNUM --domain system --root-volume-only --discard-forks -m --verbose --title "OPA $VERSION_MAJOR $VERSION_NAME"
241 echo "Creating image '$MYDIR/$PKG_NAME.dmg'"
242 hdiutil create "$MYDIR/$PKG_NAME.dmg" -srcfolder "$MYDIR/$PKG_NAME.pkg"
243 fi
244
245
246 ################################
247 # MsWindows package generation #
248 ################################
249 if [ "$WINPKG" = "true" ]; then
250 PKG_NAME="OPA $VERSION_MAJOR $VERSION_NAME Build $BUILDNUM"
251 rm -rf pkg_ms_windows
252 mkdir -p pkg_ms_windows
253 # Copy
254 # -everyting
255 cp -a $INSTALLDIR/* pkg_ms_windows/
256 # -nsis script
257 cp $OPAGENERAL/ms_windows/opa_pkg/install.nsi pkg_ms_windows
258 # -opa.bat install
259 cat $OPAGENERAL/ms_windows/opa_pkg/opa.bat | grep -v "^REM" | grep -v "^$" > pkg_ms_windows/bin/opa.bat
260 # Some tidying
261 mkdir -p pkg_ms_windows/bin/ocaml
262 mkdir -p pkg_ms_windows/bin/uninstall
263 mv pkg_ms_windows/share/opa/examples pkg_ms_windows/examples
264 mv pkg_ms_windows/bin/opa-bin pkg_ms_windows/bin/runopa.exe
265 # hidding ocaml executable to be oustide of PATH
266 mv pkg_ms_windows/bin/ocamlopt.opt.exe pkg_ms_windows/bin/ocaml/ocamlopt.opt.exe
267 cp $OPAGENERAL/ms_windows/opa_pkg/opa_logo*.ico pkg_ms_windows/bin/uninstall
268 /cygdrive/c/Program\ Files/NSIS/makensis.exe pkg_ms_windows/install.nsi
269 echo The package is in pkg_ms_windows/installer.exe
270 fi
271
272
273
274
275 #############################
276 # Debian package generation #
277 #############################
278
279 if [ "$DEB" = "true" ]; then
280 MAINTAINER="Louis Gesbert <louis.gesbert@mlstate.com>"
281 PREFIX=/usr
282 WORKDIR=$(mktemp -d /tmp/mkdeb.XXXXX)
283 cd $WORKDIR
284 DEBROOT=$WORKDIR/debian
285 mkdir -p $DEBROOT$PREFIX
286 mkdir -p $DEBROOT/DEBIAN
287 mkdir _build
288 cp -a $INSTALLDIR/* $DEBROOT$PREFIX
289 find debian -type d | xargs chmod 755
290
291 cat > debian/DEBIAN/control <<EOF
292 Package: opa
293 Version: $VERSION_STRING
294 Section: devel
295 Priority: optional
296 Architecture: $(dpkg --print-architecture)
297 Installed-Size: $(du -s $INSTALLDIR | cut -f1)
298 Pre-Depends: debconf
299 Depends: libc6 (>= 2.3.2), libgdbm3, libssl0.9.8, libssl-dev, zlib1g, zlib1g-dev, libjpeg62, libpng12-0, libgif4
300 Maintainer: $MAINTAINER
301 Description: The unified language for web 2.0 development
302 OPA is a unified programming language for web development. This self-contained
303 package contains the OPA compiler, that compiles stand-alone web servers
304 including AJAX features, database, etc. from single source files.
305 EOF
306
307 # The wrapper scripts are always bound to $PREFIX, pre-generate them...
308 $DEBROOT$PREFIX/share/opa/install.sh --quiet --dir "$DEBROOT$PREFIX" --prefix "$PREFIX"
309 rm $DEBROOT$PREFIX/share/opa/install.sh
310
311 mkdir -p $DEBROOT$PREFIX/share/lintian/overrides
312 cat > $DEBROOT$PREFIX/share/lintian/overrides/opa <<EOF
313 # The package itself is in AGPL, but includes other software and lists their licenses
314 # in the copyright file
315 opa binary: copyright-should-refer-to-common-license-file-for-lgpl
316 EOF
317
318 dpkg-deb --build debian _build
319 PACKAGE=$(ls _build/*.deb)
320 mv $PACKAGE $MYDIR
321 msg "Generated $(basename "$PACKAGE")"
322 cd $MYDIR
323 rm -rf /tmp/${WORKDIR#/tmp/}
324 fi
325
326 msg 'Done !'
Something went wrong with that request. Please try again.