Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

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