Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 328 lines (279 sloc) 10.413 kb
22b433a @fperrin Don't assume that bash is in /bin
fperrin 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 @fperrin Don't assume that bash is in /bin
fperrin 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 @fperrin Don't assume that bash is in /bin
fperrin 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
7affb20 @BourgerieQuentin [fix] package: manpage should be uninstalled
BourgerieQuentin authored
210 for DIR in "$INSTALLDIR/share/opa" "$INSTALLDIR/share/man" "$INSTALLDIR/share/doc/opa" "$INSTALLDIR/lib/opa"; do
fccc685 Initial open-source release
MLstate authored
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
7affb20 @BourgerieQuentin [fix] package: manpage should be uninstalled
BourgerieQuentin authored
219 rmdir "$INSTALLDIR/share/man" 2>/dev/null
fccc685 Initial open-source release
MLstate authored
220 rmdir "$INSTALLDIR/share/doc" 2>/dev/null
221 rmdir "$INSTALLDIR/share" 2>/dev/null
222 rmdir "$INSTALLDIR/lib" 2>/dev/null
223 rmdir "$INSTALLDIR/bin" 2>/dev/null
224 rmdir "$INSTALLDIR" 2>/dev/null
225
226 echo "Done."
227 EOF
228 chmod a+x "$INSTALLDIR/share/opa/uninstall.sh"
229
230 makeself --bzip2 $INSTALLDIR "$MYDIR/$AUTOINSTALL" "$AUTOINSTALL" ./install.sh
231 msg "Generated $AUTOINSTALL"
232 fi
233
234 #############################
235 # MacOSX package generation #
236 #############################
237 if [ "$PKG" = "true" ]; then
238 OS_VARIANT=`sw_vers -productVersion`
239 PKG_NAME="OPA $VERSION_MAJOR $VERSION_NAME Build $BUILDNUM for MacOS $OS_VARIANT"
240 echo "Making package '$MYDIR/$PKG_NAME.pkg'"
241 /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"
242 echo "Creating image '$MYDIR/$PKG_NAME.dmg'"
243 hdiutil create "$MYDIR/$PKG_NAME.dmg" -srcfolder "$MYDIR/$PKG_NAME.pkg"
244 fi
245
246
247 ################################
248 # MsWindows package generation #
249 ################################
250 if [ "$WINPKG" = "true" ]; then
251 PKG_NAME="OPA $VERSION_MAJOR $VERSION_NAME Build $BUILDNUM"
252 rm -rf pkg_ms_windows
253 mkdir -p pkg_ms_windows
254 # Copy
255 # -everyting
256 cp -a $INSTALLDIR/* pkg_ms_windows/
257 # -nsis script
258 cp $OPAGENERAL/ms_windows/opa_pkg/install.nsi pkg_ms_windows
259 # -opa.bat install
260 cat $OPAGENERAL/ms_windows/opa_pkg/opa.bat | grep -v "^REM" | grep -v "^$" > pkg_ms_windows/bin/opa.bat
261 # Some tidying
262 mkdir -p pkg_ms_windows/bin/ocaml
263 mkdir -p pkg_ms_windows/bin/uninstall
264 mv pkg_ms_windows/share/opa/examples pkg_ms_windows/examples
265 mv pkg_ms_windows/bin/opa-bin pkg_ms_windows/bin/runopa.exe
266 # hidding ocaml executable to be oustide of PATH
267 mv pkg_ms_windows/bin/ocamlopt.opt.exe pkg_ms_windows/bin/ocaml/ocamlopt.opt.exe
268 cp $OPAGENERAL/ms_windows/opa_pkg/opa_logo*.ico pkg_ms_windows/bin/uninstall
269 /cygdrive/c/Program\ Files/NSIS/makensis.exe pkg_ms_windows/install.nsi
270 echo The package is in pkg_ms_windows/installer.exe
271 fi
272
273
274
275
276 #############################
277 # Debian package generation #
278 #############################
279
280 if [ "$DEB" = "true" ]; then
281 MAINTAINER="Louis Gesbert <louis.gesbert@mlstate.com>"
282 PREFIX=/usr
283 WORKDIR=$(mktemp -d /tmp/mkdeb.XXXXX)
284 cd $WORKDIR
285 DEBROOT=$WORKDIR/debian
286 mkdir -p $DEBROOT$PREFIX
287 mkdir -p $DEBROOT/DEBIAN
288 mkdir _build
289 cp -a $INSTALLDIR/* $DEBROOT$PREFIX
290 find debian -type d | xargs chmod 755
291
292 cat > debian/DEBIAN/control <<EOF
293 Package: opa
294 Version: $VERSION_STRING
295 Section: devel
296 Priority: optional
297 Architecture: $(dpkg --print-architecture)
298 Installed-Size: $(du -s $INSTALLDIR | cut -f1)
299 Pre-Depends: debconf
300 Depends: libc6 (>= 2.3.2), libgdbm3, libssl0.9.8, libssl-dev, zlib1g, zlib1g-dev, libjpeg62, libpng12-0, libgif4
301 Maintainer: $MAINTAINER
302 Description: The unified language for web 2.0 development
303 OPA is a unified programming language for web development. This self-contained
304 package contains the OPA compiler, that compiles stand-alone web servers
305 including AJAX features, database, etc. from single source files.
306 EOF
307
308 # The wrapper scripts are always bound to $PREFIX, pre-generate them...
309 $DEBROOT$PREFIX/share/opa/install.sh --quiet --dir "$DEBROOT$PREFIX" --prefix "$PREFIX"
310 rm $DEBROOT$PREFIX/share/opa/install.sh
311
312 mkdir -p $DEBROOT$PREFIX/share/lintian/overrides
313 cat > $DEBROOT$PREFIX/share/lintian/overrides/opa <<EOF
314 # The package itself is in AGPL, but includes other software and lists their licenses
315 # in the copyright file
316 opa binary: copyright-should-refer-to-common-license-file-for-lgpl
317 EOF
318
319 dpkg-deb --build debian _build
320 PACKAGE=$(ls _build/*.deb)
321 mv $PACKAGE $MYDIR
322 msg "Generated $(basename "$PACKAGE")"
323 cd $MYDIR
324 rm -rf /tmp/${WORKDIR#/tmp/}
325 fi
326
327 msg 'Done !'
Something went wrong with that request. Please try again.