#!/usr/bin/env etsh
:
: etsh - " Force sh(1), csh(1), and other shells to exit w/ error! " <'' ;;;
:
: "  @(#)$Id: etshdir,v 1.3 2018/12/15 22:28:21 jneitzel Exp $  "
:
: "  The author of this file, J.A. Neitzel <jan (at) etsh (dot) nl>,  "
: "  hereby grants it to the public domain.                           "
:

:
: "  Make or check/remake ETSHDIR ($d) in the environment.  "
:
: "  usage: source [/path/to/]etshdir $$ (to make)  "
: "     or:                                         "
: "  usage: etshdir (to check)                      "
:

: " Script initialization                                 "
set D /tmp/etsh-$u-$$ ; : " default ETSHDIR ($d) pathname "
set N etshdir         ; : " script name                   "

: " Check for correct usage. "
: >>$0'' <'' ; : >>$1'' <'' ; : >>$$'' <''
if $# = 1 -a X$1 = X$$ goto Make
if $# = 0 -a X$d = X \
	if { exit }  \
	fd2 -e echo "$N: ETSHDIR not set - do source [/path/to/]$N \$\$" ; false
if $# = 0 goto Check

	fd2 -e echo "usage: source [/path/to/]$N"' $$ (to make)'
	fd2 -e echo '   or:'
	fd2 -e echo "usage: $N "'(to check)' ; unset N ; unset D ; false ; exit

: Make
if X$d != X goto Check

	unset N
	if ! { mkdir -m 0700 $D } if { exit } false
	setenv ETSHDIR $D
	unset D
	: fallthrough

: Check - " And remake the directory if it does not exist. "

	unset N ; unset D
	if ! -e $d -a ! -h $d if ! { mkdir -m 0700 $d } if { exit } false
	if ! -d $d -o   -h $d if   { exit } \
			      fd2 -e echo "etshdir: $d: Not a directory" ; false
	: zero status
