From 6c095843ba1e6b4bd894b5326e7f2b253ace708b Mon Sep 17 00:00:00 2001 From: Menno van Leeuwen Date: Mon, 10 Mar 2025 15:59:28 +0100 Subject: [PATCH] feat: remove WSL-specific aliases and 1Password agent bridge script; add dependency checks and installation for Python packages --- .bashrc | 8 ------ bin/1password-agent-bridge.sh | 21 -------------- bin/actions/secrets.py | 11 +------ bin/helpers/functions.py | 40 ++++++++++++++++++++++++++ config/ansible/tasks/global/global.yml | 3 ++ 5 files changed, 44 insertions(+), 39 deletions(-) delete mode 100755 bin/1password-agent-bridge.sh diff --git a/.bashrc b/.bashrc index 5428e1f..5ecfc1b 100644 --- a/.bashrc +++ b/.bashrc @@ -67,11 +67,6 @@ if [ -t 1 ]; then alias ls='l' fi -# Alias for ssh.exe and ssh-add.exe on Windows WSL (microsoft-standard-WSL2) -if [[ $(uname -a) == *"microsoft-standard-WSL2"* ]]; then - alias op='op.exe' -fi - # PATH Manipulation export DOTFILES_PATH=$HOME/.dotfiles export PATH=$PATH:$HOME/.local/bin @@ -118,9 +113,6 @@ if [ -f "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" ]; then . "$HOME/.nix-profile/etc/profile.d/hm-session-vars.sh" fi -# Source agent-bridge script for 1password -source $DOTFILES_PATH/bin/1password-agent-bridge.sh - # zoxide if available if command -v zoxide &> /dev/null; then eval "$(zoxide init bash)" diff --git a/bin/1password-agent-bridge.sh b/bin/1password-agent-bridge.sh deleted file mode 100755 index fa203cb..0000000 --- a/bin/1password-agent-bridge.sh +++ /dev/null @@ -1,21 +0,0 @@ -source $DOTFILES_PATH/bin/helpers/functions.sh -export SSH_AUTH_SOCK=$HOME/.1password/agent.sock - -# Check if is_wsl function returns true, don't continue if we are not on WSL -if ! is_wsl; then - return -fi - -printfe "%s" "cyan" "Running in WSL, ensuring 1Password SSH-Agent relay is running..." -ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?) -if [[ $ALREADY_RUNNING != "0" ]]; then - if [[ -S $SSH_AUTH_SOCK ]]; then - rm $SSH_AUTH_SOCK - fi - - (setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) >/dev/null 2>&1 - printfe "%s\n" "green" " [ Started ]" - exit 0 -fi - -printfe "%s\n" "green" " [ Already running ]" diff --git a/bin/actions/secrets.py b/bin/actions/secrets.py index 819a1ad..05a9186 100755 --- a/bin/actions/secrets.py +++ b/bin/actions/secrets.py @@ -10,18 +10,9 @@ import glob sys.path.append(os.path.join(os.path.expanduser("~/.dotfiles"), "bin")) from helpers.functions import printfe, run_command -def is_wsl(): - """Check if running under WSL""" - try: - with open('/proc/version', 'r') as f: - return 'microsoft' in f.read().lower() - except: - return False - def get_password(): """Get password from 1Password""" - # Choose the appropriate op command based on WSL status - op_cmd = "op.exe" if is_wsl() else "op" + op_cmd = "op" # Try to get the password success, output = run_command([op_cmd, "item", "get", "Dotfiles Secrets", "--fields", "password"]) diff --git a/bin/helpers/functions.py b/bin/helpers/functions.py index 89bdef9..d621bef 100644 --- a/bin/helpers/functions.py +++ b/bin/helpers/functions.py @@ -95,3 +95,43 @@ def run_command(command, shell=False): return True, result.stdout.strip() except subprocess.CalledProcessError as e: return False, e.stderr.strip() + +def ensure_dependencies(): + """Check and install required dependencies for the dotfiles system""" + required_packages = [ + 'pyfiglet', # For ASCII art generation + ] + + missing_packages = [] + for package in required_packages: + try: + __import__(package) + except ImportError: + missing_packages.append(package) + + if missing_packages: + printfe("yellow", f"Missing dependencies: {', '.join(missing_packages)}") + install = input("Would you like to install them now? (y/n): ").lower() + if install == 'y' or install == 'yes': + printfe("cyan", "Installing missing dependencies...") + for package in missing_packages: + printfe("blue", f"Installing {package}...") + success, output = run_command(['pip', 'install', '--user', package]) + if success: + printfe("green", f"Successfully installed {package}") + # Attempt to import the newly installed package + if package == 'pyfiglet': + try: + global pyfiglet + import pyfiglet + except ImportError: + printfe("red", f"Failed to import {package} after installation") + else: + printfe("red", f"Failed to install {package}: {output}") + + printfe("green", "All dependencies have been processed") + return True + else: + printfe("yellow", "Skipping dependency installation") + return False + return True diff --git a/config/ansible/tasks/global/global.yml b/config/ansible/tasks/global/global.yml index 873b53e..05350c0 100644 --- a/config/ansible/tasks/global/global.yml +++ b/config/ansible/tasks/global/global.yml @@ -31,6 +31,9 @@ - trash-cli - curl - wget + - python3 + - python3-pip + - python3-venv state: present become: true