diff options
author | Botond Hende <nettingman@gmail.com> | 2024-04-14 06:38:49 +0200 |
---|---|---|
committer | Botond Hende <nettingman@gmail.com> | 2024-04-14 06:38:49 +0200 |
commit | 0221492f62bcc1b766c2a4d5dbe26f6ff2ed8bc2 (patch) | |
tree | f91b7ada571a4dab7ae99c8f3ee252616baff2db /deploy_configs |
squashed init
Diffstat (limited to 'deploy_configs')
-rwxr-xr-x | deploy_configs | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/deploy_configs b/deploy_configs new file mode 100755 index 0000000..5a8749d --- /dev/null +++ b/deploy_configs @@ -0,0 +1,67 @@ +#!/usr/bin/bash -eu + +echo =============================== +echo Starting deploy. + +deploy_path="$HOME" +dummy_home="./home" + +cd "$(dirname "$0")" +dummy_home_abs=$(pwd)/home +additional_list="" +while read line; do + folder_path=$(dirname "$line") + file=$(basename "$line") + folder_path=${folder_path:6} + if [[ "$folder_path" != "" ]]; then + mkdir -p "$deploy_path""$folder_path" + fi + + config_path="$dummy_home_abs""$folder_path"/"$file" + desired_path="$deploy_path""$folder_path"/"$file" + if [[ "$file" == *".fof" ]]; then + desired_path=${desired_path::-4} + fi + + if [[ "$folder_path" == *"additional.d"* ]]; then + if [[ "$additional_list" != *"$folder_path"* ]]; then + additional_list+='\n\n'"$folder_path" + fi + + already_deployed="-" + if [[ -L "$desired_path" ]]; then + already_deployed="+" + fi + + additional_list+='\n'"$already_deployed""$file" + else + if [[ "$file" != *".fof" && ( -L "$desired_path" || ( ! -f "$desired_path" && ! -d "$desired_path" ) ) ]]; then + ln -sf "$config_path" "$desired_path" + else + if [[ ( -f "$desired_path".deploy_backup || -d "$desired_path".deploy_backup ) ]]; then + rm -r "$desired_path".deploy_backup + fi + + if [[ ( -f "$desired_path" || -d "$desired_path" ) ]]; then + mv -T "$desired_path" "$desired_path".deploy_backup + fi + + if [[ "$file" == *".fof" ]]; then + echo Deploying fire and forget config: "$desired_path" + cp "$config_path" "$desired_path" + else + echo Path exists, moved to filename.deploy_backup: "$desired_path" + ln -sf "$config_path" "$desired_path" + fi + fi + fi +done < <(find "$dummy_home" -type f) + +echo +echo =============================== +echo Deploy finished. +echo +echo =============================== +echo Additional configs to consider: +additional_list=${additional_list:4} +echo -e "$additional_list" |