File: rebar-pre-script

package info (click to toggle)
yaws 2.2.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,008 kB
  • sloc: erlang: 42,469; sh: 2,553; javascript: 1,459; makefile: 994; ansic: 890; lisp: 79; python: 34; xml: 12; php: 1
file content (142 lines) | stat: -rwxr-xr-x 4,865 bytes parent folder | download
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
#!/bin/sh

SCRIPT=`basename $0`
SCRIPTDIR=`dirname $0`
YAWS_DIR=`cd ${SCRIPTDIR}/.. && pwd`

. ${YAWS_DIR}/vsn.mk
YAWS_VSN=${VSN-$YAWS_VSN}

YAWS_ETCDIR=${ETCDIR-$YAWS_DIR/etc}
YAWS_BINDIR=${EXECDIR-$YAWS_DIR/bin} # BINDIR is already set by rebar
YAWS_VARDIR=${VARDIR-$YAWS_DIR/var}
YAWS_LOGDIR=${LOGDIR-$YAWS_DIR/yaws_logs}

ERL_BIN=`which erl`
ERL_BIN_DIR=${ERL_BIN%/erl}
YAWS_ERLBINDIR=${ERLBINDIR-$ERL_BIN_DIR}
ERL_BIN=$YAWS_ERLBINDIR/erl
WERL_BIN=$YAWS_ERLBINDIR/werl

# Use a function for error exit instead of set -e so we can conditionally
# remove files before exiting. If this were bash we could trap ERR but
# Bourne shell doesn't support that portably.
fail() {
    [ -n "$@" ] && rm -f "$@"
    exit 1
}

keep_or_replace() {
    if [ -f "$1" ] && cmp -s "$1" "$2"; then
        rm -f "$2"
        return 0
    else
        mv "$2" "$1" || fail "$2"
        return 1
    fi
}

## handle clean command and exit
if [ "$1" = clean ]; then
    rm -f ${YAWS_DIR}/src/mime_types.erl  \
       ${YAWS_DIR}/src/yaws_generated.erl \
       ${YAWS_DIR}/src/yaws_charset.hrl \
       ${YAWS_DIR}/test/testsuite.hrl \
       ${YAWS_DIR}/scripts/gen-yaws-generated
    exit 0
fi

## Create required directory
[ -d "$YAWS_ETCDIR" ]             || mkdir "$YAWS_ETCDIR"             || fail
[ -d "$YAWS_ETCDIR/yaws" ]        || mkdir "$YAWS_ETCDIR/yaws"        || fail
[ -d "$YAWS_BINDIR" ]             || mkdir "$YAWS_BINDIR"             || fail
[ -d "$YAWS_VARDIR" ]             || mkdir "$YAWS_VARDIR"             || fail
[ -d "$YAWS_LOGDIR" ]             || mkdir "$YAWS_LOGDIR"             || fail
[ -d "${YAWS_VARDIR}/yaws" ]      || mkdir "${YAWS_VARDIR}/yaws"      || fail
[ -d "${YAWS_VARDIR}/yaws/ebin" ] || mkdir "${YAWS_VARDIR}/yaws/ebin" || fail

## For deterministic builds, which avoids embedding differing
## pathnames in the yaws_generated beam file, set
## YAWS_DETERMINISTIC_BUILD as an environment variable (any value will
## do, the value is not used).
if [ -n "$YAWS_DETERMINISTIC_BUILD" ]; then
    flags=+deterministic
    preproc=-DDETERMINISTIC
else
    flags=+debug_info
    preproc=
fi

## generate gen-yaws-generated script
cd ${YAWS_DIR}/scripts || fail
tmpgen=`mktemp /tmp/${SCRIPT}.XXXXXX` || fail
sed -e 's/@YAWS_DETERMINISTIC_BUILD@/'"${YAWS_DETERMINISTIC_BUILD}"'/g' \
    gen-yaws-generated.in > $tmpgen || fail
mv -f $tmpgen gen-yaws-generated || fail
chmod a+x gen-yaws-generated || fail

