feat(post-boot): add post-boot initialization with first-boot service and SSH key generation
- commit
- 28d6386e7c56d7e4a6b67dbc532cb27dbdfeaf86
- author
- bnema · · 2025-10-20 18:45 UTC
- parent
- 026da9c
- signature
- unsigned
4 files · +110 -0
A install/post-boot/all.sh +27 -0
| @@ -0,0 +1,27 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | # ArchUp First Boot - Post-boot tasks that require running system | |
| 3 | + | ||
| 4 | + | set -e | |
| 5 | + | ||
| 6 | + | LOG_FILE="/var/log/archup-first-boot.log" | |
| 7 | + | ||
| 8 | + | echo "=== ArchUp First Boot Setup - $(date) ===" > "$LOG_FILE" | |
| 9 | + | ||
| 10 | + | # Run snapper configuration | |
| 11 | + | if [ -f /usr/local/share/archup/post-boot/snapper.sh ]; then | |
| 12 | + | echo "Configuring snapper..." | tee -a "$LOG_FILE" | |
| 13 | + | bash /usr/local/share/archup/post-boot/snapper.sh >> "$LOG_FILE" 2>&1 | |
| 14 | + | fi | |
| 15 | + | ||
| 16 | + | # Run SSH key generation | |
| 17 | + | if [ -f /usr/local/share/archup/post-boot/ssh-keygen.sh ]; then | |
| 18 | + | echo "Generating SSH keys..." | tee -a "$LOG_FILE" | |
| 19 | + | bash /usr/local/share/archup/post-boot/ssh-keygen.sh >> "$LOG_FILE" 2>&1 | |
| 20 | + | fi | |
| 21 | + | ||
| 22 | + | echo "=== First Boot Setup Complete ===" >> "$LOG_FILE" | |
| 23 | + | ||
| 24 | + | # Disable this service after first run | |
| 25 | + | systemctl disable archup-first-boot.service | |
| 26 | + | ||
| 27 | + | echo "First boot setup completed successfully" | |
| @@ -0,0 +1,27 @@ | |||||
| 1 | + | #!/bin/bash | |||
| 2 | + | # ArchUp First Boot - Post-boot tasks that require running system | |||
| 3 | + | ||||
| 4 | + | set -e | |||
| 5 | + | ||||
| 6 | + | LOG_FILE="/var/log/archup-first-boot.log" | |||
| 7 | + | ||||
| 8 | + | echo "=== ArchUp First Boot Setup - $(date) ===" > "$LOG_FILE" | |||
| 9 | + | ||||
| 10 | + | # Run snapper configuration | |||
| 11 | + | if [ -f /usr/local/share/archup/post-boot/snapper.sh ]; then | |||
| 12 | + | echo "Configuring snapper..." | tee -a "$LOG_FILE" | |||
| 13 | + | bash /usr/local/share/archup/post-boot/snapper.sh >> "$LOG_FILE" 2>&1 | |||
| 14 | + | fi | |||
| 15 | + | ||||
| 16 | + | # Run SSH key generation | |||
| 17 | + | if [ -f /usr/local/share/archup/post-boot/ssh-keygen.sh ]; then | |||
| 18 | + | echo "Generating SSH keys..." | tee -a "$LOG_FILE" | |||
| 19 | + | bash /usr/local/share/archup/post-boot/ssh-keygen.sh >> "$LOG_FILE" 2>&1 | |||
| 20 | + | fi | |||
| 21 | + | ||||
| 22 | + | echo "=== First Boot Setup Complete ===" >> "$LOG_FILE" | |||
| 23 | + | ||||
| 24 | + | # Disable this service after first run | |||
| 25 | + | systemctl disable archup-first-boot.service | |||
| 26 | + | ||||
| 27 | + | echo "First boot setup completed successfully" | |||
A install/post-boot/archup-first-boot.service +16 -0
| @@ -0,0 +1,16 @@ | |||
| 1 | + | [Unit] | |
| 2 | + | Description=ArchUp First Boot Setup | |
| 3 | + | After=local-fs.target systemd-logind.service dbus.service | |
| 4 | + | ConditionPathExists=!/var/lib/archup-first-boot-complete | |
| 5 | + | ||
| 6 | + | [Service] | |
| 7 | + | Type=oneshot | |
| 8 | + | Environment="ARCHUP_EMAIL=__ARCHUP_EMAIL__" | |
| 9 | + | Environment="ARCHUP_USERNAME=__ARCHUP_USERNAME__" | |
| 10 | + | ExecStart=/usr/local/share/archup/post-boot/all.sh | |
| 11 | + | ExecStartPost=/usr/bin/touch /var/lib/archup-first-boot-complete | |
| 12 | + | StandardOutput=journal+console | |
| 13 | + | StandardError=journal+console | |
| 14 | + | ||
| 15 | + | [Install] | |
| 16 | + | WantedBy=multi-user.target | |
| @@ -0,0 +1,16 @@ | |||||
| 1 | + | [Unit] | |||
| 2 | + | Description=ArchUp First Boot Setup | |||
| 3 | + | After=local-fs.target systemd-logind.service dbus.service | |||
| 4 | + | ConditionPathExists=!/var/lib/archup-first-boot-complete | |||
| 5 | + | ||||
| 6 | + | [Service] | |||
| 7 | + | Type=oneshot | |||
| 8 | + | Environment="ARCHUP_EMAIL=__ARCHUP_EMAIL__" | |||
| 9 | + | Environment="ARCHUP_USERNAME=__ARCHUP_USERNAME__" | |||
| 10 | + | ExecStart=/usr/local/share/archup/post-boot/all.sh | |||
| 11 | + | ExecStartPost=/usr/bin/touch /var/lib/archup-first-boot-complete | |||
| 12 | + | StandardOutput=journal+console | |||
| 13 | + | StandardError=journal+console | |||
| 14 | + | ||||
| 15 | + | [Install] | |||
| 16 | + | WantedBy=multi-user.target | |||
A install/post-boot/snapper.sh +23 -0
| @@ -0,0 +1,23 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | # Post-boot: Configure snapper (requires D-Bus) | |
| 3 | + | ||
| 4 | + | # Create snapper configs if they don't exist | |
| 5 | + | if ! snapper list-configs 2>/dev/null | grep -q "root"; then | |
| 6 | + | snapper -c root create-config / | |
| 7 | + | echo "Created snapper config: root" | |
| 8 | + | fi | |
| 9 | + | ||
| 10 | + | if ! snapper list-configs 2>/dev/null | grep -q "home"; then | |
| 11 | + | snapper -c home create-config /home | |
| 12 | + | echo "Created snapper config: home" | |
| 13 | + | fi | |
| 14 | + | ||
| 15 | + | # Tweak default snapper configs | |
| 16 | + | sed -i 's/^TIMELINE_CREATE="yes"/TIMELINE_CREATE="no"/' /etc/snapper/configs/root | |
| 17 | + | sed -i 's/^TIMELINE_CREATE="yes"/TIMELINE_CREATE="no"/' /etc/snapper/configs/home | |
| 18 | + | sed -i 's/^NUMBER_LIMIT="50"/NUMBER_LIMIT="5"/' /etc/snapper/configs/root | |
| 19 | + | sed -i 's/^NUMBER_LIMIT="50"/NUMBER_LIMIT="5"/' /etc/snapper/configs/home | |
| 20 | + | sed -i 's/^NUMBER_LIMIT_IMPORTANT="10"/NUMBER_LIMIT_IMPORTANT="5"/' /etc/snapper/configs/root | |
| 21 | + | sed -i 's/^NUMBER_LIMIT_IMPORTANT="10"/NUMBER_LIMIT_IMPORTANT="5"/' /etc/snapper/configs/home | |
| 22 | + | ||
| 23 | + | echo "Configured snapper limits" | |
| @@ -0,0 +1,23 @@ | |||||
| 1 | + | #!/bin/bash | |||
| 2 | + | # Post-boot: Configure snapper (requires D-Bus) | |||
| 3 | + | ||||
| 4 | + | # Create snapper configs if they don't exist | |||
| 5 | + | if ! snapper list-configs 2>/dev/null | grep -q "root"; then | |||
| 6 | + | snapper -c root create-config / | |||
| 7 | + | echo "Created snapper config: root" | |||
| 8 | + | fi | |||
| 9 | + | ||||
| 10 | + | if ! snapper list-configs 2>/dev/null | grep -q "home"; then | |||
| 11 | + | snapper -c home create-config /home | |||
| 12 | + | echo "Created snapper config: home" | |||
| 13 | + | fi | |||
| 14 | + | ||||
| 15 | + | # Tweak default snapper configs | |||
| 16 | + | sed -i 's/^TIMELINE_CREATE="yes"/TIMELINE_CREATE="no"/' /etc/snapper/configs/root | |||
| 17 | + | sed -i 's/^TIMELINE_CREATE="yes"/TIMELINE_CREATE="no"/' /etc/snapper/configs/home | |||
| 18 | + | sed -i 's/^NUMBER_LIMIT="50"/NUMBER_LIMIT="5"/' /etc/snapper/configs/root | |||
| 19 | + | sed -i 's/^NUMBER_LIMIT="50"/NUMBER_LIMIT="5"/' /etc/snapper/configs/home | |||
| 20 | + | sed -i 's/^NUMBER_LIMIT_IMPORTANT="10"/NUMBER_LIMIT_IMPORTANT="5"/' /etc/snapper/configs/root | |||
| 21 | + | sed -i 's/^NUMBER_LIMIT_IMPORTANT="10"/NUMBER_LIMIT_IMPORTANT="5"/' /etc/snapper/configs/home | |||
| 22 | + | ||||
| 23 | + | echo "Configured snapper limits" | |||
A install/post-boot/ssh-keygen.sh +44 -0
| @@ -0,0 +1,44 @@ | |||
| 1 | + | #!/bin/bash | |
| 2 | + | # Post-boot: Generate SSH key without password if email was provided | |
| 3 | + | ||
| 4 | + | # Read from environment variables (set by systemd service) | |
| 5 | + | EMAIL="$ARCHUP_EMAIL" | |
| 6 | + | USERNAME="$ARCHUP_USERNAME" | |
| 7 | + | ||
| 8 | + | if [ -z "$EMAIL" ] || [ -z "$USERNAME" ]; then | |
| 9 | + | echo "Skipping SSH key generation (no email provided)" | |
| 10 | + | exit 0 | |
| 11 | + | fi | |
| 12 | + | ||
| 13 | + | # Get user home directory | |
| 14 | + | USER_HOME=$(eval echo ~"$USERNAME") | |
| 15 | + | SSH_DIR="$USER_HOME/.ssh" | |
| 16 | + | ||
| 17 | + | # Create .ssh directory if it doesn't exist | |
| 18 | + | if [ ! -d "$SSH_DIR" ]; then | |
| 19 | + | mkdir -p "$SSH_DIR" | |
| 20 | + | chmod 700 "$SSH_DIR" | |
| 21 | + | chown "$USERNAME:$USERNAME" "$SSH_DIR" | |
| 22 | + | fi | |
| 23 | + | ||
| 24 | + | # Generate SSH key if it doesn't exist | |
| 25 | + | if [ ! -f "$SSH_DIR/id_ed25519" ]; then | |
| 26 | + | echo "Generating SSH key for $USERNAME..." | |
| 27 | + | su - "$USERNAME" -c "ssh-keygen -t ed25519 -C '$EMAIL' -f '$SSH_DIR/id_ed25519' -N ''" | |
| 28 | + | echo "SSH key generated at $SSH_DIR/id_ed25519" | |
| 29 | + | else | |
| 30 | + | echo "SSH key already exists, skipping generation" | |
| 31 | + | fi | |
| 32 | + | ||
| 33 | + | # Set proper permissions | |
| 34 | + | chmod 600 "$SSH_DIR/id_ed25519" | |
| 35 | + | chmod 644 "$SSH_DIR/id_ed25519.pub" | |
| 36 | + | chown "$USERNAME:$USERNAME" "$SSH_DIR/id_ed25519" "$SSH_DIR/id_ed25519.pub" | |
| 37 | + | ||
| 38 | + | # Configure git with user email and name | |
| 39 | + | echo "Configuring git..." | |
| 40 | + | su - "$USERNAME" -c "git config --global user.email '$EMAIL'" | |
| 41 | + | su - "$USERNAME" -c "git config --global user.name '$USERNAME'" | |
| 42 | + | echo "Git configured with email: $EMAIL and name: $USERNAME" | |
| 43 | + | ||
| 44 | + | echo "SSH key setup complete" | |
| @@ -0,0 +1,44 @@ | |||||
| 1 | + | #!/bin/bash | |||
| 2 | + | # Post-boot: Generate SSH key without password if email was provided | |||
| 3 | + | ||||
| 4 | + | # Read from environment variables (set by systemd service) | |||
| 5 | + | EMAIL="$ARCHUP_EMAIL" | |||
| 6 | + | USERNAME="$ARCHUP_USERNAME" | |||
| 7 | + | ||||
| 8 | + | if [ -z "$EMAIL" ] || [ -z "$USERNAME" ]; then | |||
| 9 | + | echo "Skipping SSH key generation (no email provided)" | |||
| 10 | + | exit 0 | |||
| 11 | + | fi | |||
| 12 | + | ||||
| 13 | + | # Get user home directory | |||
| 14 | + | USER_HOME=$(eval echo ~"$USERNAME") | |||
| 15 | + | SSH_DIR="$USER_HOME/.ssh" | |||
| 16 | + | ||||
| 17 | + | # Create .ssh directory if it doesn't exist | |||
| 18 | + | if [ ! -d "$SSH_DIR" ]; then | |||
| 19 | + | mkdir -p "$SSH_DIR" | |||
| 20 | + | chmod 700 "$SSH_DIR" | |||
| 21 | + | chown "$USERNAME:$USERNAME" "$SSH_DIR" | |||
| 22 | + | fi | |||
| 23 | + | ||||
| 24 | + | # Generate SSH key if it doesn't exist | |||
| 25 | + | if [ ! -f "$SSH_DIR/id_ed25519" ]; then | |||
| 26 | + | echo "Generating SSH key for $USERNAME..." | |||
| 27 | + | su - "$USERNAME" -c "ssh-keygen -t ed25519 -C '$EMAIL' -f '$SSH_DIR/id_ed25519' -N ''" | |||
| 28 | + | echo "SSH key generated at $SSH_DIR/id_ed25519" | |||
| 29 | + | else | |||
| 30 | + | echo "SSH key already exists, skipping generation" | |||
| 31 | + | fi | |||
| 32 | + | ||||
| 33 | + | # Set proper permissions | |||
| 34 | + | chmod 600 "$SSH_DIR/id_ed25519" | |||
| 35 | + | chmod 644 "$SSH_DIR/id_ed25519.pub" | |||
| 36 | + | chown "$USERNAME:$USERNAME" "$SSH_DIR/id_ed25519" "$SSH_DIR/id_ed25519.pub" | |||
| 37 | + | ||||
| 38 | + | # Configure git with user email and name | |||
| 39 | + | echo "Configuring git..." | |||
| 40 | + | su - "$USERNAME" -c "git config --global user.email '$EMAIL'" | |||
| 41 | + | su - "$USERNAME" -c "git config --global user.name '$USERNAME'" | |||
| 42 | + | echo "Git configured with email: $EMAIL and name: $USERNAME" | |||
| 43 | + | ||||
| 44 | + | echo "SSH key setup complete" | |||