Skip to content
This repository
tree: 1d12cb5d34
Fetching contributors…

Cannot retrieve contributors at this time

executable file 326 lines (278 sloc) 10.347 kb
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 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326
#!/usr/bin/env bash

set -e
set -u

#PREFIX=/usr
INSTALLDIR=$PWD/release_install_root

# VERSION_MAJOR must be a version number, not text !!
VERSION_MAJOR=1.0
# VERSION_NAME shall be a string of alphanumeric characters or . + ~ (Debian guidelines)
VERSION_NAME=$(tr '[:upper:]' '[:lower:]' <buildinfos/version.txt)
VERSION_BUILD=build

# the version string will be MAJORNAME+BUILDnnnn with nnnn the build number
# (MAJORNAME if BUILD is empty)

msg () {
    case "$1" in
        -n) shift; echo -n "$*";;
        *) echo "$*";;
    esac
}

. platform_helper.sh

MYDIR=$PWD

OPAGENERAL=$(dirname $0)

TBZ2=""
AUTOINSTALL=""
DEB="false"
PKG="false"
WINPKG="false"

help() {
    echo "Makes an installation package from an installed OPA (installation"
    echo "should be done through install_release.sh)."
    echo "Options"
    # echo " -prefix <dir> Prefix where the package should install opa by"
    # echo " default (default $PREFIX)"
    echo " -dir <dir> Where to get the installed tree (as specified"
    echo " to install_release.sh; default $INSTALLDIR)"
    echo " -make-autoinstall <filename> builds an auto-installing archive (you will need"
    echo " MakeSelf installed). {} in filename is replaced by"
    echo " the version string"
    echo " -make-tbz2 <filename.tar.bz2>"
    echo " -make-deb Build a debian package"
    echo " -make-pkg Build a Macintosh .pkg"
    echo " -make-winpkg Build a pakage for ms-windows (need nsis)"
    echo
}

while [ $# -gt 0 ]; do
    case $1 in
        -make-tbz2)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
TBZ2="$1";;
        -make-autoinstall)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
AUTOINSTALL="$1";;
        -make-deb)
            DEB=true;;
        -make-pkg)
            if [ -z "$OPAGENERAL" ]; then
                echo "Error: you need to define \$OPAGENERAL to build a mac package"
                exit 1
            fi
            PKG=true;;
        -make-winpkg)
            if [ -z "$OPAGENERAL" ]; then
                echo "Error: you need to define \$OPAGENERAL to build a windows package"
                exit 1
            fi
            WINPKG=true;;
        # -prefix)
        # if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
        # shift
        # PREFIX="$1";;
        -dir)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
INSTALLDIR="$1";;
        -help|--help|-h)
            help
exit 0;;
        *)
            echo "Unknown option $1."
            help
exit 1;;
    esac
    shift
done

if [ $(id -u) -ne 0 ] && [[ -z "$IS_MAC" ]] || [ -n "${MAKE_PACKAGE_NON_ROOT:-""}" ]; then
    msg "Error: running as user."
    msg "This would generate wrong packages, please run within fakeroot."
    exit 3
fi

if [ ${INSTALLDIR:0:1} != "/" ]; then
    msg "Error: please specify an absolute dir"
    exit 1
fi

BUILDNUM=$($INSTALLDIR/lib/opa/bin/opa-bin --version 2>&1 | sed 's/.*build \([0-9]\+\).*/\1/')
VERSION_STRING=${VERSION_MAJOR}${VERSION_NAME}$(if [ -n "$VERSION_BUILD" ]; then echo "+$VERSION_BUILD$BUILDNUM"; fi)

msg "Making package from installation in $INSTALLDIR, with OPA version $VERSION_STRING."

if [ -n "$TBZ2" ]; then
    msg "Making $TBZ2 (to be decompressed at the installation prefix)"
    msg "(after decompression in <prefix> (eg. /usr/local), the user will"
    msg "need to run <prefix>/share/opa/install/sh --dir <prefix>)"
    tar -C $INSTALLDIR -cj * -f $MYDIR/$TBZ2
fi

###################################
# auto-extract package generation #
###################################

if [ -n "$AUTOINSTALL" ]; then
    AUTOINSTALL=${AUTOINSTALL//\{\}/$VERSION_STRING}
    msg "Making $AUTOINSTALL"
    cat >"$INSTALLDIR/install.sh" <<EOF
#!/usr/bin/env bash

set -e
set -u

if [ -n "\${1:-}" ]; then
echo "Installing in \$1"
INSTALL="\$1"
else
PREFIX=\$HOME/mlstate-opa
if [ "\$(id -u)" -eq 0 ]; then PREFIX=/usr/local; fi
echo "Please specify install prefix. (default \$PREFIX)"
INSTALL=""
while [ -z "\$INSTALL" ]; do
read INSTALL
if [ -z "\$INSTALL" ]; then INSTALL="\$PREFIX"
elif [ "\${INSTALL:0:1}" != "/" ]; then
echo "Please provide an absolute directory"
INSTALL=""
else
mkdir -p "\$INSTALL" || {
echo "Could not create directory \$INSTALL. Please specify another install prefix"
INSTALL=""
}
fi
done
fi

echo "Installing, please wait..."

mkdir -p "\$INSTALL"
GLOBIGNORE=install.sh
cp -a * "\$INSTALL"

\$INSTALL/share/opa/install.sh --quiet --dir "\$INSTALL"

echo
echo "Done !"
echo "Documentation is in \$INSTALL/share/doc/opa"
echo "If you want to uninstall, run \$INSTALL/share/opa/uninstall.sh"
EOF
    chmod a+x "$INSTALLDIR/install.sh"

    cat >"$INSTALLDIR/share/opa/uninstall.sh" <<"EOF"
#!/usr/bin/env bash

set -e
set -u

SCRIPT="$0"
if [ "${SCRIPT:0:1}" != "/" ]; then
  SCRIPT=$PWD/$SCRIPT
fi

# Always run from /tmp
TMPDIR="${TMPDIR:-/tmp}"
if [ $# -eq 0 ] || [ "${SCRIPT:0:${#TMPDIR}}" != "$TMPDIR" ]; then
  INSTALLDIR=${SCRIPT%/share/opa/*}
  X=$(mktemp $TMPDIR/uninstall_opa.XXXXX)
  cp --preserve=mode "$0" "$X"
  exec "$X" "$INSTALLDIR" "$@"
else
  if [ $# -ne 1 ]; then echo "Error: bad number of arguments"; exit 1; fi
  INSTALLDIR="$1"
  trap "rm -f $0" EXIT
fi

echo -n "Going to remove OPA from $INSTALLDIR. Proceed ? "
read yesno
if [ "${yesno:0:1}" != "y" ]; then exit 0; fi

"$INSTALLDIR"/share/opa/install.sh --dir "$INSTALLDIR" --uninstall

P=$PWD; cd "$INSTALLDIR"
rm -f \
EOF
  ( cd $INSTALLDIR; find . ! -type d | sed 's/^\(.*\)$/ "\1" \\/' ) >>$INSTALLDIR/share/opa/uninstall.sh
  echo >>"$INSTALLDIR/share/opa/uninstall.sh"
  cat >>"$INSTALLDIR/share/opa/uninstall.sh" <<"EOF"
cd $P

for DIR in "$INSTALLDIR/share/opa" "$INSTALLDIR/share/doc/opa" "$INSTALLDIR/lib/opa"; do
  R=0
  find $DIR \( -type d -empty \) -delete || R=$?
  if [ $R -ne 0 ] || [ -d $DIR ]; then
    echo "Warning: some files left in $DIR"
  fi
done

set +e
rmdir "$INSTALLDIR/share/doc" 2>/dev/null
rmdir "$INSTALLDIR/share" 2>/dev/null
rmdir "$INSTALLDIR/lib" 2>/dev/null
rmdir "$INSTALLDIR/bin" 2>/dev/null
rmdir "$INSTALLDIR" 2>/dev/null

echo "Done."
EOF
    chmod a+x "$INSTALLDIR/share/opa/uninstall.sh"

    makeself --bzip2 $INSTALLDIR "$MYDIR/$AUTOINSTALL" "$AUTOINSTALL" ./install.sh
    msg "Generated $AUTOINSTALL"
fi

#############################
# MacOSX package generation #
#############################
if [ "$PKG" = "true" ]; then
    OS_VARIANT=`sw_vers -productVersion`
    PKG_NAME="OPA $VERSION_MAJOR $VERSION_NAME Build $BUILDNUM for MacOS $OS_VARIANT"
    echo "Making package '$MYDIR/$PKG_NAME.pkg'"
   /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"
   echo "Creating image '$MYDIR/$PKG_NAME.dmg'"
   hdiutil create "$MYDIR/$PKG_NAME.dmg" -srcfolder "$MYDIR/$PKG_NAME.pkg"
fi


################################
# MsWindows package generation #
################################
if [ "$WINPKG" = "true" ]; then
   PKG_NAME="OPA $VERSION_MAJOR $VERSION_NAME Build $BUILDNUM"
   rm -rf pkg_ms_windows
   mkdir -p pkg_ms_windows
   # Copy
   # -everyting
   cp -a $INSTALLDIR/* pkg_ms_windows/
   # -nsis script
   cp $OPAGENERAL/ms_windows/opa_pkg/install.nsi pkg_ms_windows
   # -opa.bat install
   cat $OPAGENERAL/ms_windows/opa_pkg/opa.bat | grep -v "^REM" | grep -v "^$" > pkg_ms_windows/bin/opa.bat
   # Some tidying
   mkdir -p pkg_ms_windows/bin/ocaml
   mkdir -p pkg_ms_windows/bin/uninstall
   mv pkg_ms_windows/share/opa/examples pkg_ms_windows/examples
   mv pkg_ms_windows/bin/opa-bin pkg_ms_windows/bin/runopa.exe
   # hidding ocaml executable to be oustide of PATH
   mv pkg_ms_windows/bin/ocamlopt.opt.exe pkg_ms_windows/bin/ocaml/ocamlopt.opt.exe
   cp $OPAGENERAL/ms_windows/opa_pkg/opa_logo*.ico pkg_ms_windows/bin/uninstall
   /cygdrive/c/Program\ Files/NSIS/makensis.exe pkg_ms_windows/install.nsi
   echo The package is in pkg_ms_windows/installer.exe
fi




#############################
# Debian package generation #
#############################

if [ "$DEB" = "true" ]; then
    MAINTAINER="Louis Gesbert <louis.gesbert@mlstate.com>"
    PREFIX=/usr
    WORKDIR=$(mktemp -d /tmp/mkdeb.XXXXX)
    cd $WORKDIR
    DEBROOT=$WORKDIR/debian
    mkdir -p $DEBROOT$PREFIX
    mkdir -p $DEBROOT/DEBIAN
    mkdir _build
    cp -a $INSTALLDIR/* $DEBROOT$PREFIX
    find debian -type d | xargs chmod 755

    cat > debian/DEBIAN/control <<EOF
Package: opa
Version: $VERSION_STRING
Section: devel
Priority: optional
Architecture: $(dpkg --print-architecture)
Installed-Size: $(du -s $INSTALLDIR | cut -f1)
Pre-Depends: debconf
Depends: libc6 (>= 2.3.2), libgdbm3, libssl0.9.8, libssl-dev, zlib1g, zlib1g-dev, libjpeg62, libpng12-0, libgif4
Maintainer: $MAINTAINER
Description: The unified language for web 2.0 development
OPA is a unified programming language for web development. This self-contained
package contains the OPA compiler, that compiles stand-alone web servers
including AJAX features, database, etc. from single source files.
EOF

    # The wrapper scripts are always bound to $PREFIX, pre-generate them...
    $DEBROOT$PREFIX/share/opa/install.sh --quiet --dir "$DEBROOT$PREFIX" --prefix "$PREFIX"
    rm $DEBROOT$PREFIX/share/opa/install.sh

    mkdir -p $DEBROOT$PREFIX/share/lintian/overrides
    cat > $DEBROOT$PREFIX/share/lintian/overrides/opa <<EOF
# The package itself is in AGPL, but includes other software and lists their licenses
# in the copyright file
opa binary: copyright-should-refer-to-common-license-file-for-lgpl
EOF

    dpkg-deb --build debian _build
    PACKAGE=$(ls _build/*.deb)
    mv $PACKAGE $MYDIR
    msg "Generated $(basename "$PACKAGE")"
    cd $MYDIR
    rm -rf /tmp/${WORKDIR#/tmp/}
fi

msg 'Done !'
Something went wrong with that request. Please try again.