#!/bin/bash

loadSecretsRepo() {
  secretsGitPath="ssh://secrets-git-host/neintonine/yadm-config-secrets.git"
  secretsFolderPath="$HOME/.local/share/secrets"
  configFile="$HOME/.ssh/config"

  if [[ -d "$secretsFolderPath/.git" ]]; then
    return 0
  fi

  if [[ ! -f "$configFile" ]]; then
    echo "Can't find the ssh config file!"
    return 1
  fi

  if ! grep "Host secrets-git-host" "$configFile" >/dev/null; then
    echo "Can't find secrets-git-host config"
    return 1
  fi

  git clone "$secretsGitPath" "$secretsFolderPath"
  "$secretsFolderPath/deploy.sh"
}

addActions loadSecretsRepo
