This commit is contained in:
2026-04-22 19:33:15 +02:00
parent 49df2bdf74
commit e375813045

126
part1.sh
View File

@@ -20,6 +20,69 @@ command_exists() {
command -v "$1" >/dev/null 2>&1
}
find_ssh_key_in_dir() {
local ssh_dir="$1"
local key_file=""
[[ -d "$ssh_dir" ]] || return 1
while IFS= read -r key_file; do
case "$(basename "$key_file")" in
*.pub|authorized_keys|known_hosts|config)
continue
;;
esac
if [[ -f "$key_file.pub" ]]; then
printf '%s' "$key_file"
return 0
fi
done < <(find "$ssh_dir" -maxdepth 1 -type f | sort)
return 1
}
wait_for_ssh_key() {
local preferred_path="$1"
local ssh_dir="$HOME_DIR/.ssh"
local detected_key=""
mkdir -p "$ssh_dir"
chmod 700 "$ssh_dir"
if [[ -f "$preferred_path" && -f "$preferred_path.pub" ]]; then
printf '%s' "$preferred_path"
return 0
fi
if detected_key="$(find_ssh_key_in_dir "$ssh_dir")"; then
printf '%s' "$detected_key"
return 0
fi
info "Waiting for an SSH key to appear in $ssh_dir"
printf 'Create the key in another terminal; this script will keep watching.\n'
printf 'Expected path: %s (with matching .pub file)\n' "$preferred_path"
while true; do
if [[ -f "$preferred_path" && -f "$preferred_path.pub" ]]; then
printf '%s' "$preferred_path"
return 0
fi
if detected_key="$(find_ssh_key_in_dir "$ssh_dir")"; then
printf '%s' "$detected_key"
return 0
fi
if command_exists inotifywait; then
inotifywait -q -e create -e close_write -e moved_to "$ssh_dir" >/dev/null 2>&1 || sleep 2
else
sleep 2
fi
done
}
prompt_yes_no() {
local prompt="$1"
local default="${2:-Y}"
@@ -178,6 +241,17 @@ Categories=Network;InstantMessaging;Chat;IRCClient
EOF
}
write_keyd_remap_conf() {
sudo mkdir -p /etc/keyd
sudo tee /etc/keyd/remap.conf >/dev/null <<'EOF'
[ids]
0001:0001:09b4e68d
[main]
leftalt = leftmeta
leftmeta = leftalt
EOF
}
HOME_DIR="$HOME"
BASHRC="$HOME_DIR/.bashrc"
TMP_DIR="$(mktemp -d)"
@@ -216,6 +290,7 @@ declare -a PACMAN_PACKAGES=(
grim
chromium
uv
npm
rofi
slurp
brightnessctl
@@ -275,23 +350,10 @@ if prompt_yes_no "Configure global git identity?" "Y"; then
git config --global user.email "$git_email"
fi
if prompt_yes_no "Create or reuse an SSH key for git access?" "Y"; then
info "Preparing SSH key"
if prompt_yes_no "Wait for an existing SSH key for git access?" "Y"; then
info "Waiting for SSH key"
ssh_key_path="$(prompt_required_value "SSH key path:" "$HOME_DIR/.ssh/id_ed25519")"
ssh_key_comment="$(prompt_required_value "SSH key comment/email:")"
mkdir -p "$HOME_DIR/.ssh"
chmod 700 "$HOME_DIR/.ssh"
if [[ ! -f "$ssh_key_path" ]]; then
ssh_key_passphrase=""
if prompt_yes_no "Protect the SSH key with a passphrase?" "Y"; then
ssh_key_passphrase="$(prompt_passphrase)"
fi
ssh-keygen -t ed25519 -C "$ssh_key_comment" -f "$ssh_key_path" -N "$ssh_key_passphrase"
else
info "SSH key already exists at $ssh_key_path, reusing it"
fi
ssh_key_path="$(wait_for_ssh_key "$ssh_key_path")"
chmod 600 "$ssh_key_path"
chmod 644 "$ssh_key_path.pub"
@@ -314,6 +376,38 @@ if prompt_yes_no "Create or reuse an SSH key for git access?" "Y"; then
printf '\nPublic key: %s.pub\n' "$ssh_key_path"
fi
if prompt_yes_no "Enable the keyd system service?" "Y"; then
if command_exists keyd; then
info "Enabling keyd"
sudo systemctl enable --now keyd.service
else
warn "keyd is not installed; skipping service enablement"
fi
fi
if prompt_yes_no "Remap ThinkPad Alt to Super with keyd?" "Y"; then
if command_exists keyd; then
info "Writing /etc/keyd/remap.conf"
write_keyd_remap_conf
sudo systemctl enable --now keyd.service
sudo systemctl restart keyd.service
else
warn "keyd is not installed; skipping remap configuration"
fi
fi
if prompt_yes_no "Set up uv with Python 3.14 and global tools?" "Y"; then
if command_exists uv; then
info "Configuring uv"
uv python install 3.14
uv python pin --global 3.14
uv tool install ruff
uv tool install python-lsp-server
else
warn "uv is not installed; skipping Python and tool setup"
fi
fi
if prompt_yes_no "Clone a dotfiles repository into ~/.config?" "Y"; then
info "Cloning dotfiles"
dotfiles_repo="$(prompt_required_value "Dotfiles repository URL:")"