# info:          sources environment variables from `.env` file during deployment
# installation : run 'podi recipe env-file' or put this file into .podi folder 
# example usage: * put an .env file in your repo (with 'export FOO=1' e.g.)
#                * [IMAGE=alpine] ./podi init git@server:/dir/to/deploy [branch] [port] [name] 
#                *  automatic ssh-into-container (docker/podman) is now enabled

jail(){ 
  header .pod/jail 
  print "initing automatic ssh-into-container $ALPINE"
  install(){
    script='
      u=$(whoami)
      test -z $IMAGE && IMAGE=alpine
      test $u = "root" || {
        oci=$(which podman || which docker)
        $oci run -it -v /home/$u:/home/$u -w /home/$u $IMAGE /bin/sh
        exit
      }
    '
    echo "$script" | awk '{$1=$1};1' 
  }
  install > ~/.profile
}

on init_gitops jail
