Update install.sh and restore.sh
This commit is contained in:
1 parent
8796abc5f5
commit
a632bfda4a
4 files changed
+107
-77
No files matched your search
@@ -1,31 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DOTFILES_DIR="$HOME/dotfiles"
|
||||
DATE=$(date +%Y-%m-%d_%H-%M-%S)
|
||||
BACKUP_DIR="$HOME/.config-backups/$DATE"
|
||||
|
||||
backup_configs() {
|
||||
echo "📦 Создание резервной копии текущих конфигураций..."
|
||||
echo "ℹ️ Копируются только те, которые затрагиваются этим репозиторием."
|
||||
|
||||
mkdir -p "$BACKUP_DIR/.config"
|
||||
|
||||
for dir in "$DOTFILES_DIR"/Configs/.config/*; do
|
||||
name=$(basename "$dir")
|
||||
if [[ -d "$HOME/.config/$name" ]]; then
|
||||
cp -r "$HOME/.config/$name" "$BACKUP_DIR/.config/"
|
||||
fi
|
||||
done
|
||||
|
||||
for file in .zshrc .p10k.zsh .nanorc; do
|
||||
if [[ -f "$HOME/$file" ]]; then
|
||||
cp "$HOME/$file" "$BACKUP_DIR/"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "✅ Бэкап сохранён в $BACKUP_DIR"
|
||||
}
|
||||
|
||||
backup_configs
|
||||
@@ -1,26 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
DATE=$(date +%Y-%m-%d_%H-%M-%S)
|
||||
BACKUP_DIR="$HOME/.config-backups/$DATE"
|
||||
|
||||
backup_configs() {
|
||||
echo "📦 Создание полной резервной копии: $HOME/.config → $BACKUP_DIR"
|
||||
|
||||
mkdir -p "$BACKUP_DIR"
|
||||
|
||||
if command -v rsync >/dev/null 2>&1; then
|
||||
rsync -a --delete "$HOME/.config/" "$BACKUP_DIR/.config/"
|
||||
else
|
||||
cp -a "$HOME/.config" "$BACKUP_DIR"/
|
||||
fi
|
||||
|
||||
for file in .zshrc .p10k.zsh .nanorc; do
|
||||
[ -f "$HOME/$file" ] && cp "$HOME/$file" "$BACKUP_DIR/"
|
||||
done
|
||||
|
||||
echo "✅ Бэкап сохранён в $BACKUP_DIR"
|
||||
}
|
||||
|
||||
backup_configs
|
||||
+25
-2
@@ -2,8 +2,10 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Variables
|
||||
DOTFILES_DIR="$HOME/dotfiles"
|
||||
|
||||
# Colors
|
||||
RED="\033[1;31m"
|
||||
YELLOW="\033[1;33m"
|
||||
GREEN="\033[1;32m"
|
||||
@@ -11,12 +13,14 @@ CYAN="\033[1;36m"
|
||||
BLUE="\033[1;34m"
|
||||
RESET="\033[0m"
|
||||
|
||||
# Print a section header
|
||||
print_section() {
|
||||
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo -e " $1"
|
||||
echo -e "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
|
||||
}
|
||||
|
||||
# Install packages with pacman if they are not already installed
|
||||
install_pacman() {
|
||||
local to_install_pacman=()
|
||||
for pkg in "$@"; do
|
||||
@@ -35,6 +39,7 @@ install_pacman() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Install packages with yay if they are not already installed
|
||||
install_yay() {
|
||||
local to_install_yay=()
|
||||
for pkg in "$@"; do
|
||||
@@ -53,6 +58,7 @@ install_yay() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Clone or update the dotfiles repository
|
||||
clone_repo() {
|
||||
print_section "Cloning or updating dotfiles repository"
|
||||
if [ -d "$DOTFILES_DIR" ]; then
|
||||
@@ -77,6 +83,7 @@ clone_repo() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Configure pacman and update the system
|
||||
setup_pacman() {
|
||||
print_section "Configuring Pacman"
|
||||
|
||||
@@ -84,7 +91,7 @@ setup_pacman() {
|
||||
|
||||
confirm=${confirm:-Y}
|
||||
if [[ "$confirm" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
|
||||
echo -e "${BLUE}Creating a backup of /etc/pacman.conf to /etc/pacman.conf.bak${RESET}"
|
||||
echo -e "${BLUE} Creating a backup of /etc/pacman.conf to /etc/pacman.conf.bak${RESET}"
|
||||
sudo cp /etc/pacman.conf /etc/pacman.conf.bak 2>/dev/null
|
||||
|
||||
sudo cp "$DOTFILES_DIR/Configs/etc/pacman.conf" /etc/pacman.conf
|
||||
@@ -100,6 +107,7 @@ setup_pacman() {
|
||||
echo -e "${GREEN}Pacman configuration complete${RESET}"
|
||||
}
|
||||
|
||||
# Install yay if it is not already installed
|
||||
ensure_yay() {
|
||||
if ! command -v yay &>/dev/null; then
|
||||
print_section "Installing Yay"
|
||||
@@ -126,6 +134,7 @@ ensure_yay() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Setup Zsh, Oh My Zsh and plugins
|
||||
setup_zsh() {
|
||||
if [ ! -d "$HOME/.oh-my-zsh" ]; then
|
||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended || true
|
||||
@@ -138,6 +147,7 @@ setup_zsh() {
|
||||
git clone --depth=1 https://github.com/zsh-users/zsh-autosuggestions "${ZSH_CUSTOM:-$HOME/.oh-my-zsh/custom}/plugins/zsh-autosuggestions" || true
|
||||
}
|
||||
|
||||
# Backup existing configurations
|
||||
backup_configs() {
|
||||
print_section "Backing up existing configurations"
|
||||
|
||||
@@ -151,6 +161,11 @@ backup_configs() {
|
||||
for dir in "$DOTFILES_DIR"/Configs/.config/*; do
|
||||
local name
|
||||
name=$(basename "$dir")
|
||||
|
||||
if [ "$name" = "discord" ]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
if [ -d "$HOME/.config/$name" ]; then
|
||||
echo -e "${BLUE} Copying $HOME/.config/$name to $backup_dir/.config/${RESET}"
|
||||
cp -a "$HOME/.config/$name" "$backup_dir/.config/"
|
||||
@@ -178,6 +193,7 @@ backup_configs() {
|
||||
echo -e "${GREEN}Backup saved to $backup_dir${RESET}"
|
||||
}
|
||||
|
||||
# Apply new configurations from the dotfiles repository
|
||||
apply_new_configs() {
|
||||
print_section "Applying new configurations"
|
||||
|
||||
@@ -194,6 +210,7 @@ apply_new_configs() {
|
||||
echo -e "${GREEN}New configurations applied.${RESET}"
|
||||
}
|
||||
|
||||
# Run essential services
|
||||
run_services() {
|
||||
print_section "Running services"
|
||||
|
||||
@@ -221,6 +238,7 @@ run_services() {
|
||||
echo -e "${GREEN}Services started.${RESET}"
|
||||
}
|
||||
|
||||
# Download and set up wallpapers
|
||||
setup_wallpapers() {
|
||||
print_section "Wallpapers"
|
||||
|
||||
@@ -237,7 +255,7 @@ setup_wallpapers() {
|
||||
[ -z "$name" ] && continue
|
||||
|
||||
local url="https://share.rzx.ovh/raw/$name"
|
||||
echo -e "${GREEN}Downloading wallpaper:${RESET} $url"
|
||||
echo -e "${GREEN} Downloading wallpaper:${RESET} $url"
|
||||
curl --connect-timeout 5 --max-time 30 -L -s "$url" -o "$wallpaper_dest/$name" || echo -e "${RED}Failed to download wallpaper:${RESET} $name"
|
||||
done
|
||||
|
||||
@@ -249,6 +267,7 @@ setup_wallpapers() {
|
||||
echo -e "${GREEN}Wallpaper set.${RESET}"
|
||||
}
|
||||
|
||||
# Apply GTK theme
|
||||
setup_theme() {
|
||||
print_section "Applying theme"
|
||||
|
||||
@@ -259,6 +278,7 @@ setup_theme() {
|
||||
echo -e "${GREEN}Themes applied.${RESET}"
|
||||
}
|
||||
|
||||
# Reload services after theme and wallpaper changes
|
||||
reload_services() {
|
||||
print_section "Reloading services"
|
||||
|
||||
@@ -271,12 +291,15 @@ reload_services() {
|
||||
echo -e "${GREEN}Services reloaded.${RESET}"
|
||||
}
|
||||
|
||||
# Main function
|
||||
main() {
|
||||
# Check if the script is run as root
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo -e "${RED}Error: This script should not be run as root or with sudo. Please run it as a regular user.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the script is run in a Wayland session
|
||||
if [ -z "${WAYLAND_DISPLAY:-}" ]; then
|
||||
echo -e "${YELLOW}The script must be run in an active Wayland session (Hyprland).${RESET}"
|
||||
exit 1
|
||||
|
||||
+82
-18
@@ -2,30 +2,94 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
BACKUP_DIR="$HOME/.config-backups"
|
||||
# Colors
|
||||
RED="\033[1;31m"
|
||||
YELLOW="\033[1;33m"
|
||||
GREEN="\033[1;32m"
|
||||
CYAN="\033[1;36m"
|
||||
BLUE="\033[1;34m"
|
||||
RESET="\033[0m"
|
||||
|
||||
if [[ ! -d "$BACKUP_DIR" ]]; then
|
||||
echo "❌ Резервные копии не найдены: $BACKUP_DIR"
|
||||
exit 1
|
||||
fi
|
||||
# Print a section header
|
||||
print_section() {
|
||||
echo -e "${CYAN}━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
|
||||
echo -e " $1"
|
||||
echo -e "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━${RESET}"
|
||||
}
|
||||
|
||||
echo "📦 Доступные резервные копии:"
|
||||
ls -1 "$BACKUP_DIR" | sort
|
||||
# List available backups
|
||||
list_backups() {
|
||||
print_section "Available Backups"
|
||||
local backup_dir="$HOME/.config-backups"
|
||||
if [ ! -d "$backup_dir" ] || [ -z "$(ls -A "$backup_dir")" ]; then
|
||||
echo -e "${RED}No backup directories found in $backup_dir${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
read -rp "Введите имя папки для восстановления (YYYY-MM-DD_HH-MM-SS): " folder
|
||||
mapfile -t backups < <(ls -1t "$backup_dir")
|
||||
|
||||
TARGET="$BACKUP_DIR/$folder"
|
||||
for i in "${!backups[@]}"; do
|
||||
echo -e "${YELLOW}$((i + 1))) ${backups[$i]}${RESET}"
|
||||
done
|
||||
}
|
||||
|
||||
if [[ ! -d "$TARGET" ]]; then
|
||||
echo "❌ Директория '$folder' не найдена в резервных копиях"
|
||||
exit 1
|
||||
fi
|
||||
# Restore a backup from the list of available backups
|
||||
restore_backup() {
|
||||
list_backups
|
||||
|
||||
echo "♻️ Восстановление конфигураций..."
|
||||
read -rp "$(echo -e "${CYAN}Enter the number of the backup to restore: ${RESET}")" choice
|
||||
|
||||
mkdir -p "$HOME/.config"
|
||||
if ! [[ "$choice" =~ ^[0-9]+$ ]] || [ "$choice" -lt 1 ] || [ "$choice" -gt "${#backups[@]}" ]; then
|
||||
echo -e "${RED}Invalid selection.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cp -r "$TARGET/.config/." "$HOME/.config/" 2>/dev/null || true
|
||||
cp "$TARGET"/.{zshrc,p10k.zsh,nanorc} "$HOME"/ 2>/dev/null || true
|
||||
local selected_backup_dir="$HOME/.config-backups/${backups[$((choice - 1))]}"
|
||||
echo -e "${BLUE}You have selected to restore from: $selected_backup_dir${RESET}"
|
||||
|
||||
echo "✅ Конфигурации успешно восстановлены из $TARGET"
|
||||
read -rp "$(echo -e "${YELLOW}This will overwrite your current configurations. Are you sure? (Y/n): ${RESET}")" confirm
|
||||
confirm=${confirm:-Y}
|
||||
if [[ ! "$confirm" =~ ^([Yy]|[Yy][Ee][Ss])$ ]]; then
|
||||
echo -e "${YELLOW}Restore operation cancelled.${RESET}"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
print_section "Restoring configurations"
|
||||
|
||||
if [ -d "$selected_backup_dir/.config" ]; then
|
||||
echo -e "${BLUE}Restoring .config files...${RESET}"
|
||||
cp -a "$selected_backup_dir/.config/." "$HOME/.config/"
|
||||
echo -e "${GREEN}.config files restored.${RESET}"
|
||||
fi
|
||||
|
||||
local home_files=(".zshrc" ".p10k.zsh" ".nanorc")
|
||||
for file in "${home_files[@]}"; do
|
||||
if [ -f "$selected_backup_dir/$file" ]; then
|
||||
echo -e "${BLUE}Restoring $file...${RESET}"
|
||||
cp -a "$selected_backup_dir/$file" "$HOME/"
|
||||
echo -e "${GREEN}$file restored.${RESET}"
|
||||
fi
|
||||
done
|
||||
|
||||
if [ -d "$selected_backup_dir/etc" ]; then
|
||||
echo -e "${BLUE}Restoring /etc files (requires sudo)...${RESET}"
|
||||
sudo cp -a "$selected_backup_dir/etc/." /etc/
|
||||
echo -e "${GREEN}/etc files restored.${RESET}"
|
||||
fi
|
||||
|
||||
echo -e "${GREEN}Restore complete!${RESET}"
|
||||
echo -e "${CYAN}To fully apply the changes, it is recommended to restart the system.${RESET}"
|
||||
}
|
||||
|
||||
# Main function
|
||||
main() {
|
||||
# Check if the script is run as root
|
||||
if [ "$EUID" -eq 0 ]; then
|
||||
echo -e "${RED}Error: This script should not be run as root or with sudo. Please run it as a regular user.${RESET}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
restore_backup
|
||||
}
|
||||
|
||||
main "$@"
|
||||
Reference in new issue
Block a user