working on copy script
This commit is contained in:
parent
2be8d4a6d7
commit
d518e10b3d
240
copy.sh
240
copy.sh
|
@ -568,3 +568,243 @@ for DIR_NAME in $DIR; do
|
||||||
done
|
done
|
||||||
|
|
||||||
printf "\n%.0s" {1..1}
|
printf "\n%.0s" {1..1}
|
||||||
|
|
||||||
|
# Restoring UserConfigs and UserScripts
|
||||||
|
DIRH="hypr"
|
||||||
|
FILES_TO_RESTORE=(
|
||||||
|
"ENVariables.conf"
|
||||||
|
"LaptopDisplay.conf"
|
||||||
|
"Laptops.conf"
|
||||||
|
"Monitors.conf"
|
||||||
|
"Startup_Apps.conf"
|
||||||
|
"UserDecorations.conf"
|
||||||
|
"UserAnimations.conf"
|
||||||
|
"UserKeybinds.conf"
|
||||||
|
"UserSettings.conf"
|
||||||
|
"WindowRules.conf"
|
||||||
|
"WorkspaceRules.conf"
|
||||||
|
)
|
||||||
|
|
||||||
|
DIRPATH=~/.config/"$DIRH"
|
||||||
|
BACKUP_DIR=$(get_backup_dirname)
|
||||||
|
BACKUP_DIR_PATH="$DIRPATH-backup-$BACKUP_DIR/UserConfigs"
|
||||||
|
|
||||||
|
if [ -z "$BACKUP_DIR" ]; then
|
||||||
|
echo "${ERROR} - backup directory name is empty. Exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -d "$BACKUP_DIR_PATH" ]; then
|
||||||
|
echo -e "${NOTE} restoring previous ${MAGENTA}user-configs${RESET}... "
|
||||||
|
echo -e "${WARN} ${WARNING}if you decide to restore the old configs, make sure to handle the updates or changes manually${RESET}."
|
||||||
|
|
||||||
|
for FILE_NAME in "${FILES_TO_RESTORE[@]}"; do
|
||||||
|
BACKUP_FILE="$BACKUP_DIR_PATH/$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 ${YELLOW}$FILE_NAME${RESET} from backup? (y/N): " file_restore
|
||||||
|
|
||||||
|
if [[ "$file_restore" == [Yy]* ]]; then
|
||||||
|
if cp "$BACKUP_FILE" "$DIRPATH/UserConfigs/$FILE_NAME"; then
|
||||||
|
echo "${OK} - $FILE_NAME restored!" 2>&1 | tee -a "$LOG"
|
||||||
|
else
|
||||||
|
echo "${ERROR} - failed to restore $FILE_NAME!" 2>&1 | tee -a "$LOG"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "${NOTE} - skipped restoring $FILE_NAME."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\n%.0s" {1..1}
|
||||||
|
|
||||||
|
# Restoring previous UserScripts
|
||||||
|
DIRSH="hypr"
|
||||||
|
SCRIPTS_TO_RESTORE=(
|
||||||
|
"RofiBeats.sh"
|
||||||
|
"Weather.py"
|
||||||
|
"Weather.sh"
|
||||||
|
)
|
||||||
|
|
||||||
|
DIRSHPATH=~/.config/"$DIRSH"
|
||||||
|
BACKUP_DIR_PATH="$DIRSHPATH-backup-$BACKUP_DIR/UserScripts"
|
||||||
|
|
||||||
|
if [ -d "$BACKUP_DIR_PATH" ]; then
|
||||||
|
echo -e "${NOTE} restoring previous ${MAGENTA}User-Scripts${RESET}..."
|
||||||
|
|
||||||
|
for SCRIPT_NAME in "${SCRIPTS_TO_RESTORE[@]}"; do
|
||||||
|
BACKUP_SCRIPT="$BACKUP_DIR_PATH/$SCRIPT_NAME"
|
||||||
|
|
||||||
|
if [ -f "$BACKUP_SCRIPT" ]; then
|
||||||
|
printf "\n${INFO} found ${YELLOW}$SCRIPT_NAME${RESET} in hypr backup...\n"
|
||||||
|
read -p "${CAT} do you want to restore ${YELLOW}$SCRIPT_NAME${RESET} from backup? (y/N): " script_restore
|
||||||
|
if [[ "$script_restore" == [Yy]* ]]; then
|
||||||
|
if cp "$BACKUP_SCRIPT" "$DIRSHPATH/UserScripts/$SCRIPT_NAME"; then
|
||||||
|
echo "${OK} - $SCRIPT_NAME restored!" 2>&1 | tee -a "$LOG"
|
||||||
|
else
|
||||||
|
echo "${ERROR} - failed to restore $SCRIPT_NAME!" 2>&1 | tee -a "$LOG"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "${NOTE} - skipped restoring $SCRIPT_NAME."
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\n%.0s" {1..1}
|
||||||
|
|
||||||
|
# Define the target directory for rofi themes
|
||||||
|
rofi_DIR="$HOME/.local/share/rofi/themes"
|
||||||
|
|
||||||
|
if [ ! -d "$rofi_DIR" ]; then
|
||||||
|
mkdir -p "$rofi_DIR"
|
||||||
|
fi
|
||||||
|
if [ -d "$HOME/.config/rofi/themes" ]; then
|
||||||
|
if [ -z "$(ls -A $HOME/.config/rofi/themes)" ]; then
|
||||||
|
echo '/* Dummy Rofi theme */' > "$HOME/.config/rofi/themes/dummy.rasi"
|
||||||
|
fi
|
||||||
|
ln -snf ~/.config/rofi/themes/* ~/.local/share/rofi/themes/
|
||||||
|
# Delete the dummy file if it was created
|
||||||
|
if [ -f "$HOME/.config/rofi/themes/dummy.rasi" ]; then
|
||||||
|
rm "$HOME/.config/rofi/themes/dummy.rasi"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
printf "\n%.0s" {1..1}
|
||||||
|
|
||||||
|
# wallpaper stuff
|
||||||
|
mkdir -p ~/Pictures/wallpapers
|
||||||
|
if cp -r wallpapers ~/Pictures/; then
|
||||||
|
echo "${OK} some ${MAGENTA}wallpapers${RESET} copied successfully!" | tee -a "$LOG"
|
||||||
|
else
|
||||||
|
echo "${ERROR} failed to copy some ${YELLOW}wallpapers${RESET}" | tee -a "$LOG"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Set some files as executable
|
||||||
|
chmod +x ~/.config/hypr/scripts/* 2>&1 | tee -a "$LOG"
|
||||||
|
chmod +x ~/.config/hypr/UserScripts/* 2>&1 | tee -a "$LOG"
|
||||||
|
# Set executable for initial-boot.sh
|
||||||
|
chmod +x ~/.config/hypr/initial-boot.sh 2>&1 | tee -a "$LOG"
|
||||||
|
|
||||||
|
# Waybar config to symlink & retain based on machine type
|
||||||
|
if hostnamectl | grep -q 'Chassis: desktop'; then
|
||||||
|
config_file="$waybar_config"
|
||||||
|
config_remove=" Laptop"
|
||||||
|
else
|
||||||
|
config_file="$waybar_config_laptop"
|
||||||
|
config_remove=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
ln -sf "$config_file" "$HOME/.config/waybar/config" 2>&1 | tee -a "$LOG" || true
|
||||||
|
|
||||||
|
# Remove inappropriate waybar configs
|
||||||
|
rm -rf "$HOME/.config/waybar/configs/[TOP] Default$config_remove" \
|
||||||
|
"$HOME/.config/waybar/configs/[BOT] Default$config_remove" \
|
||||||
|
"$HOME/.config/waybar/configs/[TOP] Default$config_remove (old v1)" \
|
||||||
|
"$HOME/.config/waybar/configs/[TOP] Default$config_remove (old v2)" \
|
||||||
|
"$HOME/.config/waybar/configs/[TOP] Default$config_remove (old v3)" \
|
||||||
|
"$HOME/.config/waybar/configs/[TOP] Default$config_remove (old v4)" 2>&1 | tee -a "$LOG" || true
|
||||||
|
|
||||||
|
printf "\n%.0s" {1..1}
|
||||||
|
|
||||||
|
# for SDDM (sequoia_2)
|
||||||
|
sddm_sequioa="/usr/share/sddm/themes/sequoia_2"
|
||||||
|
if [ -d "$sddm_sequioa" ]; then
|
||||||
|
while true; do
|
||||||
|
read -rp "${CAT} SDDM sequoia_2 theme detected! apply current wallpaper as SDDM background? (y/n): " SDDM_WALL
|
||||||
|
|
||||||
|
# Remove any leading/trailing whitespace or newlines from input
|
||||||
|
SDDM_WALL=$(echo "$SDDM_WALL" | tr -d '\n' | tr -d ' ')
|
||||||
|
|
||||||
|
case $SDDM_WALL in
|
||||||
|
[Yy])
|
||||||
|
# Copy the wallpaper, ignore errors if the file exists or fails
|
||||||
|
sudo cp -r "config/hypr/wallpaper_effects/.wallpaper_current" "/usr/share/sddm/themes/sequoia_2/backgrounds/default" || true
|
||||||
|
echo "${NOTE} Current wallpaper applied as default SDDM background" 2>&1 | tee -a "$LOG"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
[Nn])
|
||||||
|
echo "${NOTE} you chose not to apply the current wallpaper to SDDM." 2>&1 | tee -a "$LOG"
|
||||||
|
break
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo "please enter 'y' or 'n' to proceed."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# additional wallpapers
|
||||||
|
printf "\n%.0s" {1..1}
|
||||||
|
echo "${MAGENTA}by default only a few wallpapers are copied${RESET}..."
|
||||||
|
|
||||||
|
# TODO: download more wallpapers?
|
||||||
|
|
||||||
|
# CLeaning up of ~/.config/ backups
|
||||||
|
cleanup_backups() {
|
||||||
|
CONFIG_DIR=~/.config
|
||||||
|
BACKUP_PREFIX="-backup"
|
||||||
|
|
||||||
|
# Loop through directories in ~/.config
|
||||||
|
for DIR in "$CONFIG_DIR"/*; do
|
||||||
|
if [ -d "$DIR" ]; then
|
||||||
|
BACKUP_DIRS=()
|
||||||
|
|
||||||
|
# Check for backup directories
|
||||||
|
for BACKUP in "$DIR"$BACKUP_PREFIX*; do
|
||||||
|
if [ -d "$BACKUP" ]; then
|
||||||
|
BACKUP_DIRS+=("$BACKUP")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# If more than one backup found
|
||||||
|
if [ ${#BACKUP_DIRS[@]} -gt 1 ]; then
|
||||||
|
printf "\n\n ${INFO} performing cleanup for ${YELLOW}${DIR##*/}${RESET}\n"
|
||||||
|
|
||||||
|
echo -e "${NOTE} found multiple backups for: ${YELLOW}${DIR##*/}${RESET}"
|
||||||
|
echo "${YELLOW}Backups: ${RESET}"
|
||||||
|
|
||||||
|
# List the backups
|
||||||
|
for BACKUP in "${BACKUP_DIRS[@]}"; do
|
||||||
|
echo " - ${BACKUP##*/}"
|
||||||
|
done
|
||||||
|
|
||||||
|
read -p "${CAT} do you want to delete the older backups of ${YELLOW}${DIR##*/}${RESET} and keep the latest backup only? (y/N): " back_choice
|
||||||
|
if [[ "$back_choice" == [Yy]* ]]; then
|
||||||
|
# Sort backups by modification time
|
||||||
|
latest_backup="${BACKUP_DIRS[0]}"
|
||||||
|
for BACKUP in "${BACKUP_DIRS[@]}"; do
|
||||||
|
if [ "$BACKUP" -nt "$latest_backup" ]; then
|
||||||
|
latest_backup="$BACKUP"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
for BACKUP in "${BACKUP_DIRS[@]}"; do
|
||||||
|
if [ "$BACKUP" != "$latest_backup" ]; then
|
||||||
|
echo "deleting: ${BACKUP##*/}"
|
||||||
|
rm -rf "$BACKUP"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
echo "old backups of ${YELLOW}${DIR##*/}${RESET} deleted, keeping: ${MAGENTA}${latest_backup##*/}${RESET}"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
# Execute the cleanup function
|
||||||
|
cleanup_backups
|
||||||
|
|
||||||
|
# symlinks for waybar style
|
||||||
|
ln -sf "$waybar_style" "$HOME/.config/waybar/style.css" && \
|
||||||
|
|
||||||
|
printf "\n%.0s" {1..1}
|
||||||
|
|
||||||
|
# initialize wallust to avoid config error on hyprland
|
||||||
|
wallust run -s $wallpaper 2>&1 | tee -a "$LOG"
|
||||||
|
|
||||||
|
printf "\n%.0s" {1..2}
|
||||||
|
printf "${OK} hyprland-dotfiles is now ready"
|
||||||
|
printf "\n%.0s" {1..1}
|
||||||
|
printf "${INFO} however, it is ${MAGENTA}HIGHLY SUGGESTED${RESET} to logout and re-login or better reboot to avoid any issues"
|
||||||
|
printf "\n%.0s" {1..3}
|
Loading…
Reference in New Issue