#!/bin/sh set -euC check_command () { printf 'Checking for command %s ... ' "$1" if command -v "$1" >/dev/null then echo 'found!' else echo 'not available!'; exit 1 fi } check_perl_deps () { for d in "$@" do printf 'Checking for perl module %s ... ' "$d" if perl -Ilib -e "use $d;" then echo 'found!' else echo 'not available!'; exit 1 fi done } check_node_module () { printf 'Checking for node module %s ... ' "$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" printf 'Checking ninja version at least %s ... ' "$1" if ninja -f "$ninja_file" >/dev/null then echo 'sufficient!' else echo 'inadequate!'; exit 1 fi rm "$ninja_file" } detect_languages () { cd lib/JWebmail/I18N for l in * do echo "${l%.pm}" done } allargs="$*" while getopts 'c:e:hm:n:r:u:' opt do case $opt in (e) JWM_MAILDIR_EXTRACTOR="$OPTARG";; (r) JWM_READ_MODEL="$OPTARG";; (m) JWM_MODE="$OPTARG";; (n) JWM_SENDMAIL="$OPTARG";; (u) JWM_USER="$OPTARG";; (c) JWM_LOGIN_SCHEME="$OPTARG";; (h) t="$(printf '\t')" expand -t 70 </dev/null : "${JWM_LOGIN_SCHEME=plain}" && [ "$JWM_LOGIN_SCHEME" = plain -o "$JWM_LOGIN_SCHEME" = cram_md5 ] : "${JWM_SENDMAIL=sendmail}" && [ -x "$(command -v "$JWM_SENDMAIL")" ] PATH="$(pwd)/node_modules/.bin${PATH:+:$PATH}" check_command perl check_perl_deps v5.24 check_command prove 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 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" ] JWM_EXTRACTRS_DIR=extract check_command cargo MAILDIR_EXTRACTOR_BIN=bin/jwebmail-extract ;; esac export SENDMAIL="$JWM_SENDMAIL" 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_READ_MODEL export JWM_MODE sh confninja.sh >|build.ninja perl -pe 's/@(\w+)@/$ENV{$1}/ga' lib/JWebmail/Config.pm.in >|lib/JWebmail/Config.pm