#!/bin/sh # Enterprise Onion Toolkit cd `dirname $0` || exit 1 export EOTK_HOME=`pwd` # expected by tools # set project directory; this path is hard-replicated elsewhere project_dir=$EOTK_HOME/projects.d # set path export PATH=$EOTK_HOME/opt.d:$EOTK_HOME/lib.d:$PATH # meta prog=`basename $0` version=1.3 Warn() { echo "$@" 1>&2 } AllProjects() { ( cd $project_dir for d in *.d/ ; do echo `basename $d .d` done ) } Action() { action=$1 shift verbose=false if [ "x$1" = "x" ] ; then Warn "missing project name, try: '$prog projects' for a list, or '-a' for all" return elif [ "x$1" = "x-a" ] ; then projects=`AllProjects` verbose=true else projects="$*" fi for project in $projects ; do $verbose && echo :::: $project :::: sh $project_dir/$project.d/$action.sh done } Populate() { if [ -t 0 ] ; then dots=true else dots=false fi cat "$@" | while read line ; do case "$line" in *%NEW_ONION%*) # legacy / shorter / more common onion=secrets.d/`$EOTK_HOME/eotk genkey` echo "$line" | sed -e "s!%NEW_ONION%!$onion!" ;; *%NEW_HARD_ONION%*) onion=secrets.d/`$EOTK_HOME/eotk genkey` echo "$line" | sed -e "s!%NEW_HARD_ONION%!$onion!" ;; *%NEW_SOFT_ONION%*) onion=`$EOTK_HOME/eotk genkey` onion=`basename $onion .key` echo "$line" | sed -e "s!%NEW_SOFT_ONION%!$onion!" ;; *) echo "$line" ;; esac if $dots ; then echo ".\c" >/dev/tty fi done if $dots ; then echo "" >/dev/tty fi } Configure() { log=configure$$.log for file in "$@" ; do echo :::: $file :::: case "$file" in *.tconf) file2=`basename $file .tconf`.conf if [ -s $file2 ] ; then echo $prog: $file: using existing $file2 else echo $prog: $file: populating $file2 with onions, please be very patient... Populate $file >$file2 fi file="$file2" ;; *) ;; esac echo $prog: $file: processing if ! $EOTK_HOME/lib.d/do-configure.pl "$file" ; then echo $prog: failure processing $file: see $log exit 1 fi done 2>$log echo "$prog: done; log is in $log" } cmd="$1" shift case "$cmd" in version) echo $prog: $version $EOTK_HOME if [ -f .gitignore ] ; then git show -s --oneline fi ;; projects|proj) AllProjects ;; populate|pop) Populate "$@" ;; configure|config|conf) Configure "$@" ;; start) # project, or "-a" Action start "$@" ;; stop) # project, or "-a" Action stop "$@" ;; bounce|restart|reload) # project, or "-a" Action bounce "$@" ;; nxreload) # project, or "-a" Action nxreload "$@" ;; debugon) # project, or "-a" Action debugon "$@" ;; debugoff) # project, or "-a" Action debugoff "$@" ;; harvest|onions) # project, or "-a" Action harvest "$@" ;; status) # project, or "-a" Action status "$@" ;; maps|map) # project, or "-a" Action maps "$@" ;; ps) ps auxww | grep /eotk/ ;; genkey|gen) secrets=secrets.d test -d $secrets || mkdir $secrets || exit 1 ( cd $secrets ; generate-onion-key.sh ) ;; delete) # project, or "-a" echo $prog: delete is tbd ;; *) echo "usage: $prog args ... # see README.md for docs" 1>&2 exit 1 ;; esac exit 0