Created
September 14, 2025 16:34
-
-
Save kundancool/22c477fc61d0960bb477d90b1706c79f to your computer and use it in GitHub Desktop.
Improve base alpine install
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # Alpine Linux Server Enhancement Script | |
| # Structured with functions | |
| # Run as root | |
| set -e | |
| # ------------------------------- | |
| # Update & upgrade system | |
| # ------------------------------- | |
| update_system() { | |
| echo ">>> Updating system..." | |
| apk update && apk upgrade | |
| } | |
| # ------------------------------- | |
| # Install base utilities | |
| # ------------------------------- | |
| install_utilities() { | |
| echo ">>> Installing useful base utilities..." | |
| apk add --no-cache \ | |
| bash bash-completion \ | |
| curl wget rsync \ | |
| nano nano-syntax vim \ | |
| htop iotop ncdu \ | |
| lsof net-tools iproute2 \ | |
| tmux \ | |
| logrotate \ | |
| openssh openssl \ | |
| sudo tzdata | |
| } | |
| # ------------------------------- | |
| # Configure nano | |
| # ------------------------------- | |
| configure_nano() { | |
| echo ">>> Configuring nano..." | |
| NANO_RC="/etc/nanorc" | |
| # Backup existing nanorc if not already done | |
| [ -f "$NANO_RC" ] && cp "$NANO_RC" "${NANO_RC}.bak" | |
| cat << 'EOF' > "$NANO_RC" | |
| # System-wide nano configuration | |
| ## Enable syntax highlighting | |
| include /usr/share/nano/*.nanorc | |
| ## Show line numbers | |
| set linenumbers | |
| ## Enable auto indent | |
| set autoindent | |
| ## Enable mouse support | |
| set mouse | |
| ## Enable soft line wrapping | |
| set softwrap | |
| ## Highlight search matches | |
| set highlight | |
| EOF | |
| } | |
| # ------------------------------- | |
| # Configure timezone | |
| # ------------------------------- | |
| configure_timezone() { | |
| echo ">>> Setting timezone to UTC..." | |
| setup-timezone -z UTC | |
| } | |
| # ------------------------------- | |
| # Enable system logging | |
| # ------------------------------- | |
| enable_logging() { | |
| echo ">>> Enabling system logging..." | |
| apk add --no-cache rsyslog | |
| rc-update add rsyslog | |
| rc-service rsyslog start | |
| } | |
| # ------------------------------- | |
| # Enable automatic updates | |
| # ------------------------------- | |
| enable_auto_updates() { | |
| echo ">>> Setting up automatic updates..." | |
| apk add --no-cache unattended-upgrades | |
| rc-update add unattended-upgrades | |
| rc-service unattended-upgrades start | |
| } | |
| # ------------------------------- | |
| # Cleanup | |
| # ------------------------------- | |
| cleanup() { | |
| echo ">>> Cleaning up package cache..." | |
| apk cache clean | |
| } | |
| # ------------------------------- | |
| # Main function | |
| # ------------------------------- | |
| main() { | |
| update_system | |
| install_utilities | |
| configure_nano | |
| configure_timezone | |
| enable_logging | |
| enable_auto_updates | |
| cleanup | |
| echo ">>> Enhancement complete! Reboot recommended." | |
| } | |
| main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment