function help() { echo "" echo "bizdev" | figlet | lolcat echo "" echo " bild compile code" echo " ci run all builds and tests" echo " deps manage dependencies with niv" echo " ghci start ghci with correct options" echo " help show this message" echo " lint auto-lint all changed files" echo " pie product improvement engine" echo " push send a namespace to the cloud" echo " ship lint, bild, and push one (or all) namespace(s)" } # color codes for use with printf RED='\033[0;31m' GRN='\033[0;32m' YEL='\033[0;33m' NC='\033[0m' # No Color alias runghc="runghc --ghc-arg=-i$BIZ_ROOT" alias tree="tree -I _" # link git hooks rm -f $BIZ_ROOT/.git/hooks/{post-checkout,post-merge,pre-commit} ln -s $BIZ_ROOT/Biz/Ide/post-checkout $BIZ_ROOT/.git/hooks/post-checkout ln -s $BIZ_ROOT/Biz/Ide/post-merge $BIZ_ROOT/.git/hooks/post-merge ln -s $BIZ_ROOT/Biz/Lint.py $BIZ_ROOT/.git/hooks/pre-commit function bild() { timeout 5m runghc Biz.Bild $@ } function deps() { niv --sources-file $BIZ_ROOT/Biz/Bild/Sources.json $@ } alias ghci="ghci -i$BIZ_ROOT -ghci-script $BIZ_ROOT/.ghci" function lint { runghc Biz.Lint $@ } function pie() { runghc Biz.Pie $@ } # TODO: convert to haskell, see: # - https://github.com/awakesecurity/nix-deploy/blob/master/src/Main.hs # - http://www.haskellforall.com/2018/08/nixos-in-production.html function push() { prefix=$(echo $PWD | sed -e "s|^$BIZ_ROOT/*||g") if [[ "$prefix" == "" ]] then target="$1" else target="$prefix.$1" fi what=$(realpath "$BIZ_ROOT/_/bild/nix/$target") # hack: get the domain from the activation script. there does not seem # to be a way to get it from nix-instantiate where=$(rg -r '$2' -e '(domainname ")(.*)(")' "$what/activate") nix copy --to ssh://root@$where $what ssh root@$where $what/bin/switch-to-configuration switch ssh root@$where nix-env --profile /nix/var/nix/profiles/system --set $what printf "${GRN}good: push: $target${NC}" } # TODO: convert to haskell function ship() { stuff=(${@}) if [[ ${#stuff[@]} -eq 0 ]] then stuff=( Biz/Cloud.nix Biz/Dev.nix Biz/Que/Prod.nix # Hero/Prod.nix # disabled bc herocomcis.app domain is broken ) fi lint \ && bild --test ${stuff[@]} \ && for thing in ${stuff[@]} do push $thing done } function run-sentry() { urls=( http://que.run https://devalloc.io https://simatime.com https://tv.simatime.com https://bsima.me https://herocomics.app ) for url in ${urls[@]} do code=$(curl -L --max-time 10 --silent --show-error --insecure \ --output /dev/null \ --write-out "%{http_code}" "$url") case "$code" in 2[0-9][0-9]) printf "${GRN}$code $url${NC}\n";; 3[0-9][0-9]) printf "${YEL}$code $url${NC}\n";; 4[0-9][0-9]) printf "${YEL}$code $url${NC}\n";; 5[0-9][0-9]) printf "${RED}$code $url${NC}\n";; *) printf "${RED}$code $url${NC}\n";; esac done } export -f run-sentry alias sentry="watch --color --exec bash -c run-sentry" # Poor man's ci function run-ci() { lint **/* && bild --test **/* } alias ci="time run-ci" export PS1='\n$(r=$? && [ $r -eq 0 ] && printf "biz" || printf "%3.*s" $r $r)> ' help