|
1 | 1 | #!/usr/bin/env bash |
2 | 2 | set -euo pipefail |
| 3 | +trap 'echo "Error on line $LINENO"; exit 1' ERR |
3 | 4 |
|
4 | | -#----------------- Repo Configuration -----------------# |
| 5 | +#----------------- Configurable Parameters -----------------# |
5 | 6 | REPO_URL="https://github.com/ygweygyigyigyigerig/Mine_Hyprland_dots.git" |
6 | 7 | INSTALL_DIR="$HOME/.local/share/Mine_Hyprland_dots" |
7 | 8 | DOTFILES_DIR="$INSTALL_DIR/DOTFILES/.config" |
8 | | - |
9 | | -#----------------- Clone or Update Repository -----------------# |
10 | | -if [[ ! -d "$INSTALL_DIR" ]]; then |
11 | | - echo "Cloning repository into $INSTALL_DIR..." |
12 | | - git clone "$REPO_URL" "$INSTALL_DIR" |
13 | | -else |
14 | | - echo "Repository already exists. Checking for updates..." |
15 | | - cd "$INSTALL_DIR" |
16 | | - git pull origin install-script # Replace 'install-script' with the correct branch name if needed |
| 9 | +BRANCH="${1:-main}" # pass branch/tag as first argument, defaults to 'main' |
| 10 | + |
| 11 | +#----------------- Remove Existing Repo Safely -----------------# |
| 12 | +if [[ -d "$INSTALL_DIR" ]]; then |
| 13 | + echo "Found existing repo at $INSTALL_DIR." |
| 14 | + read -p "Delete and re‑clone? [y/N] " yn |
| 15 | + if [[ "$yn" =~ ^[Yy]$ ]]; then |
| 16 | + # safety check on INSTALL_DIR |
| 17 | + if [[ "$INSTALL_DIR" == "$HOME/.local/share/Mine_Hyprland_dots" ]]; then |
| 18 | + echo "Deleting $INSTALL_DIR..." |
| 19 | + rm -rf "$INSTALL_DIR" |
| 20 | + else |
| 21 | + echo "Refusing to delete unexpected path: $INSTALL_DIR" >&2 |
| 22 | + exit 1 |
| 23 | + fi |
| 24 | + else |
| 25 | + echo "Skipping delete; will exit to avoid stale repo." && exit 0 |
| 26 | + fi |
17 | 27 | fi |
18 | 28 |
|
19 | | -#----------------- Directory Creation -----------------# |
20 | | -echo "Creating necessary directories in $HOME/.config" |
| 29 | +#----------------- Clone Repository -----------------# |
| 30 | +echo "Cloning '$BRANCH' from $REPO_URL into $INSTALL_DIR..." |
| 31 | +git clone --depth 1 --branch "$BRANCH" "$REPO_URL" "$INSTALL_DIR" |
21 | 32 |
|
22 | | -# List of directories to create based on your repo structure |
23 | | -declare -a dirs=("hypr" "waybar" "swaync" "rofi" "scripts") |
| 33 | +#----------------- Validate DOTFILES -----------------# |
| 34 | +if [[ ! -d "$DOTFILES_DIR" ]]; then |
| 35 | + echo "Error: DOTFILES directory not found at $DOTFILES_DIR" >&2 |
| 36 | + exit 1 |
| 37 | +fi |
24 | 38 |
|
| 39 | +#----------------- Directory Creation -----------------# |
| 40 | +echo "Ensuring ~/.config subdirectories exist..." |
| 41 | +declare -a dirs=(hypr waybar swaync rofi scripts) |
25 | 42 | for dir in "${dirs[@]}"; do |
26 | | - DEST_DIR="$HOME/.config/$dir" |
27 | | - |
28 | | - # Create the directory if it doesn't exist |
29 | | - if [[ ! -d "$DEST_DIR" ]]; then |
30 | | - echo "Creating directory: $DEST_DIR" |
31 | | - mkdir -p "$DEST_DIR" |
32 | | - else |
33 | | - echo "Directory $DEST_DIR already exists." |
34 | | - fi |
| 43 | + mkdir -pv "$HOME/.config/$dir" |
35 | 44 | done |
36 | 45 |
|
37 | | -#----------------- Copy Files -----------------# |
38 | | -echo "Copying files from $DOTFILES_DIR to ~/.config..." |
39 | | - |
40 | | -# For each directory in the repository, copy files into corresponding directories |
| 46 | +#----------------- Sync Files with rsync -----------------# |
| 47 | +echo "Syncing dotfiles into ~/.config..." |
41 | 48 | for dir in "${dirs[@]}"; do |
42 | | - SRC_DIR="$DOTFILES_DIR/$dir" |
43 | | - DEST_DIR="$HOME/.config/$dir" |
44 | | - |
45 | | - if [[ -d "$SRC_DIR" ]]; then |
46 | | - echo "Copying contents of $SRC_DIR to $DEST_DIR..." |
47 | | - cp -r "$SRC_DIR"/. "$DEST_DIR"/ |
| 49 | + SRC="$DOTFILES_DIR/$dir/" |
| 50 | + DEST="$HOME/.config/$dir/" |
| 51 | + if [[ -d "$SRC" ]]; then |
| 52 | + echo " → rsync $SRC → $DEST" |
| 53 | + rsync -a --delete "$SRC" "$DEST" |
48 | 54 | else |
49 | | - echo "Warning: Directory $SRC_DIR does not exist in the repository!" |
| 55 | + echo "Warning: $SRC does not exist in repo; skipping." |
50 | 56 | fi |
51 | 57 | done |
52 | 58 |
|
53 | | -#----------------- Final Messages -----------------# |
54 | | -echo "Installation and update completed. All directories and files are now in place." |
55 | | -echo "Please verify the contents of ~/.config and adjust if necessary." |
| 59 | +#----------------- Final Message -----------------# |
| 60 | +echo "✅ Installation complete!" |
| 61 | +echo "Review ~/.config for any manual tweaks if needed." |
0 commit comments