mirror of
https://github.com/zebrajr/dotfiles.git
synced 2025-12-06 00:20:05 +01:00
initial deployment bash script
This commit is contained in:
parent
73e760780c
commit
53e5131419
42
deployer.sh
Executable file
42
deployer.sh
Executable file
|
|
@ -0,0 +1,42 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Load the pairs from the JSON file
|
||||
pairs=$(jq -r '.[] | "\(.source)=\(.destination)=\(.type)"' deployment_playbook.json)
|
||||
|
||||
# Loop through the pairs and copy the source to the destination
|
||||
for pair in ${pairs[@]}; do
|
||||
# Split the pair into source and destination
|
||||
IFS='=' read -ra pair_array <<< "$pair"
|
||||
source=$(echo "${pair_array[0]}" | sed 's/\\"/"/g')
|
||||
destination=$(echo "${pair_array[1]}" | sed 's/\\"/"/g')
|
||||
type=$(echo "${pair_array[2]}" | sed 's/\\"/"/g')
|
||||
|
||||
# Expand ~ if used in the destination
|
||||
destination="${destination/#\~/$HOME}"
|
||||
|
||||
# Check if the destination already exists
|
||||
if [ -e "$destination" ]; then
|
||||
# Backup the destination based on the type
|
||||
if [ "$type" == "append" ]; then
|
||||
echo "Backing up $destination to $destination.backup (cp -r)"
|
||||
cp -r "$destination" "$destination.backup"
|
||||
elif [ "$type" == "replace" ]; then
|
||||
echo "Backing up $destination to $destination.backup (mv)"
|
||||
mv "$destination" "$destination.backup"
|
||||
else
|
||||
echo "Invalid type: $type"
|
||||
continue
|
||||
fi
|
||||
fi
|
||||
|
||||
# Create the directory up to the destination path if it doesn't exist
|
||||
destination_dir=$(dirname "$destination")
|
||||
if [ ! -d "$destination_dir" ]; then
|
||||
echo "Creating directory: $destination_dir"
|
||||
mkdir -p "$destination_dir"
|
||||
fi
|
||||
|
||||
# Copy the source to the destination
|
||||
echo "Copying $source to $destination"
|
||||
cp -r "$source" "$destination"
|
||||
done
|
||||
12
deployment_playbook.json
Normal file
12
deployment_playbook.json
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
[
|
||||
{
|
||||
"source": "config/nvim",
|
||||
"destination": "~/.config/nvim",
|
||||
"type": "replace"
|
||||
},
|
||||
{
|
||||
"source": "oh-my-zsh/custom/aliases.zsh",
|
||||
"destination": "~/.oh-my-zsh/custom/aliases.zsh",
|
||||
"type": "append"
|
||||
}
|
||||
]
|
||||
Loading…
Reference in New Issue
Block a user