#!/bin/sh
#
# Post Startup script for the Casa Authtoken Service Daemon (casa_atsd)
#
# systemd-casa_atsd-poststart
# Runs as root


      # Check if we need to copy the Signing Certificate to the webapp folder
      if [ ! -f /srv/www/casaats/webapps/CasaAuthTokenSvc/SigningCert ]; then
        # Wait a max of 60 seconds for the webapp folder to be created
          wait_sec=60
          while [ "$wait_sec" != "0" ] ; do
            sleep 1
            if [ -d /srv/www/casaats/webapps/CasaAuthTokenSvc ]; then
              # The folder was created, end the loop
              wait_sec=0
              break
            fi
            wait_sec=$((wait_sec -1))
          done

          # Copy the signing certificate to the webapps folder so that it can be downloaded from the ATS
          cp /etc/CASA/authtoken/keys/localSigningCert /srv/www/casaats/webapps/CasaAuthTokenSvc/SigningCert
      fi

