forked from Shinonome/dots-hyprland
more save script
This commit is contained in:
+22
-21
@@ -10,20 +10,15 @@ function get_checksum() {
|
|||||||
md5sum "$1" | awk '{print $1}'
|
md5sum "$1" | awk '{print $1}'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Define the folders to update
|
# Define the folders to update
|
||||||
folders=(".config" ".local")
|
folders=(".config" ".local")
|
||||||
exclude_folders=("/home/janik/.config/hypr/custom")
|
# exclude_folders=("/home/janik/.config/hypr/custom") TODO: Implement exclude folders
|
||||||
|
|
||||||
# Build the exclude string for find command
|
|
||||||
exclude_string=""
|
|
||||||
for folder in "${exclude_folders[@]}"; do
|
|
||||||
exclude_string+="! -path $folder -prune -o "
|
|
||||||
done
|
|
||||||
|
|
||||||
# Then check which files have been modified since the last update
|
# Then check which files have been modified since the last update
|
||||||
modified_files=()
|
modified_files=()
|
||||||
|
|
||||||
# Find all files in the specified folders and their subfolders, excluding specified folders
|
# Find all files in the specified folders and their subfolders
|
||||||
while IFS= read -r -d '' file; do
|
while IFS= read -r -d '' file; do
|
||||||
# Calculate checksums
|
# Calculate checksums
|
||||||
base_checksum=$(get_checksum "$base/$file")
|
base_checksum=$(get_checksum "$base/$file")
|
||||||
@@ -32,7 +27,8 @@ while IFS= read -r -d '' file; do
|
|||||||
if [[ $base_checksum != $home_checksum ]]; then
|
if [[ $base_checksum != $home_checksum ]]; then
|
||||||
modified_files+=("$file")
|
modified_files+=("$file")
|
||||||
fi
|
fi
|
||||||
done < <(eval find "${folders[@]}" -type f $exclude_string -print0)
|
done < <(find "${folders[@]}" -type f -print0)
|
||||||
|
|
||||||
|
|
||||||
echo "Modified files: ${modified_files[@]}"
|
echo "Modified files: ${modified_files[@]}"
|
||||||
|
|
||||||
@@ -43,18 +39,19 @@ if [[ ${#modified_files[@]} -gt 0 ]]; then
|
|||||||
echo "$file"
|
echo "$file"
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
echo "No files found that have been modified since the last installation/update. All files will be replaced. Are you sure you want to continue? [y/N] "
|
echo "No files found that have been modified since the last update. All files will be replaced. Are you sure you want to continue? [Y/n] "
|
||||||
read -n 1 -r
|
read -n 1 -r
|
||||||
echo
|
echo
|
||||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
|
||||||
exit 1
|
echo "Exiting."
|
||||||
|
exit 0
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ask if the user wants to keep them
|
# Ask if the user wants to keep them
|
||||||
read -p "Do you want to keep these files untouched? [y/N] " -n 1 -r
|
read -p "Do you want to keep these files untouched? [Y/n] " -n 1 -r
|
||||||
echo
|
echo
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
|
||||||
echo "Keeping modified files."
|
echo "Keeping modified files."
|
||||||
else
|
else
|
||||||
echo "Replacing all files."
|
echo "Replacing all files."
|
||||||
@@ -67,12 +64,14 @@ git pull
|
|||||||
# Now only replace the files that are not modified by the user
|
# Now only replace the files that are not modified by the user
|
||||||
for folder in "${folders[@]}"; do
|
for folder in "${folders[@]}"; do
|
||||||
# Find all files (including those in subdirectories) and copy them
|
# Find all files (including those in subdirectories) and copy them
|
||||||
find "$folder" -type f $exclude_string -print0 | while IFS= read -r -d '' file; do
|
find "$folder" -type f -print0 | while IFS= read -r -d '' file; do
|
||||||
if [[ -f "$file" && ! " ${modified_files[@]} " =~ " ${file} " ]]; then
|
if [[ -f "$file" ]]; then
|
||||||
# Construct the destination path
|
if [[ ! " ${modified_files[@]} " =~ " ${file} " ]]; then
|
||||||
destination="$HOME/$file"
|
# Construct the destination path
|
||||||
# Copy the file
|
destination="$HOME/$file"
|
||||||
cp -rf "$base/$file" "$destination"
|
# Copy the file
|
||||||
|
cp -rf "$base/$file" "$destination"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
@@ -80,7 +79,7 @@ done
|
|||||||
# Add the new files, because maybe the update added new files
|
# Add the new files, because maybe the update added new files
|
||||||
for folder in "${folders[@]}"; do
|
for folder in "${folders[@]}"; do
|
||||||
# Find all files (including those in subdirectories) and copy them
|
# Find all files (including those in subdirectories) and copy them
|
||||||
find "$folder" -type f $exclude_string -print0 | while IFS= read -r -d '' file; do
|
find "$folder" -type f -print0 | while IFS= read -r -d '' file; do
|
||||||
if [[ ! -f "$HOME/$file" ]]; then
|
if [[ ! -f "$HOME/$file" ]]; then
|
||||||
echo "Adding new file: $file"
|
echo "Adding new file: $file"
|
||||||
# Construct the destination path
|
# Construct the destination path
|
||||||
@@ -90,3 +89,5 @@ for folder in "${folders[@]}"; do
|
|||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user