Update dotfiles/.local/share/chezmoi/home/dot_local/share/ansible/roles/run_onchange_after_symlink-ansible-roles, dotfiles/.local/share/chezmoi/home/dot_local/bin/run_onchange_ensure-executable.tmpl, dotfiles/.local/share/chezmoi/home/dot_local/share/ansible/run_onchange_after_symlink-ansible-configs

This commit is contained in:
Brian Zalewski 2022-11-27 15:13:54 +00:00
parent faaa1f34e4
commit 336151a785
3 changed files with 22 additions and 8 deletions

View file

@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
{{- includeTemplate "universal/profile" }}
{{- includeTemplate "universal/logg" }}
{{ $exeFiles := (output "find" (joinPath .chezmoi.homeDir ".local" "bin") "-mindepth" "1" "-maxdepth" "1" "-type" "f") -}} {{ $exeFiles := (output "find" (joinPath .chezmoi.homeDir ".local" "bin") "-mindepth" "1" "-maxdepth" "1" "-type" "f") -}}
{{- range $exeFile := splitList "\n" $exeFiles -}} {{- range $exeFile := splitList "\n" $exeFiles -}}
{{- if ne $exeFile "" -}} {{- if ne $exeFile "" -}}
@ -7,7 +10,7 @@
{{ end -}} {{ end -}}
{{- end }} {{- end }}
### Ensure all files in ~/.local/bin are executable logg 'Ensuring all files in ~/.local/bin are executable'
find "$HOME/.local/bin" -mindepth 1 -maxdepth 1 -type f | while read EXE_FILE; do find "$HOME/.local/bin" -mindepth 1 -maxdepth 1 -type f | while read EXE_FILE; do
chmod +x "$EXE_FILE" chmod +x "$EXE_FILE"
done done

View file

@ -1,5 +1,8 @@
#!/usr/bin/env bash #!/usr/bin/env bash
{{- includeTemplate "universal/profile" }}
{{- includeTemplate "universal/logg" }}
{{ $roleDirs := (output "find" (joinPath .chezmoi.homeDir ".local" "src" "gas-station" "roles") "-mindepth" "2" "-maxdepth" "2" "-type" "d") -}} {{ $roleDirs := (output "find" (joinPath .chezmoi.homeDir ".local" "src" "gas-station" "roles") "-mindepth" "2" "-maxdepth" "2" "-type" "d") -}}
{{- range $roleDir := splitList "\n" $roleDirs -}} {{- range $roleDir := splitList "\n" $roleDirs -}}
{{- if ne $roleDir "" -}} {{- if ne $roleDir "" -}}
@ -7,7 +10,11 @@
{{ end -}} {{ end -}}
{{- end }} {{- end }}
logg 'Ensuring Gas Station roles are symlinked to ~/.local/share/ansible/roles'
find "$HOME/.local/src/gas-station/roles" -mindepth 2 -maxdepth 2 -type d | while read ROLE_PATH; do find "$HOME/.local/src/gas-station/roles" -mindepth 2 -maxdepth 2 -type d | while read ROLE_PATH; do
ROLE_FOLDER="professormanhattan.$(echo "$ROLE_PATH" | sed 's/.*\/\([^\/]*\)$/\1/')" ROLE_FOLDER="professormanhattan.$(echo "$ROLE_PATH" | sed 's/.*\/\([^\/]*\)$/\1/')"
ln -s "$ROLE_PATH" "$XDG_DATA_HOME/ansible/roles/$ROLE_FOLDER" if [ ! -d "$XDG_DATA_HOME/ansible/roles/$ROLE_FOLDER" ] || [ "$(readlink -f "$XDG_DATA_HOME/ansible/roles/$ROLE_FOLDER")" != "$ROLE_PATH" ]; then
rm -f "$XDG_DATA_HOME/ansible/roles/$ROLE_FOLDER"
ln -s "$ROLE_PATH" "$XDG_DATA_HOME/ansible/roles/$ROLE_FOLDER"
fi
fi fi

View file

@ -1,21 +1,25 @@
#!/usr/bin/env bash #!/usr/bin/env bash
{{- includeTemplate "universal/profile" }}
{{- includeTemplate "universal/logg" }}
### Symlink the variables / files / inventories to ~/.config/ansible folders if they are present ### Symlink the variables / files / inventories to ~/.config/ansible folders if they are present
### i.e. Changes to upstream will not impact the play if your configuration files are stored locally ### i.e. Changes to upstream will not impact the play if your configuration files are stored locally
for TARGET of "files" "group_vars" "host_vars" "inventories" "templates"; do for TARGET of "files" "group_vars" "host_vars" "inventories" "templates"; do
if [ -d "$HOME/.config/ansible/$TARGET" ] && [ "$(readlink -f "$HOME/.local/share/ansible/$TARGET")" != "$HOME/.config/ansible/$TARGET" ]; then if [ -d "$XDG_CONFIG_HOME/ansible/$TARGET" ] && [ "$(readlink -f "$XDG_DATA_HOME/ansible/$TARGET")" != "$XDG_CONFIG_HOME/ansible/$TARGET" ]; then
logg 'Symlinking Ansible playbook `'"$TARGET"'` to ~/.config/ansible/$TARGET' logg 'Symlinking Ansible playbook `'"$TARGET"'` to ~/.config/ansible/$TARGET'
rm -f "$HOME/.local/share/ansible/$TARGET" rm -f "$XDG_DATA_HOME/ansible/$TARGET"
ln -s "$HOME/.config/ansible/$TARGET" "$HOME/.local/share/ansible/$TARGET" ln -s "$XDG_CONFIG_HOME/ansible/$TARGET" "$XDG_DATA_HOME/ansible/$TARGET"
fi fi
done done
### Symlink tasks as well ### Symlink tasks as well
### Note: Only handles tasks one level deep (i.e. ~/.config/ansible/tasks/my-task.yml will link to the tasks folder ### Note: Only handles tasks one level deep (i.e. ~/.config/ansible/tasks/my-task.yml will link to the tasks folder
### but ~/.config/ansible/tasks/directory/my-other-task.yml will not) ### but ~/.config/ansible/tasks/directory/my-other-task.yml will not)
find "$HOME/.config/ansible/tasks" -type f | while read TASK_FILE; do find "$XDG_CONFIG_HOME/ansible/tasks" -type f | while read TASK_FILE; do
TASK_FILE_NAME="$(echo "$TASK_FILE" | sed 's/.*\/\([^\/]*\)$/\1/')" TASK_FILE_NAME="$(echo "$TASK_FILE" | sed 's/.*\/\([^\/]*\)$/\1/')"
if [ "$(readlink -f "$HOME/.local/share/ansible/tasks/$TASK_FILE_NAME")" != "$TASK_FILE" ]; then if [ "$(readlink -f "$XDG_DATA_HOME/ansible/tasks/$TASK_FILE_NAME")" != "$TASK_FILE" ]; then
ln -s "$TASK_FILE" "$HOME/.local/share/ansible/tasks/$TASK_FILE_NAME" logg 'Symlinking new task to ~/.local/share/ansible/tasks'
ln -s "$TASK_FILE" "$XDG_DATA_HOME/ansible/tasks/$TASK_FILE_NAME"
fi fi
done done