fix: bootstrap deps and key handling
This commit is contained in:
parent
7716ba810f
commit
8fd797bf3c
68
bootstrap.sh
68
bootstrap.sh
@ -57,7 +57,7 @@ readonly RAW_BASE="https://gitea.nevim42.cz/nevim42/engram-boot/raw/branch/main"
|
|||||||
readonly ENGRAM_REPO="git@gitea.nevim42.cz:nevim42/engram.git"
|
readonly ENGRAM_REPO="git@gitea.nevim42.cz:nevim42/engram.git"
|
||||||
readonly ENGRAM_DIR="$HOME/Repositories/engram"
|
readonly ENGRAM_DIR="$HOME/Repositories/engram"
|
||||||
readonly KNOWN_HOST="gitea.nevim42.cz"
|
readonly KNOWN_HOST="gitea.nevim42.cz"
|
||||||
readonly DEPS=(age git gnupg)
|
readonly DEPS=(age git gnupg openssh)
|
||||||
|
|
||||||
WORK=""
|
WORK=""
|
||||||
CHOSEN_KEYS=()
|
CHOSEN_KEYS=()
|
||||||
@ -135,31 +135,49 @@ install_keys() {
|
|||||||
|
|
||||||
local available=()
|
local available=()
|
||||||
mapfile -t available < <(find "$WORK/plain/ssh" -maxdepth 1 -type f \
|
mapfile -t available < <(find "$WORK/plain/ssh" -maxdepth 1 -type f \
|
||||||
! -name '*.pub' ! -name 'known_hosts*' -printf '%f\n' | sort)
|
! -name '.*' ! -name '*.pub' ! -name 'known_hosts*' -printf '%f\n' | sort)
|
||||||
|
|
||||||
if (( ${#available[@]} == 0 )); then
|
if (( ${#available[@]} == 0 )); then
|
||||||
die "No SSH keys found in the bundle."
|
die "No SSH keys found in the bundle."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
info "Available keys: ${available[*]}"
|
info "Available keys:"
|
||||||
local answer
|
local i
|
||||||
read -rp " Install which keys? (space separated, empty = none): " answer
|
for i in "${!available[@]}"; do
|
||||||
read -ra CHOSEN_KEYS <<< "$answer"
|
printf ' %d) %s\n' "$((i + 1))" "${available[$i]}"
|
||||||
|
done
|
||||||
|
|
||||||
local name
|
local answer
|
||||||
for name in "${CHOSEN_KEYS[@]}"; do
|
read -rp " Which keys? (numbers, first one becomes id_ed25519, empty = none): " answer
|
||||||
if [[ ! -f "$WORK/plain/ssh/$name" ]]; then
|
|
||||||
die "Unknown key: $name"
|
local num n name target
|
||||||
|
n=0
|
||||||
|
for num in $answer; do
|
||||||
|
if [[ ! $num =~ ^[0-9]+$ ]] || (( num < 1 || num > ${#available[@]} )); then
|
||||||
|
die "Not a valid key number: $num"
|
||||||
fi
|
fi
|
||||||
if [[ -e "$HOME/.ssh/$name" ]]; then
|
|
||||||
warn "$name already exists in ~/.ssh - skipping"
|
name="${available[$((num - 1))]}"
|
||||||
|
n=$((n + 1))
|
||||||
|
|
||||||
|
# The first chosen key becomes the standard default identity,
|
||||||
|
# anything after that keeps its own name.
|
||||||
|
if (( n == 1 )); then
|
||||||
|
target="id_ed25519"
|
||||||
|
else
|
||||||
|
target="$name"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [[ -e "$HOME/.ssh/$target" ]]; then
|
||||||
|
warn "$target already exists in ~/.ssh - skipping"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
install -m 600 "$WORK/plain/ssh/$name" "$HOME/.ssh/$name"
|
install -m 600 "$WORK/plain/ssh/$name" "$HOME/.ssh/$target"
|
||||||
if [[ -f "$WORK/plain/ssh/$name.pub" ]]; then
|
if [[ -f "$WORK/plain/ssh/$name.pub" ]]; then
|
||||||
install -m 644 "$WORK/plain/ssh/$name.pub" "$HOME/.ssh/$name.pub"
|
install -m 644 "$WORK/plain/ssh/$name.pub" "$HOME/.ssh/$target.pub"
|
||||||
fi
|
fi
|
||||||
info "Installed $HOME/.ssh/$name"
|
CHOSEN_KEYS+=("$name")
|
||||||
|
info "Installed $name as ~/.ssh/$target"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -216,25 +234,17 @@ clone_engram() {
|
|||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if (( ${#CHOSEN_KEYS[@]} == 0 )); then
|
if [[ ! -f "$HOME/.ssh/id_ed25519" ]]; then
|
||||||
warn "No SSH key was installed - cannot clone."
|
warn "No default key (~/.ssh/id_ed25519) - cannot clone."
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
mkdir -p "$(dirname "$ENGRAM_DIR")"
|
mkdir -p "$(dirname "$ENGRAM_DIR")"
|
||||||
|
if ! git clone "$ENGRAM_REPO" "$ENGRAM_DIR"; then
|
||||||
local key
|
|
||||||
for key in "${CHOSEN_KEYS[@]}"; do
|
|
||||||
info "Trying key: $key"
|
|
||||||
if GIT_SSH_COMMAND="ssh -o IdentitiesOnly=yes -i $HOME/.ssh/$key" \
|
|
||||||
git clone "$ENGRAM_REPO" "$ENGRAM_DIR"; then
|
|
||||||
info "Cloned into $ENGRAM_DIR (key: $key)"
|
|
||||||
return
|
|
||||||
fi
|
|
||||||
rm -rf "$ENGRAM_DIR"
|
rm -rf "$ENGRAM_DIR"
|
||||||
done
|
die "Clone failed - is the deploy key set up on gitea?"
|
||||||
|
fi
|
||||||
die "Clone failed with every key - check the deploy key setup on gitea."
|
info "Cloned into $ENGRAM_DIR"
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---------------------------------------------------------------------------
|
# ---------------------------------------------------------------------------
|
||||||
|
|||||||
@ -9,7 +9,8 @@ master key to all of it, so keep it outside this repo.
|
|||||||
|
|
||||||
- `ssh/nevim42-desktop`, `ssh/nevim42-mikoshi`, ... - SSH private keys named
|
- `ssh/nevim42-desktop`, `ssh/nevim42-mikoshi`, ... - SSH private keys named
|
||||||
after machines (+ their `.pub`; `nevim42-mikoshi.pub` is registered as a
|
after machines (+ their `.pub`; `nevim42-mikoshi.pub` is registered as a
|
||||||
read-only deploy key on the engram repo)
|
read-only deploy key on the engram repo). The bootstrap installs your first
|
||||||
|
chosen key as the standard `~/.ssh/id_ed25519`.
|
||||||
- `ssh/known_hosts.gitea` - pinned gitea host key, no TOFU on first connect
|
- `ssh/known_hosts.gitea` - pinned gitea host key, no TOFU on first connect
|
||||||
- `gpg/nevim42.asc` - armored export of the GPG secret key
|
- `gpg/nevim42.asc` - armored export of the GPG secret key
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user