From 6a180c7ba64ffae635e6e1139dd35b653624b273 Mon Sep 17 00:00:00 2001 From: shynd Date: Tue, 25 Feb 2025 20:21:28 +0100 Subject: [PATCH] update copy script --- copy.sh | 184 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 93 insertions(+), 91 deletions(-) diff --git a/copy.sh b/copy.sh index dacd765..b99762b 100644 --- a/copy.sh +++ b/copy.sh @@ -521,101 +521,103 @@ printf "\n%.0s" {1..1} # special copy for waybar because of symlink DIRW="waybar" -DIRPATHW="$HOME/.config/$DIRW" -if [ -d "$DIRPATHW" ]; then - while true; do - read -p "${CAT} do you want to replace ${YELLOW}$DIRW${RESET} config? (y/n): " DIR1_CHOICE - case "$DIR1_CHOICE" in - [Yy]* ) - BACKUP_DIR=$(get_backup_dirname) - cp -r "$DIRPATHW" "$DIRPATHW-backup-$BACKUP_DIR" 2>&1 | tee -a "$LOG" - echo -e "${NOTE} - backed up $DIRW to $DIRPATHW-backup-$BACKUP_DIR" 2>&1 | tee -a "$LOG" +DIRPATHw="$HOME/.config/$DIRW" +if [ -d "$DIRPATHw" ]; then + while true; do + read -p "${CAT} do you want to replace ${YELLOW}$DIRW${RESET} config? (y/n): " DIR1_CHOICE + case "$DIR1_CHOICE" in + [Yy]* ) + BACKUP_DIR=$(get_backup_dirname) + cp -r "$DIRPATHw" "$DIRPATHw-backup-$BACKUP_DIR" 2>&1 | tee -a "$LOG" + echo -e "${NOTE} - backed up $DIRW to $DIRPATHw-backup-$BACKUP_DIR." 2>&1 | tee -a "$LOG" + + # Remove the old $DIRPATHw and copy the new one + rm -rf "$DIRPATHw" && cp -r "config/$DIRW" "$DIRPATHw" 2>&1 | tee -a "$LOG" + + # step 1: handle waybar symlinks + for file in "config" "style.css"; do + symlink="$DIRPATHw-backup-$BACKUP_DIR/$file" + target_file="$DIRPATHw/$file" + + if [ -L "$symlink" ]; then + symlink_target=$(readlink "$symlink") + if [ -f "$symlink_target" ]; then + rm -f "$target_file" && cp -f "$symlink_target" "$target_file" + echo -e "${NOTE} - copied $file as a regular file" + else + echo -e "${WARN} - symlink target for $file does not exist" + fi + fi + done + + # Step 2: Copy non-existing directories and files under waybar/configs + for dir in "$DIRPATHw-backup-$BACKUP_DIR/configs"/*; do + [ -e "$dir" ] || continue # Skip if no files are found + if [ -d "$dir" ]; then + target_dir="$HOME/.config/waybar/configs/$(basename "$dir")" + if [ ! -d "$target_dir" ]; then + echo "copying directory $dir to $HOME/.config/waybar/configs/" >> "$LOG" + cp -r "$dir" "$HOME/.config/waybar/configs/" + else + echo "directory $target_dir already exists, skipping..." >> "$LOG" + fi + fi + done - # remove old $DIRPATHW and copy the new one - rm -rf "$DIRPATHW" && cp "config/$DIRW" "$DIRPATHW" 2>&1 | tee -a "$LOG" + for file in "$DIRPATHw-backup-$BACKUP_DIR/configs"/*; do + [ -e "$file" ] || continue + target_file="$HOME/.config/waybar/configs/$(basename "$file")" + if [ ! -e "$target_file" ]; then + echo "Copying $file to $HOME/.config/waybar/configs/" >> "$LOG" + cp "$file" "$HOME/.config/waybar/configs/" + else + echo "file $target_file already exists, skipping..." >> "$LOG" + fi + done || true + + # Step 3: Copy unique files in waybar/style + for file in "$DIRPATHw-backup-$BACKUP_DIR/style"/*; do + [ -e "$file" ] || continue + + if [ -d "$file" ]; then + target_dir="$HOME/.config/waybar/style/$(basename "$file")" + if [ ! -d "$target_dir" ]; then + echo "copying directory $file to $HOME/.config/waybar/style/" >> "$LOG" + cp -r "$file" "$HOME/.config/waybar/style/" + else + echo "directory $target_dir already exists, skipping..." >> "$LOG" + fi + else + target_file="$HOME/.config/waybar/style/$(basename "$file")" + if [ ! -e "$target_file" ]; then + echo "copying file $file to $HOME/.config/waybar/style/" >> "$LOG" + cp "$file" "$HOME/.config/waybar/style/" + else + echo "file $target_file already exists, skipping..." >> "$LOG" + fi + fi + done || true - # step 1: handle waybar symlinks - for file in "config" "style.css"; do - symlink="$DIRPATHW-backup-$BACKUP_DIR/$file" - target_file="$DIRPATHW/$file" + # Step 4: restore Modules_Extras + BACKUP_FILE="$DIRPATHw-backup-$BACKUP_DIR/UserModules" + if [ -f "$BACKUP_FILE" ]; then + cp -f "$BACKUP_FILE" "$DIRPATHw/UserModules" + fi - if [ -L "$symlink" ]; then - symlink_target=$(readlink "$symlink") - if [ -f "$symlink_target" ]; then - rm -f "$target_file" && cp -f "$symlink_target" "$target_file" - echo -e "${NOTE} - copied $file as a regular file" - else - echo -e "${WARN} - symlink target for $file does not exist" - fi - fi - done - - # step 2: copy non-existing directories and files under waybar/configs - for dir in "$DIRPATHW-backup-$BACKUP_DIR/configs"/*; do - [ -e "$dir" ] || continue # skip if no files are found - if [ -d "$dir" ]; then - target_dir="$HOME/.config/waybar/configs/$(basename "$dir")" - if [ ! -d "$target_dir" ]; then - echo "copying directory $dir to $HOME/.config/waybar/configs/" >> "$LOG" - cp -r "$dir" "$HOME/.config/waybar/configs/" - else - echo "directory $target_dir already exists, skipping..." >> "$LOG" - fi - fi - done - - for file in "$DIRPATHW-backup-$BACKUP_DIR/configs"/*; do - [ -e "$file" ] || continue # skip if no files are found - target_file="$HOME/.config/waybar/configs/$(basename "$file")" - if [ ! -e "$target_file" ]; then - echo "copying $file to $HOME/.config/waybar/configs/" >> "$LOG" - cp "$file" "$HOME/.config/waybar/configs/" - else - echo "file $target_file already exists, skipping..." >> "$LOG" - fi - done || true - - # step 3: copy unique files in waybar/style - for file in "$DIRPATHW-backup-$BACKUP_DIR/style/"*; do - [ -e "$file" ] || continue # skip if no files are found - if [ -d "$file" ]; then - target_dir="$HOME/.config/waybar/style/$(basename "$file")" - if [ ! -d "$target_dir" ]; then - echo "copying directory $file to $HOME/.config/waybar/style/" >> "$LOG" - cp -r "$file" "$HOME/.config/waybar/style/" # TODO: shouldn't this be $target_dir instead of $file? - else - echo "directory $target_dir already_exists, skipping..." >> "$LOG" - fi - else - target_file="$HOME/.config/waybar/style/$(basename "$file")" - if [ ! -e "$target_file" ]; then - echo "copying file $file to $HOME/.config/waybar/style/" >> "$LOG" - cp "$file" "$HOME/.config/waybar/style/" - else - echo "file $target_file already exists, skipping..." >> "$LOG" - fi - fi - done || true - - # step 4: restore Modules_Extra - BACKUP_FILE="$DIRPATHW-backup-$BACKUP_DIR/UserModules" - if [ -f "$BACKUP_FILE" ]; then - cp -f "$BACKUP_FILE" "$DIRPATHW/UserModules" - fi - - break - ;; - [Nn]* ) - echo -e "${NOTE} - skipping ${YELLOW}$DIRW${RESET} config replacement" 2>&1 | tee -a "$LOG" - break - ;; - * ) - echo -e "${WARN} - invalid choice, please enter Y or N" - esac - done + break + ;; + [Nn]* ) + echo -e "${NOTE} - skipping ${YELLOW}$DIRW${RESET} config replacement" 2>&1 | tee -a "$LOG" + break + ;; + * ) + echo -e "${WARN} - invalid choice, please enter Y or N" + ;; + esac + done else - cp -r "config/$DIRW" "$DIRWPATH" 2>&1 | tee -a "$LOG" - echo -e "${OK} - copy completed for ${YELLOW}$DIRW${RESET}" 2>&1 | tee -a "$LOG" + cp -r "config/$DIRW" "$DIRPATHw" 2>&1 | tee -a "$LOG" + echo -e "${OK} - copy completed for ${YELLOW}$DIRW${RESET}" 2>&1 | tee -a "$LOG" fi printf "\n%.0s" {1..1}