#!/bin/bash

[ -r "env-oci-reg" ] && . ./env-oci-reg

[ -f "bin/apply.sh" ] && chmod +x bin/apply.sh
[ -f "make_istio-system_secret.sh" ] && chmod +x make_istio-system_secret.sh

if [ -f "install-reg.sh" ] ; then 
   chmod +x install-reg.sh
   ./install-reg.sh
fi

if [ -n "$SERVICES_SAVE_PATH" ] ; then
   sudo mkdir -p "$SERVICES_SAVE_PATH/oci-reg"
   for it in ./* 
   do
      if [ -d "$it" ] ; then 
         sudo cp -pr "$it" "$SERVICES_SAVE_PATH/oci-reg" && rm -rf "$it"
      elif [ -f "$it" ] ; then 
         sudo mv "$it" "$SERVICES_SAVE_PATH/oci-reg"
      fi
   done
   sudo rm -f "$SERVICES_SAVE_PATH/oci-reg/$(basename "$0")"
   sudo rm -f "$SERVICES_SAVE_PATH/oci-reg/env-oci-reg"
   sudo chown -R devadm "$SERVICES_SAVE_PATH/oci-reg"
   echo "service saved in $SERVICES_SAVE_PATH/oci-reg"
fi

#exit 0 