Last active
March 8, 2025 03:06
-
-
Save forkwhilefork/c1aea0c39124f78eab467c0227e4f1fa to your computer and use it in GitHub Desktop.
setup.sh
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/bash | |
| # Linux Setup Script | |
| # This script automates common setup tasks for new Linux machines | |
| # Check if script is run as root | |
| if [[ $EUID -ne 0 ]]; then | |
| echo "This script must be run as root" | |
| exit 1 | |
| fi | |
| # Display help message | |
| function show_help { | |
| echo "Usage: $0 [options]" | |
| echo "Options:" | |
| echo " --all Run all tasks" | |
| echo " --packages Install common packages" | |
| echo " --docker Install and enable Docker" | |
| echo " --caddy Install and enable Caddy" | |
| echo " --mariadb Install MariaDB database server" | |
| echo " --help Display this help message" | |
| echo "" | |
| echo "Example: $0 --packages --docker" | |
| } | |
| # Function to install common packages | |
| function install_packages { | |
| echo "Installing common packages..." | |
| # Install basic packages | |
| dnf install -y nano wget tar unzip whois traceroute tcpdump epel-release | |
| # Install packages from EPEL repository | |
| dnf install -y screen bind-utils open-vm-tools policycoreutils-python-utils | |
| echo "Common packages installed successfully." | |
| } | |
| # Function to install and enable Docker | |
| function install_docker { | |
| echo "Installing Docker..." | |
| # Add Docker repository | |
| dnf config-manager --add-repo https://download.docker.com/linux/rhel/docker-ce.repo | |
| # Install Docker packages | |
| dnf install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin | |
| # Enable and start Docker service | |
| systemctl enable --now docker | |
| echo "Docker installed and started successfully." | |
| } | |
| # Function to install and enable Caddy | |
| function install_caddy { | |
| echo "Installing Caddy..." | |
| # Install COPR plugin for DNF | |
| dnf install -y 'dnf-command(copr)' | |
| # Enable Caddy repository | |
| dnf copr enable -y @caddy/caddy | |
| # Install Caddy | |
| dnf install -y caddy | |
| # Enable Caddy service (but don't start it) | |
| systemctl enable caddy | |
| echo "Caddy installed and enabled successfully." | |
| } | |
| # Function to install MariaDB | |
| function install_mariadb { | |
| echo "Installing MariaDB..." | |
| # Create MariaDB repository file | |
| cat > /etc/yum.repos.d/MariaDB.repo << EOF | |
| [mariadb] | |
| name = MariaDB | |
| baseurl = https://rpm.mariadb.org/11.rolling/rhel\$releasever-amd64 | |
| gpgkey= https://rpm.mariadb.org/RPM-GPG-KEY-MariaDB | |
| gpgcheck=1 | |
| EOF | |
| # Install MariaDB packages | |
| dnf install -y MariaDB-server MariaDB-client | |
| echo "MariaDB installed successfully." | |
| } | |
| # Parse command line arguments | |
| if [[ $# -eq 0 ]]; then | |
| show_help | |
| exit 0 | |
| fi | |
| # Process arguments | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| --all) | |
| INSTALL_PACKAGES=true | |
| INSTALL_DOCKER=true | |
| INSTALL_CADDY=true | |
| INSTALL_MARIADB=true | |
| shift | |
| ;; | |
| --packages) | |
| INSTALL_PACKAGES=true | |
| shift | |
| ;; | |
| --docker) | |
| INSTALL_DOCKER=true | |
| shift | |
| ;; | |
| --caddy) | |
| INSTALL_CADDY=true | |
| shift | |
| ;; | |
| --mariadb) | |
| INSTALL_MARIADB=true | |
| shift | |
| ;; | |
| --help) | |
| show_help | |
| exit 0 | |
| ;; | |
| *) | |
| echo "Unknown option: $1" | |
| show_help | |
| exit 1 | |
| ;; | |
| esac | |
| done | |
| # Execute selected tasks | |
| if [[ $INSTALL_PACKAGES == true ]]; then | |
| install_packages | |
| fi | |
| if [[ $INSTALL_DOCKER == true ]]; then | |
| install_docker | |
| fi | |
| if [[ $INSTALL_CADDY == true ]]; then | |
| install_caddy | |
| fi | |
| if [[ $INSTALL_MARIADB == true ]]; then | |
| install_mariadb | |
| fi | |
| echo "Setup completed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment