Skip to content
This repository
tag: v285
Fetching contributors…

Cannot retrieve contributors at this time

executable file 134 lines (125 sloc) 4.208 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
#!/bin/sh -eu

help() {
    echo "OPA installation script: creates wrapper scripts to call OPA and tools"
    echo "with an environment setting their correct working directories; sets up"
    echo "the www-data user with a ~/mlstate directory"
    echo "Options:"
    echo " --dir <dir> the OPA installation prefix to work in"
    echo " (by default, the current directory)"
    echo " --help show this help"
    echo " --link <dir> also install links to the scripts in the given directory"
    echo " --no-ocaml don't force the use of a specific ocaml"
    echo " --ocaml-prefix what ocaml prefix to use (default <prefix>/lib/opa/ocaml)"
    echo " --ocamllib ocaml libraries directory (default <ocaml-prefix>/lib/ocaml)"
    echo " --ocamlopt ocaml native compiler to use (default <ocaml-prefix>/bin/ocamlopt.opt)"
    echo " --prefix <dir> make wrappers for the given installation prefix"
    echo " (by default, the value of --dir)"
    echo " --quiet be quiet"
    echo " --uninstall remove installed scripts instead"
}

BUILDDIR=_build
INSTALLDIR=$PWD
LINKDIR=""
UNINSTALL=false
NO_OCAML=false
QUIET=false
QMLFLAT=false

while [ $# -gt 0 ]; do
    case $1 in
        --qmlflat)
            QMLFLAT=true
            ;;
        --build-dir)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
BUILDDIR=$1
            ;;
        --dir)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
INSTALLDIR=$1
            ;;
        --prefix)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
PREFIX=$1
            ;;
        --ocaml-prefix)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
OCAML_PREFIX=$1
            ;;
        --ocamllib)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
OCAMLLIB=$1
            ;;
        --ocamlopt)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
OCAMLOPT=$1
            ;;
        --link)
            if [ $# -lt 2 ]; then echo "Error: option $1 requires an argument"; exit 1; fi
            shift
LINKDIR=$1
            ;;
        --quiet)
            QUIET=true
            ;;
        --uninstall)
            UNINSTALL=true
            ;;
        --no-ocaml)
            NO_OCAML=true
            ;;
        --help)
            help
exit 0
            ;;
        *)
            echo "Error: unknown option $1"
            help
exit 1
    esac
    shift
done

: ${PREFIX:=$INSTALLDIR}
: ${OCAML_PREFIX:=$PREFIX/lib/opa/ocaml}

# create_wrapper basefile exename
create_wrapper() {
    local source="$1"; shift
local name="$1"; shift
    [ $# -eq 0 ]
    local wrapper=$INSTALLDIR/bin/$name

    if [ $UNINSTALL = true ]; then
        [ $QUIET = true ] || echo "Removing $wrapper"
        rm -f $wrapper
        if [ -n "$LINKDIR" ]; then
            rm -f $LINKDIR/$name
        fi
    else
        [ $QUIET = true ] || echo "Creating $wrapper"
        mkdir -p $(dirname $wrapper)
        {
            echo '#!/bin/sh'
            echo "export MLSTATELIBS=$PREFIX"
            if [ $NO_OCAML = false ]; then
                echo "export OCAMLLIB=${OCAMLLIB:-$OCAML_PREFIX/lib/ocaml}"
                echo "export OCAMLOPT=${OCAMLOPT:-$OCAML_PREFIX/bin/ocamlopt.opt}"
                # may need to rewrite $PREFIX/lib/opa/ocaml/lib/ld.conf if ocaml is relocated
            fi
            echo 'exec '$source' "$@"'
        } > $wrapper
        chmod 755 $wrapper
        if [ -n "$LINKDIR" ]; then
            ln -fs $wrapper $LINKDIR/
        fi
    fi
}

# creating wrapper script 'opa'
create_wrapper $PREFIX/lib/opa/bin/opa-bin opa

# creating wrapper script 'opa-plugin-builder'
create_wrapper $PREFIX/lib/opa/bin/opa-plugin-builder-bin opa-plugin-builder

# creating wrapper script 'opa-plugin-browser'
create_wrapper $PREFIX/lib/opa/bin/opa-plugin-browser-bin opa-plugin-browser
Something went wrong with that request. Please try again.