summaryrefslogtreecommitdiff
path: root/configure
blob: 428f89a9e2b26134169f3f620384a49723e87133 (plain)
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
#!/bin/sh

set -euC

check_command () {
    echo -n "Checking for command $1 ... "
    if command -v "$1" >/dev/null
    then echo 'found!'
    else echo 'not available!'; exit 1
    fi
}

check_perl_deps () {
    for d in "$@"
    do
        echo -n "Checking for perl module $d ... "
        if perl -Ilib -e "use $d;"
        then echo 'found!'
        else echo 'not available!'; exit 1
        fi
    done
}

check_node_module () {
    echo -n "Checking for node module $1 ... "
    if [ -d "node_modules/$1" ]
    then echo 'found!'
    else echo 'not available!'; exit 1
    fi
}

check_ninja_version () {
    ninja_file="$(mktemp -t jwm-build-XXXXXXXX)"
    echo "ninja_required_version = $1" >>"$ninja_file"
    echo -n "Checking ninja version at least $1 ... "
    if ninja -f "$ninja_file" >/dev/null
    then echo 'sufficient!'
    else echo 'inadequate!'; exit 1
    fi
    rm "$ninja_file"
}

JWM_INIT=
if readlink /sbin/init | grep -q systemd
then JWM_INIT=systemd
fi

eval PERL_LIB_PATH="$(perl -V::installsitelib)"
eval PERL_BIN_PATH="$(perl -V::installsitebin)"

allargs="$*"
while getopts 'c:d:e:i:hm:p:P:' opt
do case $opt in
    (e) JWM_MAILDIR_EXTRACTOR="$OPTARG";;
    (m) JWM_MODE="$OPTARG";;
    (c) JWM_LOGIN_SCHEME="$OPTARG";;
    (d) DESTDIR="$OPTARG";;
    (p) PREFIX="$OPTARG";;
    (P) PERL_LIB_PATH="$OPTARG";;
    (i) JWM_INIT="$OPTARG";;
    (h)
        t="$(printf '\t')"
        expand -t 38,68 <<END
usage: $0 configure [options...]

  OPTIONS
    FLAG ARGUMENT         DEFAULT     VALUES                           DESCRIPTION
    -e MAILDIR_EXTRACTOR  extractpy   {extractpy,extractpl,extractrs}
    -m MODE               development {development,production}
    -c LOGIN_SCHEME       plain       {plain,cram_md5}                 The login scheme (don't use plain unless over TLS)
    -d DESTDIR            /                                            Install root
    -p PREFIX             usr/local   {usr,usr/local}                  Install prefix
    -P PATH               $PERL_LIB_PATH$t$t  Perl install path
    -i INIT               $JWM_INIT $t{,systemd}                       Init system to install service files for
END
        exit
        ;;
    (*) exit 2;;
esac
done
shift $((OPTIND-1))
[ $# -gt 0 ] && { echo 'unknown arguments' >&2; exit 2; }

: "${JWM_MAILDIR_EXTRACTOR=extractpy}" && echo "$JWM_MAILDIR_EXTRACTOR" | grep -Eq '^extract(pl|py|rs)$'
: "${JWM_MODE=development}" && [ "$JWM_MODE" = development -o "$JWM_MODE" = production ]
: "${JWM_LOGIN_SCHEME=plain}" && [ "$JWM_LOGIN_SCHEME" = plain -o "$JWM_LOGIN_SCHEME" = cram_md5 ]
: "${DESTDIR=/}" && [ -d "$DESTDIR" ]
: "${PREFIX=usr/local}"

PATH="$(pwd)/node_modules/.bin${PATH:+:$PATH}"

check_command perl
check_perl_deps v5.24
check_command prove
check_command pod2man
check_command morbo
check_command hypnotoad
check_command npm
check_command esbuild
check_command sass
check_command ninja
check_ninja_version 1.11

check_perl_deps 'Mojolicious 9.31' Email::MIME Role::Tiny Class::Method::Modifiers TOML::Tiny namespace::clean Test2::Bundle::More MIME::Words

check_node_module bulma

if [ "$JWM_LOGIN_SCHEME" = cram_md5 ]
then
    check_node_module crypto-js
    check_perl_deps Digest::HMAC_MD5
fi

case "$JWM_MAILDIR_EXTRACTOR" in
    (extractpl)
        [ -x "$(pwd)/script/extract.pl" ]
        check_perl_deps Mail::Box::Maildir
        MAILDIR_EXTRACTOR_BIN=script/extract.pl
        ;;
    (extractpy)
        [ -x "$(pwd)/script/extract.py" ]
        check_command python3
        MAILDIR_EXTRACTOR_BIN=script/extract.py
        ;;
    (extractrs)
        [ -f "$(pwd)/extract/Cargo.toml" ] || { echo 'extractrs not available' >&2; exit; }
        JWM_EXTRACTRS_DIR=extract
        check_command cargo
        MAILDIR_EXTRACTOR_BIN=bin/jwebmail-extract
        ;;
esac

export LOGIN_SCHEME="$JWM_LOGIN_SCHEME"
export CONFARGS="$allargs"
export MAILDIR_EXTRACTOR_NAME="$JWM_MAILDIR_EXTRACTOR"
export MAILDIR_EXTRACTOR_BIN
export JWM_EXTRACTRS_DIR
export JWM_MODE
export JWM_INIT
export DESTDIR
export PREFIX
export PERL_LIB_PATH
export PERL_BIN_PATH
export DATADIR="share/jwebmail"
if [ "$PREFIX" = usr ]
then export CONFDIR="../etc"
else export CONFDIR="etc"
fi

perl -pe 's/@(\w+)@/$ENV{$1}/ga' lib/JWebmail/Config.pm.in >|lib/JWebmail/Config.pm
perl -pe 's/@(\w+)@/$ENV{$1}/ga' install/jwebmail.service.in >|install/jwebmail.service
sh confninja.sh >|build.ninja