Compare commits

..

No commits in common. "8fd797bf3c4cde903ed86485470fc84f268ee6bf" and "a45f2eacd498316f74e7bd8c780f06b33fe0b5e8" have entirely different histories.

3 changed files with 31 additions and 68 deletions

View File

@ -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 openssh) readonly DEPS=(age git gnupg)
WORK="" WORK=""
CHOSEN_KEYS=() CHOSEN_KEYS=()
@ -135,49 +135,31 @@ 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 '.*' ! -name '*.pub' ! -name 'known_hosts*' -printf '%f\n' | sort) ! -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:" info "Available keys: ${available[*]}"
local i
for i in "${!available[@]}"; do
printf ' %d) %s\n' "$((i + 1))" "${available[$i]}"
done
local answer local answer
read -rp " Which keys? (numbers, first one becomes id_ed25519, empty = none): " answer read -rp " Install which keys? (space separated, empty = none): " answer
read -ra CHOSEN_KEYS <<< "$answer"
local num n name target local name
n=0 for name in "${CHOSEN_KEYS[@]}"; do
for num in $answer; do if [[ ! -f "$WORK/plain/ssh/$name" ]]; then
if [[ ! $num =~ ^[0-9]+$ ]] || (( num < 1 || num > ${#available[@]} )); then die "Unknown key: $name"
die "Not a valid key number: $num"
fi fi
if [[ -e "$HOME/.ssh/$name" ]]; then
name="${available[$((num - 1))]}" warn "$name already exists in ~/.ssh - skipping"
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/$target" install -m 600 "$WORK/plain/ssh/$name" "$HOME/.ssh/$name"
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/$target.pub" install -m 644 "$WORK/plain/ssh/$name.pub" "$HOME/.ssh/$name.pub"
fi fi
CHOSEN_KEYS+=("$name") info "Installed $HOME/.ssh/$name"
info "Installed $name as ~/.ssh/$target"
done done
} }
@ -234,17 +216,25 @@ clone_engram() {
return return
fi fi
if [[ ! -f "$HOME/.ssh/id_ed25519" ]]; then if (( ${#CHOSEN_KEYS[@]} == 0 )); then
warn "No default key (~/.ssh/id_ed25519) - cannot clone." warn "No SSH key was installed - cannot clone."
return return
fi fi
mkdir -p "$(dirname "$ENGRAM_DIR")" mkdir -p "$(dirname "$ENGRAM_DIR")"
if ! git clone "$ENGRAM_REPO" "$ENGRAM_DIR"; then
rm -rf "$ENGRAM_DIR" local key
die "Clone failed - is the deploy key set up on gitea?" 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 fi
info "Cloned into $ENGRAM_DIR" rm -rf "$ENGRAM_DIR"
done
die "Clone failed with every key - check the deploy key setup on gitea."
} }
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------

View File

@ -16,7 +16,7 @@
# bash install.sh # bash install.sh
# #
# Flow: checks -> questions -> partition -> LUKS -> BTRFS -> pacstrap -> # Flow: checks -> questions -> partition -> LUKS -> BTRFS -> pacstrap ->
# fstab -> chroot setup -> GRUB -> bootstrap.sh -> reboot # fstab -> chroot setup -> GRUB -> reboot
# #
set -euo pipefail set -euo pipefail
@ -77,7 +77,6 @@ readonly PACSTRAP_PACKAGES=(
wpa_supplicant wget neovim tmux wpa_supplicant wget neovim tmux
) )
readonly HOOKS_ENCRYPTED="base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems fsck" readonly HOOKS_ENCRYPTED="base systemd autodetect microcode modconf kms keyboard sd-vconsole block sd-encrypt filesystems fsck"
readonly RAW_BASE="https://gitea.nevim42.cz/nevim42/engram-boot/raw/branch/main"
# Filled in by ask_questions. # Filled in by ask_questions.
TARGET_DISK="" TARGET_DISK=""
@ -355,30 +354,6 @@ CHROOT
rm -f /mnt/root/engram-setup.sh rm -f /mnt/root/engram-setup.sh
} }
# ---------------------------------------------------------------------------
# bootstrap.sh - drop it into the new home, so the next step is one command.
# ---------------------------------------------------------------------------
fetch() {
if command -v curl >/dev/null; then
curl -fsSL "$1"
else
wget -qO- "$1"
fi
}
place_bootstrap() {
step "Dropping bootstrap.sh into /home/${USER_NAME}"
fetch "$RAW_BASE/bootstrap.sh" > "/mnt/home/${USER_NAME}/bootstrap.sh" \
|| die "Could not fetch bootstrap.sh from $RAW_BASE"
# A fresh system has exactly one user, so uid/gid 1000 is safe.
chown 1000:1000 "/mnt/home/${USER_NAME}/bootstrap.sh"
chmod +x "/mnt/home/${USER_NAME}/bootstrap.sh"
info "Waiting in the new home - no download needed after reboot."
}
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# The exit - summary and reboot. # The exit - summary and reboot.
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
@ -393,7 +368,7 @@ finish() {
encrypted : ${ENCRYPTED} encrypted : ${ENCRYPTED}
SUMMARY SUMMARY
info "Reboot and log in as ${USER_NAME} - run ~/bootstrap.sh, your engram is waiting." info "Reboot, log in as ${USER_NAME} and run the bootstrap - your engram is waiting."
local answer local answer
read -rp " Reboot now? [y/N]: " answer read -rp " Reboot now? [y/N]: " answer
@ -430,7 +405,6 @@ main() {
pacstrap_base pacstrap_base
generate_fstab generate_fstab
configure_system configure_system
place_bootstrap
finish finish
} }

View File

@ -9,8 +9,7 @@ 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). The bootstrap installs your first read-only deploy key on the engram repo)
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