#!/bin/bash set -e # Setup script for Deb-Mock Debian Repository # This script sets up a Debian repository on the Forgejo server REPO_DIR="/var/www/debian-repo" REPO_USER="www-data" REPO_GROUP="www-data" echo "Setting up Deb-Mock Debian Repository..." # Create repository directory sudo mkdir -p "$REPO_DIR" sudo chown "$REPO_USER:$REPO_GROUP" "$REPO_DIR" # Install required packages sudo apt update sudo apt install -y reprepro nginx apache2-utils # Create repository structure sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/conf" sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/dists" sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/pool" # Create repository configuration sudo -u "$REPO_USER" cat > "$REPO_DIR/conf/distributions" << 'EOF' Origin: Deb-Mock Repository Label: Deb-Mock Codename: unstable Architectures: amd64 arm64 i386 all source Components: main Description: Deb-Mock Debian Package Repository SignWith: default EOF # Create options file sudo -u "$REPO_USER" cat > "$REPO_DIR/conf/options" << 'EOF' verbose basedir . EOF # Create incoming directory for package uploads sudo -u "$REPO_USER" mkdir -p "$REPO_DIR/incoming" # Set up nginx configuration sudo cat > /etc/nginx/sites-available/debian-repo << 'EOF' server { listen 80; server_name debian.raines.xyz; root /var/www/debian-repo; index index.html; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; } location ~ /\. { deny all; } } EOF # Enable the site sudo ln -sf /etc/nginx/sites-available/debian-repo /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl reload nginx # Create GPG key for repository signing (if not exists) if ! gpg --list-keys deb-mock@raines.xyz >/dev/null 2>&1; then echo "Creating GPG key for repository signing..." cat > /tmp/gpg-batch << 'EOF' %echo Generating GPG key for Deb-Mock repository Key-Type: RSA Key-Length: 4096 Name-Real: Deb-Mock Repository Name-Email: deb-mock@raines.xyz Expire-Date: 0 %commit %echo GPG key generation complete EOF gpg --batch --generate-key /tmp/gpg-batch rm /tmp/gpg-batch fi # Export public key gpg --armor --export deb-mock@raines.xyz > "$REPO_DIR/deb-mock.gpg.key" # Set proper permissions sudo chown -R "$REPO_USER:$REPO_GROUP" "$REPO_DIR" sudo chmod -R 755 "$REPO_DIR" echo "Deb-Mock Debian Repository setup complete!" echo "" echo "Repository URL: http://debian.raines.xyz" echo "Public key: http://debian.raines.xyz/deb-mock.gpg.key" echo "" echo "To add this repository to a Debian system:" echo "wget -O - http://debian.raines.xyz/deb-mock.gpg.key | sudo apt-key add -" echo "echo 'deb http://debian.raines.xyz unstable main' | sudo tee /etc/apt/sources.list.d/deb-mock.list" echo "sudo apt update" echo "" echo "To add a package to the repository:" echo "reprepro -b $REPO_DIR includedeb unstable /path/to/package.deb"