mirror of
https://github.com/duma799/hyprduma-config.git
synced 2026-05-13 14:11:01 +00:00
refactor: merge install.sh into install.py, use symlinks instead of copying files
This commit is contained in:
+50
-69
@@ -64,8 +64,11 @@ def print_info(msg):
|
|||||||
def ask_yn(prompt, default=True):
|
def ask_yn(prompt, default=True):
|
||||||
suffix = " [Y/n] " if default else " [y/N] "
|
suffix = " [Y/n] " if default else " [y/N] "
|
||||||
try:
|
try:
|
||||||
answer = input(f" {MAGENTA}?{RESET} {prompt}{suffix}").strip().lower()
|
with open("/dev/tty") as tty:
|
||||||
except (EOFError, KeyboardInterrupt):
|
sys.stdout.write(f" {MAGENTA}?{RESET} {prompt}{suffix}")
|
||||||
|
sys.stdout.flush()
|
||||||
|
answer = tty.readline().strip().lower()
|
||||||
|
except (OSError, KeyboardInterrupt):
|
||||||
print()
|
print()
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if not answer:
|
if not answer:
|
||||||
@@ -203,26 +206,43 @@ def install_caelestia():
|
|||||||
print_info("Caelestia will start automatically on next Hyprland session")
|
print_info("Caelestia will start automatically on next Hyprland session")
|
||||||
|
|
||||||
|
|
||||||
|
def make_symlink(src: Path, dst: Path):
|
||||||
|
"""Create symlink dst -> src, backing up any existing non-symlink at dst."""
|
||||||
|
if dst.is_symlink():
|
||||||
|
if dst.resolve() == src.resolve():
|
||||||
|
return # already correct
|
||||||
|
dst.unlink()
|
||||||
|
elif dst.exists():
|
||||||
|
backup = dst.parent / (dst.name + ".backup")
|
||||||
|
if backup.exists():
|
||||||
|
shutil.rmtree(str(backup)) if backup.is_dir() else backup.unlink()
|
||||||
|
shutil.move(str(dst), str(backup))
|
||||||
|
print_warn(f"Backed up {dst} -> {backup}")
|
||||||
|
dst.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
dst.symlink_to(src)
|
||||||
|
|
||||||
|
|
||||||
def clone_repo():
|
def clone_repo():
|
||||||
repo_dir = find_repo_dir()
|
repo_dir = find_repo_dir()
|
||||||
if repo_dir:
|
if repo_dir:
|
||||||
print_ok(f"Using repo at: {repo_dir}")
|
print_ok(f"Using repo at: {repo_dir}")
|
||||||
return repo_dir
|
return repo_dir
|
||||||
|
|
||||||
clone_target = Path.home() / "Downloads" / "hyprduma-config"
|
clone_target = Path.home() / "hyprduma-config"
|
||||||
print_info(f"Cloning to {clone_target}")
|
print_info(f"Cloning to {clone_target}")
|
||||||
|
|
||||||
if clone_target.exists():
|
if clone_target.exists():
|
||||||
if ask_yn(f"{clone_target} already exists. Remove and re-clone?"):
|
if (clone_target / "hyprland.conf").exists():
|
||||||
|
print_ok("Repo already exists, using it")
|
||||||
|
return clone_target
|
||||||
|
if ask_yn(f"{clone_target} exists but looks wrong. Remove and re-clone?"):
|
||||||
shutil.rmtree(clone_target)
|
shutil.rmtree(clone_target)
|
||||||
else:
|
else:
|
||||||
if (clone_target / "hyprland.conf").exists():
|
print_err("Cannot proceed without a valid repo directory")
|
||||||
return clone_target
|
|
||||||
print_err("Directory exists but doesn't contain config files")
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if run(f"git clone {REPO_URL} {clone_target}"):
|
if run(f"git clone {REPO_URL} {clone_target}"):
|
||||||
print_ok("Repository cloned")
|
print_ok(f"Repository cloned to {clone_target}")
|
||||||
return clone_target
|
return clone_target
|
||||||
else:
|
else:
|
||||||
print_err("Failed to clone repository")
|
print_err("Failed to clone repository")
|
||||||
@@ -230,44 +250,25 @@ def clone_repo():
|
|||||||
|
|
||||||
|
|
||||||
def backup_configs():
|
def backup_configs():
|
||||||
config = Path.home() / ".config"
|
# Backups are now handled per-item in make_symlink; this step is a no-op.
|
||||||
backed_up = []
|
print_ok("Backups handled automatically during symlinking")
|
||||||
|
|
||||||
for name in ["hypr", "waybar", "wlogout", "waypaper", "nvim", "fastfetch"]:
|
|
||||||
src = config / name
|
|
||||||
dst = config / f"{name}.backup"
|
|
||||||
if src.exists() and not src.is_symlink():
|
|
||||||
if dst.exists():
|
|
||||||
print_warn(f"{dst} already exists - skipping backup of {name}")
|
|
||||||
continue
|
|
||||||
shutil.move(str(src), str(dst))
|
|
||||||
backed_up.append(name)
|
|
||||||
|
|
||||||
if backed_up:
|
|
||||||
print_ok(f"Backed up: {', '.join(f'~/.config/{n}' for n in backed_up)}")
|
|
||||||
else:
|
|
||||||
print_ok("No existing configs to back up")
|
|
||||||
|
|
||||||
|
|
||||||
def install_hypr_config(repo):
|
def install_hypr_config(repo):
|
||||||
hypr_dir = Path.home() / ".config" / "hypr"
|
hypr_dir = Path.home() / ".config" / "hypr"
|
||||||
hypr_dir.mkdir(parents=True, exist_ok=True)
|
hypr_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
shutil.copy2(repo / "hyprland.conf", hypr_dir / "hyprland.conf")
|
make_symlink(repo / "hyprland.conf", hypr_dir / "hyprland.conf")
|
||||||
print_ok("Copied hyprland.conf")
|
print_ok("Symlinked hyprland.conf")
|
||||||
|
|
||||||
screenshots = Path.home() / "Pictures" / "Screenshots"
|
screenshots = Path.home() / "Pictures" / "Screenshots"
|
||||||
screenshots.mkdir(parents=True, exist_ok=True)
|
screenshots.mkdir(parents=True, exist_ok=True)
|
||||||
print_ok(f"Created {screenshots}")
|
print_ok(f"Created {screenshots}")
|
||||||
|
|
||||||
wallpapers_src = repo / "wallpapers"
|
wallpapers_src = repo / "wallpapers"
|
||||||
wallpapers_dst = Path.home() / "wallpapers"
|
|
||||||
if wallpapers_src.exists():
|
if wallpapers_src.exists():
|
||||||
if wallpapers_dst.exists():
|
make_symlink(wallpapers_src, Path.home() / "wallpapers")
|
||||||
shutil.rmtree(wallpapers_dst)
|
print_ok("Symlinked ~/wallpapers/ -> repo/wallpapers/")
|
||||||
shutil.copytree(str(wallpapers_src), str(wallpapers_dst))
|
|
||||||
count = len(list(wallpapers_dst.iterdir()))
|
|
||||||
print_ok(f"Copied {count} wallpapers to ~/wallpapers/")
|
|
||||||
|
|
||||||
|
|
||||||
def install_pywal(repo):
|
def install_pywal(repo):
|
||||||
@@ -276,31 +277,20 @@ def install_pywal(repo):
|
|||||||
hypr_dir.mkdir(parents=True, exist_ok=True)
|
hypr_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
# Pywal templates
|
# Pywal templates
|
||||||
templates_dst = home / ".config" / "wal" / "templates"
|
|
||||||
templates_dst.mkdir(parents=True, exist_ok=True)
|
|
||||||
templates_src = repo / "config" / "wal" / "templates"
|
templates_src = repo / "config" / "wal" / "templates"
|
||||||
if templates_src.exists():
|
if templates_src.exists():
|
||||||
for f in templates_src.iterdir():
|
(home / ".config" / "wal").mkdir(parents=True, exist_ok=True)
|
||||||
shutil.copy2(str(f), str(templates_dst / f.name))
|
make_symlink(templates_src, home / ".config" / "wal" / "templates")
|
||||||
print_ok("Installed pywal templates")
|
print_ok("Symlinked pywal templates")
|
||||||
else:
|
else:
|
||||||
print_err("config/wal/templates not found in repo")
|
print_err("config/wal/templates not found in repo")
|
||||||
|
|
||||||
# Scripts
|
# Scripts
|
||||||
|
scripts_src = repo / "scripts"
|
||||||
scripts_dir = hypr_dir / "scripts"
|
scripts_dir = hypr_dir / "scripts"
|
||||||
scripts_dir.mkdir(parents=True, exist_ok=True)
|
if scripts_src.exists():
|
||||||
for script in [
|
make_symlink(scripts_src, scripts_dir)
|
||||||
"pywal.sh",
|
print_ok("Symlinked scripts -> ~/.config/hypr/scripts/")
|
||||||
"sync-caelestia-wallpaper.sh",
|
|
||||||
"waypaper-hook.sh",
|
|
||||||
"monitor-handler.py",
|
|
||||||
]:
|
|
||||||
src = repo / "scripts" / script
|
|
||||||
dst = scripts_dir / script
|
|
||||||
if src.exists():
|
|
||||||
shutil.copy2(str(src), str(dst))
|
|
||||||
dst.chmod(0o755)
|
|
||||||
print_ok("Copied scripts to ~/.config/hypr/scripts/")
|
|
||||||
|
|
||||||
# Waypaper hook
|
# Waypaper hook
|
||||||
hook_cmd = str(scripts_dir / "waypaper-hook.sh")
|
hook_cmd = str(scripts_dir / "waypaper-hook.sh")
|
||||||
@@ -336,12 +326,10 @@ def install_pywal(repo):
|
|||||||
# pywal.sh is already in ~/.config/hypr/scripts/pywal.sh
|
# pywal.sh is already in ~/.config/hypr/scripts/pywal.sh
|
||||||
|
|
||||||
# Kitty
|
# Kitty
|
||||||
kitty_dir = home / ".config" / "kitty"
|
kitty_src = repo / "config" / "kitty"
|
||||||
kitty_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
kitty_src = repo / "config" / "kitty" / "kitty.conf"
|
|
||||||
if kitty_src.exists():
|
if kitty_src.exists():
|
||||||
shutil.copy2(str(kitty_src), kitty_dir / "kitty.conf")
|
make_symlink(kitty_src, home / ".config" / "kitty")
|
||||||
print_ok("Installed kitty config with pywal colors")
|
print_ok("Symlinked kitty config")
|
||||||
|
|
||||||
# Bashrc
|
# Bashrc
|
||||||
bashrc = home / ".bashrc"
|
bashrc = home / ".bashrc"
|
||||||
@@ -413,13 +401,10 @@ def install_fastfetch_config(repo):
|
|||||||
print_warn("Skipping fastfetch config")
|
print_warn("Skipping fastfetch config")
|
||||||
return
|
return
|
||||||
|
|
||||||
fastfetch_dst = home / ".config" / "fastfetch"
|
make_symlink(fastfetch_src, home / ".config" / "fastfetch")
|
||||||
if fastfetch_dst.exists():
|
|
||||||
shutil.rmtree(str(fastfetch_dst))
|
|
||||||
shutil.copytree(str(fastfetch_src), str(fastfetch_dst))
|
|
||||||
|
|
||||||
# Fix hardcoded home path
|
# Fix hardcoded home path in the repo file if needed
|
||||||
config_file = fastfetch_dst / "config.jsonc"
|
config_file = fastfetch_src / "config.jsonc"
|
||||||
if config_file.exists():
|
if config_file.exists():
|
||||||
content = config_file.read_text()
|
content = config_file.read_text()
|
||||||
fixed = content.replace("/home/duma/", str(home) + "/")
|
fixed = content.replace("/home/duma/", str(home) + "/")
|
||||||
@@ -427,7 +412,7 @@ def install_fastfetch_config(repo):
|
|||||||
config_file.write_text(fixed)
|
config_file.write_text(fixed)
|
||||||
print_ok("Fixed fastfetch config paths for current user")
|
print_ok("Fixed fastfetch config paths for current user")
|
||||||
|
|
||||||
print_ok("Installed fastfetch config to ~/.config/fastfetch/")
|
print_ok("Symlinked fastfetch config -> ~/.config/fastfetch/")
|
||||||
|
|
||||||
|
|
||||||
def install_nvim_config(repo):
|
def install_nvim_config(repo):
|
||||||
@@ -442,12 +427,8 @@ def install_nvim_config(repo):
|
|||||||
print_warn("Skipping Neovim config")
|
print_warn("Skipping Neovim config")
|
||||||
return
|
return
|
||||||
|
|
||||||
nvim_dst = home / ".config" / "nvim"
|
make_symlink(nvim_src, home / ".config" / "nvim")
|
||||||
if nvim_dst.exists():
|
print_ok("Symlinked Neovim config -> ~/.config/nvim/")
|
||||||
shutil.rmtree(str(nvim_dst))
|
|
||||||
shutil.copytree(str(nvim_src), str(nvim_dst))
|
|
||||||
|
|
||||||
print_ok("Installed Neovim config to ~/.config/nvim/")
|
|
||||||
|
|
||||||
|
|
||||||
def print_banner():
|
def print_banner():
|
||||||
|
|||||||
-25
@@ -1,25 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
|
|
||||||
set -e
|
|
||||||
|
|
||||||
REPO="https://github.com/duma799/hyprduma-config.git"
|
|
||||||
TMPDIR=$(mktemp -d)
|
|
||||||
trap 'rm -rf "$TMPDIR"' EXIT
|
|
||||||
|
|
||||||
echo -e "\033[36m=> Downloading HyprDuma config...\033[0m"
|
|
||||||
|
|
||||||
if ! command -v git &>/dev/null; then
|
|
||||||
echo -e "\033[31mError: git is not installed. Run: sudo pacman -S git\033[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! command -v python3 &>/dev/null; then
|
|
||||||
echo -e "\033[31mError: python3 is not installed. Run: sudo pacman -S python\033[0m"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
git clone --depth 1 "$REPO" "$TMPDIR/hyprduma-config" 2>/dev/null
|
|
||||||
|
|
||||||
echo -e "\033[36m=> Launching installer...\033[0m\n"
|
|
||||||
|
|
||||||
python3 "$TMPDIR/hyprduma-config/install.py" </dev/tty
|
|
||||||
Reference in New Issue
Block a user