#!/bin/sh

#SCRIPT=$(readlink -f $0)
#SCRIPT_PATH=$(dirname "$BASH_SOURCE")

cat "./ascii-art.txt"
read START_DUMMY
cat "./install-notice.txt"

while :
do

  echo "  Please select an offering to install:"
  echo "  1) CKB (Community Knowledge Box) - Ideal for servers, hubs, consortia"
  echo "  2) anansi - Local mode for personal archiving and storytelling"
  echo "  3) Read more about the various options"
  
  read IN
  case $IN in 
  	1 | ckb | CKB )
  	  DEV_MODE=false 
  	  break ;;
  
  	2 | anansi )
  	  DEV_MODE=true
  	  break ;;
  
  	3 | *)
  	  cat ./offerings.md ;;
  esac

done

#echo "The base name of the program: `basename $0`"
#echo "This script was called with $# parameters"
#echo "All passed parameters: $@"

DEFAULT_APP_SECRET=`openssl rand -base64 32`
#LOCAL_MODE=false
DEFAULT_BULK_UPLOAD_KEY=`openssl rand -base64 15`

if [ "$?" -ne "0" ]; then
	echo "[ERROR] Not able to generate application secret with openssl!"
fi

echo "  >> Press [RETURN] key to accept system generated defaults"
echo "     or enter your own values:"
echo ""

#echo "1. Do you want to run in LOCAL_MODE? [Default: ${LOCAL_MODE}]"
#read DEV_MODE
#echo "      Niosx would run in local mode? ${DEV_MODE:=$LOCAL_MODE}"
#echo ""

echo "1.  Default APPLICATION_SECRET: [${DEFAULT_APP_SECRET}] ?"
read APPLICATION_SECRET
echo "      Application secret is: ${APPLICATION_SECRET:=$DEFAULT_APP_SECRET}"

echo "2.  Default BULK_UPLOAD_KEY: [${DEFAULT_BULK_UPLOAD_KEY}] ?"
read BULK_UPLOAD_KEY
echo "      Password for bulk_upload_user is: ${BULK_UPLOAD_KEY:=$DEFAULT_BULK_UPLOAD_KEY}"
echo "      >> The username:password for bulk uploading data as admin is:"
echo "            [[[  bulk_upload_user:${BULK_UPLOAD_KEY}   ]]]"
echo ""
echo "######## IMPORTANT!!! NOTE DOWN THE ABOVE USERNAME AND PASSWORD ########"
echo ""
echo ""

#cat "$SCRIPT_PATH/ascii-art.txt"
#cat "$SCRIPT_PATH/launching-service.txt"
#CONF_PATH="$SCRIPT_PATH"

cat > "../conf/customizer.env" << EOF
# This docker-compose customizer environemnt variables file is auto generated by scripts/niosx.sh, edit it by hand only if you must!

DEV_MODE=$DEV_MODE
APPLICATION_SECRET=$APPLICATION_SECRET
BULK_UPLOAD_KEY=$BULK_UPLOAD_KEY

EOF

exec docker-compose -f ../conf/docker-compose-test.yaml --env-file=../conf/customizer.env  up 


