What does the Server Configuration Script do?


Return to Main Page  |  Go Back To Setup

Warning: Running this script involves risks! It modifies system settings and disks, which can lead to data loss if not used carefully.
Only proceed if you are comfortable with command-line operations and server configuration or are willing to accept potential risks.


Stay tuned for future video tutorials covering these steps in detail!

What This Script Does

This script automates the setup of a Linux server (e.g., a Raspberry Pi or other Ubuntu-based system) as a file-sharing server using Samba. It allows you to share files across your network, accessible from Windows, macOS, or Linux devices. Below is a step-by-step explanation of what the script does.

1: Verifies Administrator Privileges

The script checks if it's running with root (administrator) privileges, as some tasks require elevated access. If not run with sudo, it will exit with a warning.

2: Checks for Required Tools

Ensures essential tools (e.g., blkid, samba, ufw) are installed. If any are missing, it prompts you to install them before proceeding.

3: Updates the System

Checks for an internet connection and updates the server's software to the latest versions for security and stability. If there's no internet, this step is skipped.

4: Installs Necessary Software

Installs required packages if not already present:

5: Configures Disks

Detects connected disks (e.g., USB drives) and sets them up for sharing:

  1. Identifies disks with supported file systems (ext4, NTFS, exFAT, FAT32).
  2. If a disk lacks a file system, it asks if you want to format it as ext4 (warning: this erases all data).
  3. Mounts disks to folders like /mnt/main or /mnt/secondary1.
  4. Updates the system to mount these disks automatically on boot.

6: Sets Up Samba Shares

Configures Samba to share the mounted disks over the network:

  1. Prompts for a list of allowed users (or allows all authenticated users if left blank).
  2. Sets up secure shares with read/write access for authorized users.
  3. Validates the Samba configuration and restarts the Samba service.

7: Configures the Firewall

Sets up the firewall (ufw) to allow Samba and SSH traffic for secure access. If the firewall is disabled, it asks if you want to enable it.

8: Schedules Automatic Updates

Creates a script to update the system and reboot safely (only when no users are accessing Samba shares):

  1. Offers a default schedule (weekly on Sundays at 3:00 AM) or a custom schedule (daily, weekly, or monthly).
  2. Saves the update script to /root/cronjobs/updater.sh and adds it to the system's cron jobs.

9: Displays Server Information

At the end, the script shows:

Use these paths to connect to the shares from your devices, entering the Samba username and password if prompted.

Logs

All actions are logged to /var/log/server_config.log for troubleshooting. Check this file if you encounter issues.

The "download and run" command:

The NAS Setup page provides you with the following command:

cd ~ && wget https://nas.humbertoduenas.com/configure_server.sh && chmod +x configure_server.sh && sudo ./configure_server.sh

What it does: The command navigates to your "home" directory then downloads the configuration script we just described from our website to your home directory. It then makes the script executable so that your machine can run it, then it actually runs it.