#!/bin/sh set -euC help_text= help_text="$help_text build\t[]\t\n" dev_config () { ./configure -e extractrs } help_text="$help_text unconfigure\t[]\tresets the build\n" unconfigure () { rm build.ninja lib/JWebmail/Config.pm MANIFEST.BIN rm -r JWebmail-srcdist/ JWebmail-bindist/ } help_text="$help_text build\t[]\t\n" build () { env PATH="node_modules/.bin/:$PATH" ninja "$@" } help_text="$help_text install\t[]\t\n" install () { perl Makefile.PL make if readlink /bin/init | grep -q 'systemd' then install -m 644 jwebmail.service /etc/systemd/system fi install -m 644 jwebmail.toml /etc } help_text="$help_text start_dev\t[]\tstarts a hot reloading dev server\n" start_dev () { morbo script/jwebmail } help_text="$help_text logrotate_dev\t[mode=development]\tarchives the current log file\n" logrotate_dev () { mode=${1:-development} mv -i "log/$mode.log" "log/${mode}_$(date --iso-8601=minutes).log" } help_text="$help_text follow_log\t[mode=development]\tfollows the current log file\n" follow_log () { mode=${1:-development} tail -f "log/$mode.log" } help_text="$help_text release_check\t[]\t\n" release_check () { files='README.md CHANGES.md LICENSE' for file in $files do fold -s -w 85 "$file" | diff "$file" - done perl -nE 'chomp; say if $_ && !-e' MANIFEST } help_text="$help_text list_deps\t[module=JWebmail]\tlists all non core dependencies of a module\n" list_deps () { module=${1:-JWebmail} core="$(corelist -v v5.34.1 | awk '{ print $1 }')" deps="$(perl -wE "use lib 'lib'; use Module::Load::Conditional 'requires'; @res = requires '$module'; \$\" = qq(\n); say \$res[0] ? qq(@res) : ''")" for dep in $deps do if ! echo "$core" | grep -qxF "$dep" then echo "$dep" fi done } help_text="$help_text list_translations\t[raw='']\tlists translatable snipptes on a best effort base (incomplete!!)\n" list_translations () { raw=${1-} if [ "$raw" ] then find lib -name '*.pm' -exec grep '\->l(' '{}' '+' find templates -name '*.html.ep' -exec grep "l[ (][\"']" '{}' '+' else p1="$(find lib -name '*.pm' -exec grep '\->l(' '{}' '+' | sed 's/^\(\S*\):.*->l(\([^)]*\)).*$/\1: \2/')" p2="$(find templates -name '*.html.ep' -exec grep "l[ (][\"']" '{}' '+' | sed "s/^\\(\\S*\\):.*l[ (][\"']\\([^\"']*\\)[\"'].*$/\\1: '\\2'/")" echo "$(echo "$p1"; echo "$p2")" | sort | uniq fi } help () { echo "The following actions are available:" echo printf "$help_text\n" | expand -t 21,41 } cmd=${1-help} [ $# -gt 0 ] && shift if LANG=C type "$cmd" 2>/dev/null | grep -q 'function$' then $cmd "$@" else echo "unkown commad '$cmd'" >&2; exit 1 fi