#!/bin/sh -x
echo $0

# if [ ! -d /zTools/zPrivateConfig ] && [ -d /static ]
# then
# 	BASE=/static
# fi

# if [ -d /zTools/zPrivateConfig ] && [ ! -d /static ] 
# then
# 	BASE=/zTools/zPrivateConfig
# fi

# if [ -d /zTools/zShared ]
# then
# 	BASE=/zTools/zShared
# fi

if [  -d /static ] && [ ! -d /zTools ]
then
	BASE=/static
fi

if [ ! -d /static ] && [ -d /zTools/zPrivateConfig ]
then
	BASE=/zTools/zPrivateConfig
fi

if [ -d /zTools/zShared ]
then
	BASE=/zTools/zShared
fi

if [  -d /static ] && [ ! -d /zTools/zShared ] && [ ! -d /zTools/zPrivateConfig ]
then
	BASE=/static
else
	BASE=/zTools/zPrivateConfig
fi

# if [ ! -d /static ] && [ -d /zTools/zShared ] && [ ! -d /zTools/zPrivateConfig ]
# then
# 	BASE=/zTools/zShared
# fi

# if [ ! -d /static ] && [ ! -d /zTools/zShared ] && [ -d /zTools/zPrivateConfig ]
# then
# 	BASE=/zTools/zPrivateConfig
# fi


MYNAME=$(uname -n)
# if [ -d /volume12/zTools/Sync${MYNAME}/zTools/zSyno ]
# then
# 	BASE=/volume12/zTools/Sync${MYNAME}/zTools/zSyno
# fi

if [  -d /zz/zPrivate/secrets ]
then
	SECRETS=/zz/zPrivate
fi

if [  -d /zz/zDocky/secrets ]
then
	SECRETS=/zz/zDocky
fi

if [  -d /zz/zSyno/secrets ]
then
	SECRETS=/zz/zSyno
fi

# echo "BASE=${BASE}"
# if [ -f ${BASE}/secrets/.${MYNAME} ]
# then
#   . ${BASE}/secrets/.${MYNAME}
# else
# if [ -f ${BASE}/secrets/.ntfyenv ]
# then
#   . ${BASE}/secrets/.ntfyenv
# else
#   if [ -z ${DUFUS+x} ]
#   then
#     mkdir -p ${BASE}/secrets
#       echo "Creat ${BASE}/secrets/.ntfyenv"
#     echo "Please update contents and rerun"
#     exit 1
#     fi
#   fi
# fi


echo "SECRETS=${SECRETS}"
if [ -f ${SECRETS}/secrets/.${MYNAME}.${LOGNAME}.private ]
then
  . ${SECRETS}/secrets/.${MYNAME}.${LOGNAME}.private
else
# if [ -f ${SECRETS}/secrets/.ntfyenv ]
# then
#   . ${SECRETS}/secrets/.ntfyenv
# else
  if [ -z ${DUFUS+x} ]
  then
    mkdir -p ${SECRETS}/secrets
      echo "Create ${SECRETS}/secrets/.${MYNAME}.${LOGNAME}.private"
    echo "Please update contents and rerun"
    exit 1
    fi
  # fi
fi

SCRIPT=$1
MSG=$2
MYNAME=`uname -n`

SUBJECT=" ${MYNAME} - ${SCRIPT}: "



curl \
  -d "${SUBJECT} ${MSG}" \
  ntfy.sh/${DUFUSH}
