Compare commits

...

2 commits

Author SHA1 Message Date
1f59cb6a36 setup: make reruns idempotent
- Overwrite root and jordanwages authorized_keys each run (deduped)
- Replace ad-hoc fstab edits with a managed NFS block
- Continue using overwrite for fastfetch profile script
2025-08-14 20:41:21 -05:00
9cce83abca replaced neofetch with fastfetch 2025-08-14 20:22:22 -05:00
2 changed files with 57 additions and 39 deletions

View file

@ -7,7 +7,7 @@ It uses a twostage approach:
- Prompts for root if needed - Prompts for root if needed
- Downloads and runs the latest interactive wizard - Downloads and runs the latest interactive wizard
2. **Remote setup wizard** (pulled from Git) 2. **Remote setup wizard** (pulled from Git)
- Menudriven (`whiptail`) configuration: updates, sudo, hostname, SSH keys, aliases, neofetch, CIFS mounts, etc. - Menudriven (`whiptail`) configuration: updates, sudo, hostname, SSH keys, aliases, fastfetch, CIFS mounts, etc.
--- ---

View file

@ -1,7 +1,7 @@
#!/bin/bash #!/bin/bash
############################################################################### ###############################################################################
# setup.sh - Interactive Debian VM bootstrap wizard # # setup.sh - Interactive Debian VM bootstrap wizard #
# Jordan-friendly edition (whiptail UI, aliases, neofetch, CIFS, etc.) # # Jordan-friendly edition (whiptail UI, aliases, fastfetch, CIFS, etc.) #
############################################################################### ###############################################################################
set -euo pipefail set -euo pipefail
@ -63,7 +63,7 @@ fi
# Welcome # # Welcome #
############################################################################### ###############################################################################
whiptail --title "VM Setup Wizard" --yesno "\ whiptail --title "VM Setup Wizard" --yesno "\
Welcome!\n\nThis wizard will update the system, configure sudo, hostname,\naliases, neofetch, optional tools, CIFS mounts, and SSH keys.\n\nContinue?" 12 70 || exit 0 Welcome!\n\nThis wizard will update the system, configure sudo, hostname,\naliases, fastfetch, optional tools, CIFS mounts, and SSH keys.\n\nContinue?" 12 70 || exit 0
############################################################################### ###############################################################################
# Core packages & sudo # # Core packages & sudo #
@ -100,44 +100,44 @@ hostnamectl set-hostname "$NEW_HOST"
msg "Hostname set to $NEW_HOST" msg "Hostname set to $NEW_HOST"
############################################################################### ###############################################################################
# SSH keys for root # # SSH keys for root (idempotent overwrite per run) #
############################################################################### ###############################################################################
install -d -m 700 /root/.ssh install -d -m 700 /root/.ssh
chmod 700 /root/.ssh chmod 700 /root/.ssh
test -n "$DEFAULT_SSH_KEY" && { TMP_KEYS_ROOT=$(mktemp)
grep -qxF "$DEFAULT_SSH_KEY" /root/.ssh/authorized_keys 2>/dev/null || \ if [[ -n "$DEFAULT_SSH_KEY" ]]; then
echo "$DEFAULT_SSH_KEY" >> /root/.ssh/authorized_keys printf '%s\n' "$DEFAULT_SSH_KEY" >>"$TMP_KEYS_ROOT"
chmod 600 /root/.ssh/authorized_keys fi
msg "Default SSH key added for root"
}
if confirm "Add additional SSH public key for root?"; then if confirm "Add additional SSH public key for root?"; then
KEY=$(whiptail --title "SSH Key (root)" --inputbox "Paste your public key for root:" 12 70 3>&1 1>&2 2>&3) || die "Cancelled" KEY=$(whiptail --title "SSH Key (root)" --inputbox "Paste your public key for root:" 12 70 3>&1 1>&2 2>&3) || die "Cancelled"
grep -qxF "$KEY" /root/.ssh/authorized_keys 2>/dev/null || echo "$KEY" >> /root/.ssh/authorized_keys [[ -n "$KEY" ]] && printf '%s\n' "$KEY" >>"$TMP_KEYS_ROOT"
chmod 600 /root/.ssh/authorized_keys
msg "Additional SSH key added for root"
fi fi
# de-duplicate and overwrite authorized_keys
awk '!seen[$0]++' "$TMP_KEYS_ROOT" > /root/.ssh/authorized_keys
chmod 600 /root/.ssh/authorized_keys
msg "Root authorized_keys updated (overwritten this run)"
rm -f "$TMP_KEYS_ROOT"
############################################################################### ###############################################################################
# SSH keys for user jordanwages # # SSH keys for user jordanwages (idempotent overwrite per run) #
############################################################################### ###############################################################################
USER_NAME="jordanwages" USER_NAME="jordanwages"
USER_HOME="/home/$USER_NAME" USER_HOME="/home/$USER_NAME"
install -d -m 700 "$USER_HOME/.ssh" install -d -m 700 "$USER_HOME/.ssh"
chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh" chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh"
test -n "$DEFAULT_SSH_KEY" && { TMP_KEYS_USER=$(mktemp)
grep -qxF "$DEFAULT_SSH_KEY" "$USER_HOME/.ssh/authorized_keys" 2>/dev/null || \ if [[ -n "$DEFAULT_SSH_KEY" ]]; then
echo "$DEFAULT_SSH_KEY" >> "$USER_HOME/.ssh/authorized_keys" printf '%s\n' "$DEFAULT_SSH_KEY" >>"$TMP_KEYS_USER"
chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh/authorized_keys" fi
chmod 600 "$USER_HOME/.ssh/authorized_keys"
msg "Default SSH key added for $USER_NAME"
}
if confirm "Add additional SSH public key for $USER_NAME?"; then if confirm "Add additional SSH public key for $USER_NAME?"; then
KEY=$(whiptail --title "SSH Key ($USER_NAME)" --inputbox "Paste public key for $USER_NAME:" 12 70 3>&1 1>&2 2>&3) || die "Cancelled" KEY=$(whiptail --title "SSH Key ($USER_NAME)" --inputbox "Paste public key for $USER_NAME:" 12 70 3>&1 1>&2 2>&3) || die "Cancelled"
grep -qxF "$KEY" "$USER_HOME/.ssh/authorized_keys" 2>/dev/null || echo "$KEY" >> "$USER_HOME/.ssh/authorized_keys" [[ -n "$KEY" ]] && printf '%s\n' "$KEY" >>"$TMP_KEYS_USER"
chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh/authorized_keys"
chmod 600 "$USER_HOME/.ssh/authorized_keys"
msg "Additional SSH key added for $USER_NAME"
fi fi
awk '!seen[$0]++' "$TMP_KEYS_USER" > "$USER_HOME/.ssh/authorized_keys"
chown $USER_NAME:$USER_NAME "$USER_HOME/.ssh/authorized_keys"
chmod 600 "$USER_HOME/.ssh/authorized_keys"
msg "$USER_NAME authorized_keys updated (overwritten this run)"
rm -f "$TMP_KEYS_USER"
############################################################################### ###############################################################################
# Optional utilities # # Optional utilities #
@ -148,16 +148,18 @@ SEL_RAW=$(whiptail --title "Extra Utilities" --checklist \
"Select additional packages to install:" 15 60 8 \ "Select additional packages to install:" 15 60 8 \
"${OPTS[@]}" 3>&1 1>&2 2>&3) || true "${OPTS[@]}" 3>&1 1>&2 2>&3) || true
IFS=' ' read -r -a SEL_PKGS <<< "${SEL_RAW//\"/}" IFS=' ' read -r -a SEL_PKGS <<< "${SEL_RAW//\"/}"
ensure_pkgs bat ncdu neofetch cifs-utils "${SEL_PKGS[@]}" ensure_pkgs bat ncdu fastfetch cifs-utils "${SEL_PKGS[@]}"
# Aliases # Aliases
echo "alias cat='batcat --paging=never'" >/etc/profile.d/10-bat_alias.sh echo "alias cat='batcat --paging=never'" >/etc/profile.d/10-bat_alias.sh
echo "alias du='ncdu'" >/etc/profile.d/10-ncdu_alias.sh echo "alias du='ncdu'" >/etc/profile.d/10-ncdu_alias.sh
chmod +x /etc/profile.d/10-*alias.sh chmod +x /etc/profile.d/10-*alias.sh
echo 'neofetch' >/etc/profile.d/90-neofetch.sh # Ensure only fastfetch runs on login
chmod +x /etc/profile.d/90-neofetch.sh rm -f /etc/profile.d/90-neofetch.sh
echo 'fastfetch' >/etc/profile.d/90-fastfetch.sh
chmod +x /etc/profile.d/90-fastfetch.sh
############################################################################### ###############################################################################
# NFS mounts # # NFS mounts (managed block, idempotent) #
############################################################################### ###############################################################################
NFS_HOSTS=(jimmu keiko keitai) NFS_HOSTS=(jimmu keiko keitai)
OPTS=(); for h in "${NFS_HOSTS[@]}"; do OPTS+=("$h" "" OFF); done OPTS=(); for h in "${NFS_HOSTS[@]}"; do OPTS+=("$h" "" OFF); done
@ -167,17 +169,33 @@ SEL_HOSTS=$(whiptail --title "NFS Mounts" --checklist \
mkdir -p /media mkdir -p /media
for host in "${NFS_HOSTS[@]}"; do for host in "${NFS_HOSTS[@]}"; do
TEMPLATE="${host}.wageshouse:/Data /media/${host} nfs4 _netdev,x-systemd.automount,noatime 0 0" [[ $SEL_HOSTS == *\"$host\"* ]] && mkdir -p "/media/$host"
if [[ $SEL_HOSTS == *\"$host\"* ]]; then
mkdir -p "/media/$host"
grep -q "${host}.wageshouse" /etc/fstab && \
sed -i "#${host}\.wageshouse#d" /etc/fstab
echo "$TEMPLATE" >> /etc/fstab
else
grep -q "${host}.wageshouse" /etc/fstab || echo "# $TEMPLATE" >> /etc/fstab
fi
done done
# Clean up legacy lines from prior runs (pre-managed-block versions)
for host in "${NFS_HOSTS[@]}"; do
TEMPLATE="${host}.wageshouse:/Data /media/${host} nfs4 _netdev,x-systemd.automount,noatime 0 0"
sed -i "#^${host}\.wageshouse:/Data /media/${host} nfs4 _netdev,x-systemd.automount,noatime 0 0$#d" /etc/fstab || true
sed -i "#^# ${host}\.wageshouse:/Data /media/${host} nfs4 _netdev,x-systemd.automount,noatime 0 0$#d" /etc/fstab || true
done
# Replace the managed block with current selections
BLOCK_START="# BEGIN setup.sh managed NFS"
BLOCK_END="# END setup.sh managed NFS"
sed -i "/^$BLOCK_START$/,/^$BLOCK_END$/d" /etc/fstab || true
{
echo "$BLOCK_START"
for host in "${NFS_HOSTS[@]}"; do
TEMPLATE="${host}.wageshouse:/Data /media/${host} nfs4 _netdev,x-systemd.automount,noatime 0 0"
if [[ $SEL_HOSTS == *\"$host\"* ]]; then
echo "$TEMPLATE"
else
echo "# $TEMPLATE"
fi
done
echo "$BLOCK_END"
} >> /etc/fstab
if ! mount -a 2>>"$LOGFILE"; then if ! mount -a 2>>"$LOGFILE"; then
msg "⚠️ Some NFS mounts failed. Re-run the script to check configuration." msg "⚠️ Some NFS mounts failed. Re-run the script to check configuration."
fi fi
@ -186,4 +204,4 @@ fi
# Summary # # Summary #
############################################################################### ###############################################################################
msg "\ msg "\
Setup complete!\n\n• Hostname: $NEW_HOST\n• Sudoers: ${SEL_SUDO//\"/ }\n• Packages: bat ncdu neofetch ${SEL_PKGS[*]}\n• CIFS: ${SEL_HOSTS//\"/ }\n\nLog saved to $LOGFILE\n\nEnjoy your new Debian VM!" Setup complete!\n\n• Hostname: $NEW_HOST\n• Sudoers: ${SEL_SUDO//\"/ }\n• Packages: bat ncdu fastfetch ${SEL_PKGS[*]}\n• CIFS: ${SEL_HOSTS//\"/ }\n\nLog saved to $LOGFILE\n\nEnjoy your new Debian VM!"