Skip to content

Instantly share code, notes, and snippets.

@gallo-s-chingon
Created July 11, 2025 04:13
Show Gist options
  • Save gallo-s-chingon/48f3950db7fbb36b4bceba6c1f77d4ea to your computer and use it in GitHub Desktop.
Save gallo-s-chingon/48f3950db7fbb36b4bceba6c1f77d4ea to your computer and use it in GitHub Desktop.
bare metal install of ubuntu with stuff and things I want
#!/bin/bash
# Homelab Ubuntu Server Setup Script - Takes bare Ubuntu Server to Transmission homelab
set -e # Exit on any error
# Configuration Variables
STATIC_IP="192.168.1.39"
NETMASK="24"
GATEWAY="192.168.1.1"
DNS_SERVERS="192.168.1.1 8.8.8.8 1.1.1.1"
SMB_SERVER="192.168.1.30"
SMB_USER="gchingon"
TORRENT_USER="torrser"
HOSTNAME_NAME="bmini"
TRANSMISSION_VERSION="4.0.5"
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
log() {
echo -e "${GREEN}[$(date '+%Y-%m-%d %H:%M:%S')] $1${NC}"
}
warn() {
echo -e "${YELLOW}[WARNING] $1${NC}"
}
error() {
echo -e "${RED}[ERROR] $1${NC}"
exit 1
}
# Check if running as root
if [[ $EUID -eq 0 ]]; then
error "This script should not be run as root. Run as a regular user with sudo access."
fi
# Check if sudo is available
if ! sudo -v; then
error "This script requires sudo access"
fi
log "Starting Homelab Ubuntu Server Setup..."
# 1. System Update
log "Updating system packages..."
sudo apt update && sudo apt upgrade -y
# 2. Install Essential Packages
log "Installing essential packages..."
sudo apt install -y git curl wget neovim htop cifs-utils ufw net-tools \
build-essential cmake pkg-config libssl-dev libcurl4-openssl-dev \
libevent-dev libsystemd-dev gettext
# 3. Set Hostname
log "Setting hostname..."
sudo hostnamectl set-hostname "$HOSTNAME_NAME"
# 4. Create Torrent User
log "Creating torrent user..."
if ! id "$TORRENT_USER" &>/dev/null; then
sudo useradd -r -s /bin/bash -d /home/$TORRENT_USER -m $TORRENT_USER
# Set specific UID for SMB compatibility
sudo usermod -u 988 $TORRENT_USER
sudo groupmod -g 988 $TORRENT_USER
log "Created user: $TORRENT_USER with UID 988"
else
log "User $TORRENT_USER already exists"
fi
# 5. Create Directory Structure
log "Creating directory structure..."
# Main directories
sudo mkdir -p /opt/transmission/{downloads,incomplete}
sudo mkdir -p /home/$TORRENT_USER/.config/transmission-daemon
sudo mkdir -p /home/$TORRENT_USER/.local/bin
# Watch directories
sudo -u $TORRENT_USER mkdir -p /home/$TORRENT_USER/tend/{32ps,book,cine,iso,rawn,show,tune}
# Mount points for SMB shares
sudo mkdir -p /Volumes/{kalisma,movies,shows,cinema,armor,delta,barco,hold}
sudo mkdir -p /Volumes/armor/{buk,iso,32ps}
sudo mkdir -p /Volumes/delta/music
# Set ownership
sudo chown -R $TORRENT_USER:$TORRENT_USER /home/$TORRENT_USER
sudo chown -R $TORRENT_USER:$TORRENT_USER /opt/transmission
log "Directory structure created"
# 6. Configure Static IP with Netplan
log "Configuring static IP..."
NETWORK_INTERFACE=$(ip route | grep default | awk '{print $5}' | head -n1)
if [ -n "$NETWORK_INTERFACE" ]; then
log "Configuring static IP on interface: $NETWORK_INTERFACE"
sudo tee /etc/netplan/01-netcfg.yaml > /dev/null <<EOF
network:
version: 2
renderer: networkd
ethernets:
$NETWORK_INTERFACE:
dhcp4: false
addresses:
- $STATIC_IP/$NETMASK
routes:
- to: default
via: $GATEWAY
nameservers:
addresses: [$DNS_SERVERS]
EOF
sudo netplan apply
log "Static IP configured: $STATIC_IP"
fi
# 7. Configure Firewall
log "Configuring firewall..."
sudo ufw --force enable
sudo ufw allow ssh
sudo ufw allow 9091/tcp # Transmission web interface
sudo ufw allow 51413/tcp # Transmission BitTorrent
sudo ufw allow 51413/udp
log "Firewall configured"
# 8. Configure SMB Credentials
log "Configuring SMB access..."
echo "Please enter your SMB password for user $SMB_USER:"
read -s SMB_PASS
sudo mkdir -p /etc/samba
sudo tee /etc/samba/credentials >/dev/null <<EOF
username=$SMB_USER
password=$SMB_PASS
domain=WORKGROUP
EOF
sudo chmod 600 /etc/samba/credentials
# 9. Configure SMB Mounts in fstab
log "Configuring SMB mounts..."
sudo cp /etc/fstab /etc/fstab.backup
# Add SMB mount entries
sudo tee -a /etc/fstab >/dev/null <<EOF
# SMB Mounts for Homelab
//$SMB_SERVER/kalisma /Volumes/kalisma cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
//$SMB_SERVER/movies /Volumes/movies cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
//$SMB_SERVER/shows /Volumes/shows cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
//$SMB_SERVER/cinema /Volumes/cinema cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
//$SMB_SERVER/armor /Volumes/armor cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
//$SMB_SERVER/delta /Volumes/delta cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
//$SMB_SERVER/barco /Volumes/barco cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
//$SMB_SERVER/hold /Volumes/hold cifs credentials=/etc/samba/credentials,uid=988,gid=988,iocharset=utf8,file_mode=0664,dir_mode=0775,rw,users 0 0
EOF
# Mount all SMB shares
log "Mounting SMB shares..."
sudo mount -a
log "SMB shares mounted"
# 10. Build and Install Transmission 4.0.5
log "Building Transmission $TRANSMISSION_VERSION from source..."
cd /tmp
wget https://github.com/transmission/transmission/releases/download/$TRANSMISSION_VERSION/transmission-$TRANSMISSION_VERSION.tar.xz
tar -xf transmission-$TRANSMISSION_VERSION.tar.xz
cd transmission-$TRANSMISSION_VERSION
# Configure and build
mkdir build && cd build
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DENABLE_DAEMON=ON \
-DENABLE_GTK=OFF \
-DENABLE_QT=OFF \
-DENABLE_UTILS=ON \
-DENABLE_CLI=ON \
-DCMAKE_INSTALL_PREFIX=/usr/local
make -j$(nproc)
sudo make install
sudo ldconfig
# Create symbolic links
sudo ln -sf /usr/local/bin/transmission-daemon /usr/bin/transmission-daemon
sudo ln -sf /usr/local/bin/transmission-remote /usr/bin/transmission-remote
sudo ln -sf /usr/local/bin/transmission-cli /usr/bin/transmission-cli
log "Transmission $TRANSMISSION_VERSION installed successfully"
# 11. Configure Transmission
log "Configuring Transmission..."
sudo tee /etc/transmission-daemon/settings.json > /dev/null <<EOF
{
"bind-address-ipv4": "0.0.0.0",
"download-dir": "/Volumes/kalisma/frag",
"download-queue-enabled": true,
"download-queue-size": 5,
"incomplete-dir": "/Volumes/kalisma/frag/incomplete",
"incomplete-dir-enabled": true,
"peer-port": 51413,
"ratio-limit-enabled": false,
"idle-seeding-limit-enabled": false,
"rpc-authentication-required": true,
"rpc-bind-address": "0.0.0.0",
"rpc-enabled": true,
"rpc-password": "homelab123",
"rpc-port": 9091,
"rpc-username": "homelab",
"rpc-whitelist": "127.0.0.1,192.168.1.*",
"seed-queue-enabled": false,
"watch-dir": "/home/$TORRENT_USER/tend",
"watch-dir-enabled": true
}
EOF
# Create transmission user and set permissions
sudo useradd -r -s /bin/false -d /var/lib/transmission-daemon transmission 2>/dev/null || true
sudo usermod -u 988 transmission
sudo groupmod -g 988 transmission
sudo mkdir -p /etc/transmission-daemon /var/lib/transmission-daemon
sudo chown -R transmission:transmission /etc/transmission-daemon /var/lib/transmission-daemon
# 12. Create Transmission systemd service
log "Creating Transmission systemd service..."
sudo tee /etc/systemd/system/transmission-daemon.service > /dev/null <<EOF
[Unit]
Description=Transmission BitTorrent Daemon
After=network.target
[Service]
User=transmission
Group=transmission
Type=simple
ExecStart=/usr/bin/transmission-daemon -f --config-dir /etc/transmission-daemon
Restart=on-failure
RestartSec=5
TimeoutStartSec=60
[Install]
WantedBy=multi-user.target
EOF
# 13. Create Watch Directory Script
log "Creating watch directory script..."
sudo -u $TORRENT_USER tee /home/$TORRENT_USER/.local/bin/watch-subdirs.sh > /dev/null <<'EOF'
#!/bin/bash
# Watch subdirectories and add torrents with appropriate labels
WATCH_BASE="/home/torrser/tend"
TRANSMISSION_HOST="192.168.1.39:9091"
TRANSMISSION_AUTH="homelab:homelab123"
# Category to download path mapping
declare -A DOWNLOAD_PATHS=(
["32ps"]="/Volumes/armor/32ps/done"
["book"]="/Volumes/armor/buk/done"
["cine"]="/Volumes/movies/done"
["iso"]="/Volumes/armor/iso/done"
["rawn"]="/Volumes/barco/done"
["show"]="/Volumes/shows/done"
["tune"]="/Volumes/delta/music/done"
)
# Function to add torrent with category
add_torrent_with_category() {
local torrent_file="$1"
local category="$2"
local download_path="${DOWNLOAD_PATHS[$category]}"
if [ -n "$download_path" ]; then
echo "Adding torrent: $torrent_file to category: $category"
transmission-remote "$TRANSMISSION_HOST" -n "$TRANSMISSION_AUTH" \
--add "$torrent_file" \
--download-dir "$download_path" \
--labels "$category"
# Remove the torrent file after adding
rm "$torrent_file"
else
echo "Unknown category: $category"
fi
}
# Monitor each subdirectory
for category in "${!DOWNLOAD_PATHS[@]}"; do
category_dir="$WATCH_BASE/$category"
if [ -d "$category_dir" ]; then
# Process any existing .torrent files
for torrent_file in "$category_dir"/*.torrent; do
if [ -f "$torrent_file" ]; then
add_torrent_with_category "$torrent_file" "$category"
fi
done
fi
done
EOF
chmod +x /home/$TORRENT_USER/.local/bin/watch-subdirs.sh
# 14. Create Watch Directory Timer
log "Creating watch directory timer..."
sudo tee /etc/systemd/system/transmission-watch.service > /dev/null <<EOF
[Unit]
Description=Transmission Watch Subdirectories
After=transmission-daemon.service
[Service]
Type=oneshot
User=$TORRENT_USER
Group=$TORRENT_USER
ExecStart=/home/$TORRENT_USER/.local/bin/watch-subdirs.sh
EOF
sudo tee /etc/systemd/system/transmission-watch.timer > /dev/null <<EOF
[Unit]
Description=Run Transmission Watch every 30 seconds
Requires=transmission-watch.service
[Timer]
OnBootSec=30
OnUnitActiveSec=30
[Install]
WantedBy=timers.target
EOF
# 15. Enable and start services
log "Enabling services..."
sudo systemctl daemon-reload
sudo systemctl enable --now transmission-daemon.service
sudo systemctl enable --now transmission-watch.timer
# 16. Create useful aliases and environment
log "Setting up user environment..."
sudo -u $TORRENT_USER tee /home/$TORRENT_USER/.bashrc >> /dev/null <<EOF
# Homelab aliases
alias ll='ls -la'
alias la='ls -A'
alias l='ls -CF'
alias ..='cd ..'
alias ...='cd ../..'
alias grep='grep --color=auto'
alias transmission-log='journalctl -u transmission-daemon.service -f'
alias watch-log='journalctl -u transmission-watch.service -f'
alias check-mounts='df -h | grep Volumes'
alias watch-downloads='watch -n 2 "ls -la /Volumes/kalisma/frag"'
alias v=nvim
alias mk='mkdir -p'
# Environment
export EDITOR=nvim
export PATH="\$PATH:/home/$TORRENT_USER/.local/bin"
EOF
# 17. Create maintenance script
log "Creating maintenance script..."
sudo -u $TORRENT_USER tee /home/$TORRENT_USER/.local/bin/homelab-status > /dev/null <<'EOF'
#!/bin/bash
echo "=== Homelab Status ==="
echo "Date: $(date)"
echo ""
echo "=== Services ==="
systemctl is-active transmission-daemon.service transmission-watch.timer
echo ""
echo "=== Network ==="
ip addr show | grep "inet 192.168.1"
echo ""
echo "=== Mounts ==="
df -h | grep Volumes
echo ""
echo "=== Transmission Version ==="
transmission-daemon --version
echo ""
echo "=== Disk Usage ==="
df -h / /opt
echo ""
echo "=== Load ==="
uptime
EOF
chmod +x /home/$TORRENT_USER/.local/bin/homelab-status
# Cleanup
log "Cleaning up..."
cd /
rm -rf /tmp/transmission-$TRANSMISSION_VERSION*
log "Setup completed successfully!"
log ""
log "=== Next Steps ==="
log "1. Transmission Web UI: http://$STATIC_IP:9091"
log " Username: homelab"
log " Password: homelab123"
log "2. Check service status: sudo -u $TORRENT_USER homelab-status"
log "3. View transmission logs: journalctl -u transmission-daemon.service -f"
log "4. View watch logs: journalctl -u transmission-watch.service -f"
log "5. Switch to torrent user: sudo -i -u $TORRENT_USER"
log ""
log "=== Transmission 4.0.5 Features ==="
log "- Unlimited seeding (no ratio limits)"
log "- 5 concurrent downloads maximum"
log "- Watch directory monitoring every 30 seconds"
log "- Category-based download directories"
log "- SMB shares auto-mounted"
log ""
warn "Remember to:"
warn "- Test SMB mount accessibility"
warn "- Verify Transmission version is 4.0.5"
warn "- Configure *arr services to use this Transmission instance"
warn "- Test torrent download workflow"
log ""
log "Ubuntu Server homelab setup completed! 🚀"
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment