aboutsummaryrefslogtreecommitdiffstats
path: root/copy.sh
diff options
context:
space:
mode:
authorJaKooLit <ejhay.games@gmail.com>2024-12-08 05:55:35 +0900
committerJaKooLit <ejhay.games@gmail.com>2024-12-08 05:55:35 +0900
commita620abfc0a347ed2a891349c616b61af9544af69 (patch)
tree7a15dc406d6f5cdeb89310f3aa5bfd60b5b405e5 /copy.sh
parent3f83a9d15a00c6600619a4fa37e8387cf16dd4a9 (diff)
fix copy.sh multiple copies or backup for hypr directory
Diffstat (limited to 'copy.sh')
-rwxr-xr-xcopy.sh76
1 files changed, 28 insertions, 48 deletions
diff --git a/copy.sh b/copy.sh
index ce0f2825..384f6558 100755
--- a/copy.sh
+++ b/copy.sh
@@ -370,6 +370,12 @@ get_backup_dirname() {
echo "back-up_${timestamp}"
}
+# Check if the ~/.config/ directory exists
+if [ ! -d "$HOME/.config" ]; then
+ echo "${ERROR} - The ~/.config directory does not exist."
+ exit 1
+fi
+
printf "${INFO} - copying dotfiles ${BLUE}first${RESET} part\n"
# Config directories which will ask the user whether to replace or not
DIRS="
@@ -385,7 +391,7 @@ for DIR2 in $DIRS; do
if [ -d "$DIRPATH" ]; then
while true; do
- read -p "${CAT} ${ORANGE}$DIR2${RESET} config found in ~/.config/ Do you want to replace ${ORANGE}$DIR2${RESET} config? (Y/N): " DIR1_CHOICE
+ read -p "${CAT} ${ORANGE}$DIR2${RESET} config found in ~/.config/. Do you want to replace ${ORANGE}$DIR2${RESET} config? (Y/N): " DIR1_CHOICE
case "$DIR1_CHOICE" in
[Yy]* )
BACKUP_DIR=$(get_backup_dirname)
@@ -472,7 +478,7 @@ for DIR_NAME in $DIR; do
# Copy the new config
if [ -d "config/$DIR_NAME" ]; then
- cp -r "config/$DIR_NAME" ~/.config/"$DIR_NAME" 2>&1 | tee -a "$LOG"
+ cp -r "config/$DIR_NAME/" ~/.config/"$DIR_NAME" 2>&1 | tee -a "$LOG"
if [ $? -eq 0 ]; then
echo "${OK} - Copy of config for ${YELLOW}$DIR_NAME${RESET} completed!"
else
@@ -481,20 +487,12 @@ for DIR_NAME in $DIR; do
fi
else
echo "${ERROR} - Directory config/$DIR_NAME does not exist to copy."
- exit 1
fi
done
printf "\n"
-printf "${INFO} - Copying dotfiles ${BLUE}hypr directory${RESET} part\n"
-
-# Check if the config directory exists
-if [ ! -d "config" ]; then
- echo "${ERROR} - The 'config' directory does not exist."
- exit 1
-fi
-
+# restoration of old configs
DIRH="hypr"
FILES_TO_RESTORE=(
"Monitors.conf"
@@ -503,46 +501,28 @@ FILES_TO_RESTORE=(
)
DIRPATH=~/.config/"$DIRH"
-# Backup the existing directory if it exists
-if [ -d "$DIRPATH" ]; then
- echo -e "${NOTE} - Config for $DIRH found, attempting to back up."
- BACKUP_DIR=$(get_backup_dirname)
-
- mv "$DIRPATH" "$DIRPATH-backup-$BACKUP_DIR" 2>&1 | tee -a "$LOG"
- if [ $? -eq 0 ]; then
- echo -e "${NOTE} - Backed up $DIRH to $DIRPATH-backup-$BACKUP_DIR."
- else
- echo "${ERROR} - Failed to back up ${ORANGE}$DIRH${RESET}."
- exit 1
- fi
-fi
+BACKUP_DIR=$(get_backup_dirname)
-# Copy the new config
-if [ -d "config/$DIRH" ]; then
- cp -r "config/$DIRH" "$DIRPATH" 2>&1 | tee -a "$LOG"
- if [ $? -eq 0 ]; then
- echo "${OK} - Copy of config for ${ORANGE}$DIRH${RESET} completed!"
-
- # Loop through files to check and offer restoration
- for FILE_NAME in "${FILES_TO_RESTORE[@]}"; do
- BACKUP_FILE="$DIRPATH-backup-$BACKUP_DIR/UserConfigs/$FILE_NAME"
- if [ -f "$BACKUP_FILE" ]; then
- printf "\n${INFO} Found ${YELLOW}$FILE_NAME${RESET} in hypr backup...\n"
- read -p "${CAT} Do you want to restore ${ORANGE}$FILE_NAME${RESET} from backup? (y/n): " file_restore
- if [[ "$file_restore" == [Yy]* ]]; then
- cp "$BACKUP_FILE" "$DIRPATH/UserConfigs/$FILE_NAME" && echo "${OK} - $FILE_NAME restored!" 2>&1 | tee -a "$LOG"
- else
- echo "${NOTE} - Skipped restoring $FILE_NAME."
- fi
+# Check if the UserConfigs directory exists in ~/.config/hypr
+if [ -d "$DIRPATH/UserConfigs" ]; then
+ # Loop through files to check and offer restoration
+ for FILE_NAME in "${FILES_TO_RESTORE[@]}"; do
+ BACKUP_FILE="$DIRPATH-backup-$BACKUP_DIR/UserConfigs/$FILE_NAME"
+
+ if [ -f "$BACKUP_FILE" ]; then
+ printf "\n${INFO} Found ${YELLOW}$FILE_NAME${RESET} in hypr backup...\n"
+ read -p "${CAT} Do you want to restore ${ORANGE}$FILE_NAME${RESET} from backup? (y/n): " file_restore
+ if [[ "$file_restore" == [Yy]* ]]; then
+ cp "$BACKUP_FILE" "$DIRPATH/UserConfigs/$FILE_NAME" && echo "${OK} - $FILE_NAME restored!" 2>&1 | tee -a "$LOG"
+ else
+ echo "${NOTE} - Skipped restoring $FILE_NAME."
fi
- done
- else
- echo "${ERROR} - Failed to copy $DIRH."
- exit 1
- fi
+ else
+ echo "${WARNING} - No backup found for $FILE_NAME."
+ fi
+ done
else
- echo "${ERROR} - Directory config/$DIRH does not exist to copy."
- exit 1
+ echo "${ERROR} - UserConfigs directory does not exist in $DIRPATH. Skipping restoration."
fi
printf "\n%.0s" {1..2}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage