-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendToGit.sh
56 lines (46 loc) · 1.45 KB
/
sendToGit.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# Get the current directory
current_dir="$(pwd)"
# Ensure .bashrc exists before removing and backing up
if [ -f "$HOME/.bashrc" ]; then
# Remove the current data
rm -f "$current_dir/.bashrc"
# Backup .bashrc
cp "$HOME/.bashrc" "$current_dir/.bashrc"
echo "Backed up .bashrc to $current_dir/.bashrc"
else
echo ".bashrc does not exist in the home directory."
fi
# Setup backup directory
config_backup="$current_dir/config"
mkdir -p "$config_backup"
# Define an array of directories to exclude
exclusions=(
"BraveSoftware"
# Add more directories to exclude here
)
# Build the rsync exclude parameters
exclude_params=()
for dir in "${exclusions[@]}"; do
exclude_params+=("--exclude" "$dir")
done
# Use rsync to copy the .config directory with exclusions
rsync -av --delete "${exclude_params[@]}" "$HOME/.config/" "$config_backup/"
echo "Backed up .config directory to $config_backup, excluding ${exclusions[*]}"
# Add all dot files excluding specified files
echo "Adding dot files to git repository..."
git add .
# Commit and push the changes
echo "Committing changes..."
timestamp=$(date +"%Y-%m-%d_%H:%M:%S")
commit_message="Update dot files - $timestamp"
if git commit -m "$commit_message"; then
echo "Commit successful. Pushing changes to git repository..."
if git push; then
echo "Backup complete and changes pushed!"
else
echo "Failed to push changes to the repository."
fi
else
echo "Nothing to commit or commit failed."
fi