Adds hooks for secrets
This commit is contained in:
parent
63fcd502a8
commit
7a56328fad
4 changed files with 50 additions and 11 deletions
|
|
@ -6,10 +6,6 @@ loadSecretsRepo() {
|
|||
configFile="$HOME/.ssh/config"
|
||||
|
||||
if [[ -d "$secretsFolderPath/.git" ]]; then
|
||||
(
|
||||
cd "$secretsFolderPath"
|
||||
git pull --ff-only
|
||||
)
|
||||
return 0
|
||||
fi
|
||||
|
||||
|
|
@ -24,13 +20,7 @@ loadSecretsRepo() {
|
|||
fi
|
||||
|
||||
git clone "$secretsGitPath" "$secretsFolderPath"
|
||||
}
|
||||
|
||||
loadSecrets() {
|
||||
secretsFolderPath="$HOME/.local/share/secrets"
|
||||
|
||||
loadSecretsRepo
|
||||
"$secretsFolderPath/deploy.sh"
|
||||
}
|
||||
|
||||
addActions loadSecrets
|
||||
addActions loadSecretsRepo
|
||||
|
|
|
|||
13
.config/yadm/hooks/post_commit
Executable file
13
.config/yadm/hooks/post_commit
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/bin/bash
|
||||
|
||||
handleSecretChanges() {
|
||||
secretsFolderPath="$HOME/.local/share/secrets"
|
||||
|
||||
message=$(yadm log -1 --format="%s")
|
||||
hash=$(yadm rev-parse HEAD)
|
||||
|
||||
git --git-dir "$secretsFolderPath/.git" --work-tree "$secretsFolderPath" add .
|
||||
git --git-dir "$secretsFolderPath/.git" --work-tree "$secretsFolderPath" commit -m "$message" -m "Issued from YADM by commit '$hash'"
|
||||
}
|
||||
|
||||
handleSecretChanges
|
||||
28
.config/yadm/hooks/post_pull
Executable file
28
.config/yadm/hooks/post_pull
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/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
|
||||
git --git-dir "$secretsFolderPath/.git" --work-tree "$secretsFolderPath" pull --ff-only
|
||||
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"
|
||||
}
|
||||
|
||||
echo "# Updating secrets"
|
||||
loadSecretsRepo
|
||||
"$secretsFolderPath/deploy.sh"
|
||||
8
.config/yadm/hooks/post_push
Normal file
8
.config/yadm/hooks/post_push
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#!/bin/bash
|
||||
|
||||
handleSecretChanges() {
|
||||
secretsFolderPath="$HOME/.local/share/secrets"
|
||||
|
||||
git --git-dir "$secretsFolderPath/.git" --work-tree "$secretsFolderPath" push }
|
||||
|
||||
handleSecretChanges
|
||||
Loading…
Add table
Add a link
Reference in a new issue