Compare commits
2 Commits
a45f2eacd4
...
8fd797bf3c
| Author | SHA1 | Date | |
|---|---|---|---|
| 8fd797bf3c | |||
| 7716ba810f |
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_DIR="$HOME/Repositories/engram"
|
||||
readonly KNOWN_HOST="gitea.nevim42.cz"
|
||||
readonly DEPS=(age git gnupg)
|
||||
readonly DEPS=(age git gnupg openssh)
|
||||
|
||||
WORK=""
|
||||
CHOSEN_KEYS=()
|
||||
@ -135,31 +135,49 @@ install_keys() {
|
||||
|
||||
local available=()
|
||||
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
|
||||
die "No SSH keys found in the bundle."
|
||||
fi
|
||||
|
||||
info "Available keys: ${available[*]}"
|
||||
local answer
|
||||
read -rp " Install which keys? (space separated, empty = none): " answer
|
||||
read -ra CHOSEN_KEYS <<< "$answer"
|
||||
info "Available keys:"
|
||||
local i
|
||||
for i in "${!available[@]}"; do
|
||||
printf ' %d) %s\n' "$((i + 1))" "${available[$i]}"
|
||||
done
|
||||
|
||||
local name
|
||||
for name in "${CHOSEN_KEYS[@]}"; do
|
||||
if [[ ! -f "$WORK/plain/ssh/$name" ]]; then
|
||||
die "Unknown key: $name"
|
||||
local answer
|
||||
read -rp " Which keys? (numbers, first one becomes id_ed25519, empty = none): " answer
|
||||
|
||||
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
|
||||
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
|
||||
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
|
||||
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
|
||||
info "Installed $HOME/.ssh/$name"
|
||||
CHOSEN_KEYS+=("$name")
|
||||
info "Installed $name as ~/.ssh/$target"
|
||||
done
|
||||
}
|
||||
|
||||
@ -216,25 +234,17 @@ clone_engram() {
|
||||
return
|
||||
fi
|
||||
|
||||
if (( ${#CHOSEN_KEYS[@]} == 0 )); then
|
||||
warn "No SSH key was installed - cannot clone."
|
||||
if [[ ! -f "$HOME/.ssh/id_ed25519" ]]; then
|
||||
warn "No default key (~/.ssh/id_ed25519) - cannot clone."
|
||||
return
|
||||
fi
|
||||
|
||||
mkdir -p "$(dirname "$ENGRAM_DIR")"
|
||||
|
||||
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
|
||||
if ! git clone "$ENGRAM_REPO" "$ENGRAM_DIR"; then
|
||||
rm -rf "$ENGRAM_DIR"
|
||||
done
|
||||
|
||||
die "Clone failed with every key - check the deploy key setup on gitea."
|
||||
die "Clone failed - is the deploy key set up on gitea?"
|
||||
fi
|
||||
info "Cloned into $ENGRAM_DIR"
|
||||
}
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
30
install.sh
30
install.sh
@ -16,7 +16,7 @@
|
||||
# bash install.sh
|
||||
#
|
||||
# Flow: checks -> questions -> partition -> LUKS -> BTRFS -> pacstrap ->
|
||||
# fstab -> chroot setup -> GRUB -> reboot
|
||||
# fstab -> chroot setup -> GRUB -> bootstrap.sh -> reboot
|
||||
#
|
||||
set -euo pipefail
|
||||
|
||||
@ -77,6 +77,7 @@ readonly PACSTRAP_PACKAGES=(
|
||||
wpa_supplicant wget neovim tmux
|
||||
)
|
||||
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.
|
||||
TARGET_DISK=""
|
||||
@ -354,6 +355,30 @@ CHROOT
|
||||
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.
|
||||
# ---------------------------------------------------------------------------
|
||||
@ -368,7 +393,7 @@ finish() {
|
||||
encrypted : ${ENCRYPTED}
|
||||
SUMMARY
|
||||
|
||||
info "Reboot, log in as ${USER_NAME} and run the bootstrap - your engram is waiting."
|
||||
info "Reboot and log in as ${USER_NAME} - run ~/bootstrap.sh, your engram is waiting."
|
||||
|
||||
local answer
|
||||
read -rp " Reboot now? [y/N]: " answer
|
||||
@ -405,6 +430,7 @@ main() {
|
||||
pacstrap_base
|
||||
generate_fstab
|
||||
configure_system
|
||||
place_bootstrap
|
||||
finish
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
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
|
||||
- `gpg/nevim42.asc` - armored export of the GPG secret key
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user