## generate yaws_generated.erl module
cd ${YAWS_DIR}/src || fail
tmpgen=`mktemp /tmp/${SCRIPT}.XXXXXX` || fail
YAWS_VSN="${YAWS_VSN}" VARDIR="${YAWS_VARDIR}" ETCDIR="${YAWS_ETCDIR}"  \
    ${YAWS_DIR}/scripts/gen-yaws-generated >$tmpgen || fail
keep_or_replace ${YAWS_DIR}/src/yaws_generated.erl $tmpgen

## generate mime_types.erl module
cd ${YAWS_DIR}/src || fail
need_mime=yes
if [ -f mime_types.erl ]; then
    need_mime=`find mime_type_c.erl -newer mime_types.erl -print`
fi
rm_ebin=
if [ ! -d "${YAWS_DIR}/ebin" ]; then
    mkdir "${YAWS_DIR}/ebin"
    rm_ebin=yes
fi
if [ -n "$need_mime" ]; then
    set yaws yaws_generated mime_type_c
    for f; do
        erlc $flags $preproc -o ${YAWS_DIR}/ebin ${f}.erl || fail
    done
    erl -pa ${YAWS_DIR}/ebin -noshell -s mime_type_c generate || fail mime_types.erl
    for f; do
        rm ${YAWS_DIR}/ebin/${f}.beam
    done
    [ -n "$rm_ebin" ] && rm -rf ${YAWS_DIR}/ebin
fi

## generate yaws scripts
cd ${YAWS_DIR}/scripts
tmpgen=`mktemp /tmp/${SCRIPT}.XXXXXX` || fail
YAWSDIR="${YAWS_DIR}" VARDIR="${YAWS_VARDIR}" ERLBINDIR="${YAWS_ERLBINDIR}"   \
    ERL="${ERL_BIN}" WERL="${WERL_BIN}"                                       \
    ${YAWS_DIR}/scripts/gen-yaws > $tmpgen || fail
chmod +x $tmpgen
echo "--- Installed yaws script at ${YAWS_BINDIR}"
keep_or_replace ${YAWS_BINDIR}/yaws $tmpgen

## generate default yaws configuration
cd ${YAWS_DIR}/scripts
tmpgen=`mktemp /tmp/${SCRIPT}.XXXXXX` || fail
YAWSDIR="${YAWS_DIR}" LOGDIR="${YAWS_LOGDIR}" VARDIR="${YAWS_VARDIR}"          \
    PORT=8000 DOCROOT="${YAWS_DIR}/www" CERTDIR="${YAWS_DIR}/ssl" SSLPORT=4443 \
    ${YAWS_DIR}/scripts/gen-yaws-conf > $tmpgen
if [ -f "${YAWS_ETCDIR}/yaws/yaws.conf" ]; then
    echo "--- Will not overwrite ${YAWS_ETCDIR}/yaws/yaws.conf"
    keep_or_replace ${YAWS_ETCDIR}/yaws/yaws.conf.template $tmpgen
else
    echo "--- Installing local config file at ${YAWS_ETCDIR}/yaws"
    keep_or_replace ${YAWS_ETCDIR}/yaws/yaws.conf $tmpgen
fi

## generate test suite files
cd ${YAWS_DIR}/test
srcdir=`echo "${YAWS_DIR}" | sed -e 's/\//\\\\\//g'`
[ -n "${REBAR_BUILD_DIR}" ] && builddir="${REBAR_BUILD_DIR}" || builddir="${YAWS_DIR}"
builddir=`echo "${builddir}" | sed -e 's/\//\\\\\//g'`
tmpgen=`mktemp /tmp/${SCRIPT}.XXXXXX` || fail
sed -e 's/@abs_top_srcdir@/'"${srcdir}"'/g' \
    -e 's/@abs_top_builddir@/'"${builddir}"'/g' testsuite.hrl.in > $tmpgen || fail
mv -f $tmpgen testsuite.hrl || fail

exit 0