diff --git a/.config/fish/config.fish b/.config/fish/config.fish index 8287482..228f89e 100644 --- a/.config/fish/config.fish +++ b/.config/fish/config.fish @@ -38,7 +38,7 @@ # DOTFILES_DIR holds the template files; DOTFILES_BACKUP_DIR holds backups # and the last-update-check timestamp. -set -g DOTFILES_VERSION "1.0.2" +set -g DOTFILES_VERSION "1.0.3" # --- Remote repository (set this to enable auto-updates) -------------------- # Example: diff --git a/.config/fish/functions/dotfiles.fish b/.config/fish/functions/dotfiles.fish index 7ceb88c..fc3f1ec 100644 --- a/.config/fish/functions/dotfiles.fish +++ b/.config/fish/functions/dotfiles.fish @@ -61,7 +61,7 @@ function dotfiles -d "Manage dotfiles and self-update system" dotfiles_version case status - dotfiles_status + dotfiles_status $argv[2..] case init # `dotfiles init` → init all diff --git a/install.fish b/install.fish index b60e225..8d401ad 100644 --- a/install.fish +++ b/install.fish @@ -9,11 +9,14 @@ # # What this script does: # 1. Checks prerequisites: Fish shell, Git, and a few common tools -# 2. Clones the dotfiles repository (default: git@gitssh.toomuchtaco.net:taco/dots.git) +# 2. Tries SSH clone (git@gitssh.toomuchtaco.net:taco/dots.git); falls back +# to HTTPS (https://git.toomuchtaco.net/taco/dots.git) and rewrites the +# remote origin to SSH so future pushes use the right URL # 3. Replaces or updates ~/.config/fish/ with the contents of the repo # 4. Sources the new config and runs `dotfiles init` to install templates # (~/.tmux.conf, ~/.gitconfig, ~/.config/starship.toml, etc.) -# 5. Prints next steps +# 5. Warns if SSH key is needed and points to the gitea_key helper +# 6. Prints next steps # # You can pass a custom repo URL as the first argument: # @@ -25,10 +28,12 @@ # Configuration # ────────────────────────────────────────────────────────────────────────────── -# Default repository URL (overridable via first argument). -set -l REPO_URL "git@gitssh.toomuchtaco.net:taco/dots.git" +# Default repository URLs (overridable via first argument). +set -l SSH_REPO "git@gitssh.toomuchtaco.net:taco/dots.git" +set -l HTTPS_REPO "https://git.toomuchtaco.net/taco/dots.git" if set -q argv[1] - set REPO_URL "$argv[1]" + set SSH_REPO "$argv[1]" + set HTTPS_REPO "$argv[1]" end set -l REPO_BRANCH "main" @@ -93,31 +98,33 @@ end # 2. Fetch the repository # ────────────────────────────────────────────────────────────────────────────── -_step "2/5" "Fetching dotfiles from $REPO_URL ..." +_step "2/5" "Fetching dotfiles ..." set -l tmpdir (mktemp -d) +set -l CLONED_SSH 0 -if command git clone --branch "$REPO_BRANCH" "$REPO_URL" "$tmpdir" 2>/dev/null - echo "$GRN ✓$RST Repository cloned." +# Try SSH first (private repo, full read/write access). +echo " Trying SSH: $SSH_REPO" +if command git clone --branch "$REPO_BRANCH" "$SSH_REPO" "$tmpdir" + echo "$GRN ✓$RST Repository cloned via SSH." + set CLONED_SSH 1 else - # Clone failed — the repo might not exist yet, or this is a first install. - # Print the error and let the user decide. - echo "$YLW ⚠ Clone failed.$RST" - echo " This might mean:" - echo " - The repository doesn't exist yet" - echo " - SSH key is not loaded (ssh-add -l)" - echo " - No network access" + echo "$YLW ⚠ SSH clone failed.$RST" + echo " (SSH key may not be loaded — this is expected on first install)" echo "" - echo " Attempting alternative clone (HTTPS fallback) ..." - # Try HTTPS fallback. - set -l https_url (string replace "git@gitssh.toomuchtaco.net:" "https://git.toomuchtaco.net/" "$REPO_URL" | string replace ".git" "") - if command git clone --branch "$REPO_BRANCH" "$https_url" "$tmpdir" 2>/dev/null + # Fall back to HTTPS (public read-only access). + echo " Trying HTTPS: $HTTPS_REPO" + if command git clone --branch "$REPO_BRANCH" "$HTTPS_REPO" "$tmpdir" echo "$GRN ✓$RST Repository cloned via HTTPS." + echo "" + echo " Switching remote origin to SSH path for future pushes ..." + command git -C "$tmpdir" remote set-url origin "$SSH_REPO" + echo "$GRN ✓$RST Remote origin updated to: $SSH_REPO" else echo "$RED ERROR: All clone methods failed.$RST" echo " Manually clone the repo and re-run this script:" - echo " git clone $REPO_URL $FISH_CONFIG_DIR" + echo " git clone $SSH_REPO $FISH_CONFIG_DIR" command rm -rf "$tmpdir" exit 1 end @@ -173,9 +180,9 @@ if test -f "$FISH_CONFIG_DIR/functions/dotfiles.fish" source "$FISH_CONFIG_DIR/functions/dotfiles.fish" end -# Persist the repo URL so `dotfiles publish` and `dotfiles sync` work. -if test -n "$REPO_URL" - dotfiles repo "$REPO_URL" 2>/dev/null +# Persist the SSH repo URL so `dotfiles publish` and `dotfiles sync` work. +if test -n "$SSH_REPO" + dotfiles repo "$SSH_REPO" 2>/dev/null end # Run init for every managed template. @@ -205,12 +212,28 @@ echo "$BOLD━━━━━━━━━━━━━━━━━━━━━━━ echo "" echo " $YLW""Next steps:$RST" echo "" -echo " 1. Start a new fish shell or run: exec fish" -echo " 2. Check status of managed files: dotfiles status" -echo " 3. Edit a dotfile: dotfiles edit tmux" -echo " 4. Pull remote updates: dotfiles sync" -echo " 5. Push your changes: dotfiles publish" +echo " $(set_color green)1.$RST Start a new fish shell: exec fish" +echo " $(set_color green)2.$RST Check managed files: dotfiles status" +echo " $(set_color green)3.$RST Edit a dotfile: dotfiles edit tmux" +echo " $(set_color green)4.$RST Pull remote updates: dotfiles sync" +echo " $(set_color green)5.$RST Push your changes: dotfiles publish" echo "" + +# If we fell back to HTTPS, SSH auth isn't set up yet. +if test "$CLONED_SSH" -eq 0 + echo " $YLW""⚠ SSH key required for push access$RST" + echo "" + echo " To push changes, you need an SSH key set up for Gitea." + echo " Run this built-in helper to generate one and configure SSH:" + echo "" + echo " $(set_color --bold)gitea_key$RST" + echo "" + echo " It will create ~/.ssh/id_ed25519_gitea, update ~/.ssh/config," + echo " and print the public key for you to add at:" + echo " $(set_color cyan)https://git.toomuchtaco.net/user/settings/keys$RST" + echo "" +end + echo " $YLW""New to the dotfiles system?$RST" echo " dotfiles help" echo ""