]> git.rocketbowman.com Git - srv-deb.git/commitdiff
automate keys; add hosting; update README
authorKyle Bowman <kyle+github@rocketbowman.com>
Sat, 11 Oct 2025 17:32:24 +0000 (13:32 -0400)
committerKyle Bowman <kyle+github@rocketbowman.com>
Sat, 11 Oct 2025 17:32:24 +0000 (13:32 -0400)
.gitignore
Makefile
README.md
deb-repo.conf [new file with mode: 0644]
reprepro/conf/distributions
scripts/_make_keyinit.sh [new file with mode: 0755]
scripts/_make_keyspecs.sh [new file with mode: 0755]
scripts/download.sh
scripts/generate_index.sh
scripts/replace_key.sh [deleted file]
update_all.sh

index d661e00462cbb41514b4692087b2d753f2a0a523..a8df2d5ca816faca03d358183533ef042d4b4946 100644 (file)
@@ -1,3 +1,5 @@
 packages
 reprepro/db
 store/
+.keyspecs
+.keyid
\ No newline at end of file
index fba5151e664acb27622c41364e9dcb4654df2a78..e31e4ca893125bd97fa4c0772355d546245e94ff 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,12 @@ help:
        @echo ""
        @echo "The following targets are available:"
        @echo ""
-       @echo "init:    Initializes the repository structure according to the .env file."
+       @echo "clean      removes hosted packages and index."
+       @echo "help      prints this help message."
+       @echo "full-reset     WARNING: cleans, then removes additional settings, like keys."
+       @echo "key       initializes a GPG key and populates it throughout the package."
+       @echo "update     installs packages and updates index."
+       @echo ""
 
 .PHONY:
 clean:
@@ -14,7 +19,31 @@ clean:
        rm -rf $(DOWNLOAD_DIR)/bookworm/*
        rm -rf $(DOWNLOAD_DIR)/trixie/*
        rm -rf $(DOWNLOAD_DIR)/sid/*
-       rm reprepro/db/*
+       rm -rf reprepro/db/*
+
+.PHONY:
+full-reset: clean
+       rm -f pub-signing-key.asc
+       rm -f .keyspecs
+       gpg --delete-secret-keys $(shell cat .keyid) && gpg --delete-keys $(shell cat .keyid)
+       sed --in-place --expression "s/$(shell cat .keyid)/KEY_ID_PLACEHOLDER/g" ./reprepro/conf/distributions
+       rm -f .keyid
+
+.keyspecs:
+       ./scripts/_make_keyspecs.sh
+
+# NOTE: This only works if the key has been made
+.keyid: .keyspecs
+       . ./.keyspecs && gpg --list-keys --with-colons $$NAME_EMAIL | grep fpr | cut -d ':' -f 10 > .keyid
+
+.PHONY:
+key: pub-signing-key.asc
+       sed --in-place --expression "s/KEY_ID_PLACEHOLDER/$(shell cat .keyid)/g" ./reprepro/conf/distributions
+
+pub-signing-key.asc: .keyspecs
+       ./scripts/_make_keyinit.sh | gpg --batch --pinentry-mode ask --gen-key
+       make .keyid
+       cat .keyid | gpg --armor --export > pub-signing-key.asc
 
 .PHONY:
 update: $(DOWNLOAD_DIR)/bookworm $(DOWNLOAD_DIR)/trixie $(DOWNLOAD_DIR)/sid
index 8e640b197324534cf9403f581e57e1f68f7fb25f..9aa66de71f5c843d957eb753049334f34de1247e 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,60 +1,54 @@
 # Overview
 
 This repository helps you bootstrap a Debian repository. It does not archive
-old versions by default.
+old versions by default. It was largely inspired by 
+[The Ultimate Guide to Debian Repository Hosting](https://dario.griffo.io/posts/ultimate-guide-debian-repository-hosting/).
 
-# Set Up
+# Client side Set Up
 
-## Prerequisites
-
-``` bash
-sudo apt install gnupg reprepro
-```
-
-## Create a GPG Key
-
-A GPG key enables you to cryptographically sign packages to assure people that
-you are the one who packaged it.
+Do this for whatever "yourdomain" is.
 
 ``` bash
-gpg --full-generate-key
+curl -sS https://debian.yourdomain.com/repository-key.asc | sudo gpg --dearmor --yes -o /etc/apt/trusted.gpg.d/yourrepo.gpg
+echo "deb https://debian.yourdomain.com $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/yourrepo.list
+sudo apt update
 ```
 
-1. Select "RSA (sign only)".
-2. Select a key size of 4096
+# Repository Set Up
 
-## Add your GPG Key to the Repository
+This section is for people who want to host their own repository.
 
-Get your Key ID by by running the following command:
+## Prerequisites
 
 ``` bash
-gpg --list-keys --keyid-format long
+sudo apt install gnupg reprepro
 ```
 
-Copy it into the repository so people can validate against it with the following command:
+## Generate your Key
 
-``` bash
-gpg --armor --export YOUR_KEY_ID > repository-key.asc
-```
+Use `make key`. It will ask you some questions, but otherwise do everything for
+you.
 
-Apply it throughout the repository by using `./scripts/replace_key.sh YOUR_KEY_ID <YOUR_ACTUAL_KEY_ID>`.
+## Set up your Web Server
 
-Okay, that's confusing. The first `YOUR_KEY_ID` is the literal string. The second
-is your actual key ID. The script does a targeted search and replace throughout
-the repository.
+There is an Apache configuration file in `deb-repo.conf`. Modify it where you
+see `PLACEHOLDER`, include it into your server configuration and restart the
+server.
 
 # Add packages to GitHub
 
 Use [Cookiecutter-deb](https://github.com/rocketbowman/cookiecutter-deb) to 
 create a new template of a package. 
 
-The GitHub action produces a draft build. You must convert that draft into a
-proper release.
+The GitHub action produces a draft build. **You must convert that draft into a
+proper release for it to be visible to this repository. **
 
 # Add packages to this Repository
 
 Add the new package to the `update_all.sh` script.
 
-# Use the Makefile
+# Update the packages via the Makefile
+
+Use `make update` to fetch the latest releases from GitHub to your repo.
 
-Use `make update` to fetch the latest releases from GitHub to your repo.
\ No newline at end of file
+Alternatively, you can use the scripts to pull specific versions from GitHub.
\ No newline at end of file
diff --git a/deb-repo.conf b/deb-repo.conf
new file mode 100644 (file)
index 0000000..ce2372b
--- /dev/null
@@ -0,0 +1,13 @@
+<VirtualHost *:80>
+    ServerName SERVER_NAME_PLACEHOLDER
+    DocumentRoot /path/to/STORE_PLACEHOLDER
+    <Directory /path/to/STORE_PLACEHOLDER>
+        Options Indexes FollowSymLinks
+        AllowOverride None
+        Require all granted
+    </Directory>
+    
+    ErrorLog ${APACHE_LOG_DIR}/debian-repo-error.log
+    CustomLog ${APACHE_LOG_DIR}/debian-repo-access.log combined
+</VirtualHost>
\ No newline at end of file
index 96f82c7fcaad1470e18991b9d5ba8e3e5e5b2362..f5e32734822158343613f9e824aff7c51e4f4700 100644 (file)
@@ -2,16 +2,16 @@ Codename: bookworm
 Architectures: amd64
 Components: main 
 Description: Apt repository for unofficial packages 
-SignWith: YOUR_KEY_ID
+SignWith: KEY_ID_PLACEHOLDER
 
 Codename: trixie
 Architectures: amd64
 Components: main 
 Description: Apt repository for unofficial packages
-SignWith: YOUR_KEY_ID
+SignWith: KEY_ID_PLACEHOLDER
 
 Codename: sid
 Architectures: amd64
 Components: main 
 Description: Apt repository for unofficial packages
-SignWith: YOUR_KEY_ID
+SignWith: KEY_ID_PLACEHOLDER
diff --git a/scripts/_make_keyinit.sh b/scripts/_make_keyinit.sh
new file mode 100755 (executable)
index 0000000..83fee90
--- /dev/null
@@ -0,0 +1,27 @@
+#!/bin/bash
+
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+ROOTDIR=$(dirname "$SCRIPT_DIR")
+
+# Get variables for the template
+if [ -f "$ROOTDIR"/.keyspecs ]; then
+    # shellcheck disable=SC1091
+    . "$ROOTDIR"/.keyspecs
+else
+    echo "Keyspecs could not be found." > /dev/stderr
+    exit 1
+fi;
+
+# Print the template after resolving variables
+cat << EOF
+%echo Generating a basic OpenPGP key
+Key-Type: RSA
+Key-Length: 4096
+Key-Usage: sign
+Name-Real: $NAME_REAL
+Name-Comment: $NAME_COMMENT
+Name-Email: $NAME_EMAIL
+Expire-Date: 0
+%commit
+%echo done
+EOF
\ No newline at end of file
diff --git a/scripts/_make_keyspecs.sh b/scripts/_make_keyspecs.sh
new file mode 100755 (executable)
index 0000000..2b139ff
--- /dev/null
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+# Get entries from user
+printf "Real Name: " && read -r NAME_REAL
+printf "Email: " && read -r NAME_EMAIL
+printf "Comment for Key: " && read -r NAME_COMMENT
+
+# Write .keyspecs file to stdout (which should be redirected for use)
+cat << EOF > .keyspecs
+NAME_REAL="$NAME_REAL"
+NAME_EMAIL="$NAME_EMAIL"
+NAME_COMMENT="$NAME_COMMENT"
+EOF
\ No newline at end of file
index e9794c1eaf8663375363796249af522fcde4c927..6be6a6892a00d6e788d68b6df2e5ae2707b6a162 100755 (executable)
@@ -2,6 +2,9 @@
 # download.sh
 # Usage: ./download uv 0.8.22 1 "amd64"
 
+# Magic to get this directory
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+
 PACKAGE_NAME="$1"
 PACKAGE_VERSION=${2:-"default"}
 BUILD_VERSION=${3:-"1"}
@@ -12,10 +15,10 @@ REPO="deb-$PACKAGE_NAME"
 
 # If PACKAGE_VERSION is unspecified, check GitHub to get the latest.
 if [ "$PACKAGE_VERSION" == "default" ]; then
-    read -r PACKAGE_VERSION <<< "$(./check_latest.sh "$PACKAGE_NAME" |sed 's/\r$//')"
+    read -r PACKAGE_VERSION <<< "$("$SCRIPT_DIR"/check_latest.sh "$PACKAGE_NAME" | sed 's/\r$//')"
 fi
 
-echo $PACKAGE_VERSION
+echo "$PACKAGE_VERSION"
 
 # Get deb for all Debian distributions
 declare -a arr=("bookworm" "trixie" "sid")
@@ -23,6 +26,6 @@ for i in "${arr[@]}"
 do
     DEBIAN_DIST=$i
     filename="${PACKAGE_NAME}_${PACKAGE_VERSION}-${BUILD_VERSION}+${DEBIAN_DIST}_${ARCHITECTURES}"
-    wget -O "../store/${DEBIAN_DIST}/${filename}.deb" \
+    wget -O "$SCRIPT_DIR/../store/${DEBIAN_DIST}/${filename}.deb" \
         "https://github.com/rocketbowman/${REPO}/releases/download/${PACKAGE_VERSION}/${filename}.deb"
 done
\ No newline at end of file
index a9c5dacfb62b4062a8646099acfa070e0c26a8c0..056ac9c7ca73187aabd43283a508bde07cda6986 100755 (executable)
@@ -1,19 +1,26 @@
 #!/bin/bash
 # generate_index.sh
 # Usage: ./generate_index.sh
-KEY_ID=YOUR_KEY_ID
-root=$(pwd)/..
-reprepro=$root/reprepro
 
+# Magic to get the directory of this script
+SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+
+# Derived Constants
+cd "$SCRIPT_DIR"/.. || exit 1
+ROOTDIR=$(pwd)
+KEY_ID=$(cat "$ROOTDIR"/.keyid)
+REPREPRO="$ROOTDIR"/reprepro
+
+# Iterate over distributions to create package information.
 declare -a arr=("bookworm" "trixie" "sid")
 for i in "${arr[@]}"
 do
     DEBIAN_DIST=$i
-    reprepro --dbdir "$reprepro"/db \
-            --confdir "$reprepro"/conf \
-            --outdir="$root"/packages \
+    reprepro --dbdir "$REPREPRO"/db \
+            --confdir "$REPREPRO"/conf \
+            --outdir="$ROOTDIR"/packages \
             --component main \
-            includedeb "$DEBIAN_DIST" "$root"/store/"$DEBIAN_DIST"/*.deb
-    package_dir="$root/packages/dists/$DEBIAN_DIST"
-    cat "$package_dir"/Release | gpg -s --default-key "$KEY_ID" -abs > "$package_dir"/Release.gpg
+            includedeb "$DEBIAN_DIST" "$ROOTDIR"/store/"$DEBIAN_DIST"/*.deb
+    package_dir="$ROOTDIR/packages/dists/$DEBIAN_DIST"
+    cat "$package_dir"/Release | gpg --sign --default-key "$KEY_ID" -abs > "$package_dir"/Release.gpg
 done
\ No newline at end of file
diff --git a/scripts/replace_key.sh b/scripts/replace_key.sh
deleted file mode 100755 (executable)
index 96c9321..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-#!/bin/bash
-rootdir=$(pwd)/..
-OLD_KEY_ID=$1
-NEW_KEY_ID=$2
-sed --in-place --expression "s/$OLD_KEY_ID/$NEW_KEY_ID/g" "$rootdir/reprepro/conf/distributions"
-sed --in-place --expression "s/$OLD_KEY_ID/$NEW_KEY_ID/g" "$rootdir/scripts/generate_index.sh"
\ No newline at end of file
index d46f6a502910c0aca530ef19fe29ebc4ced8d0ca..55c283eefc963ed98336e06b481a99919811cc5b 100755 (executable)
@@ -1,10 +1,17 @@
 #!/bin/bash
-cd scripts || return 1
+
+ROOTDIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
+SCRIPT_DIR="$ROOTDIR"/scripts
+
+
 declare -a packages=("uv")
+
+# Download all packages
 for i in "${packages[@]}"
 do
     package=$i
-    ./download.sh "$package"
+    "$SCRIPT_DIR"/download.sh "$package"
 done
 
-./generate_index.sh
\ No newline at end of file
+# Generate Index
+"$SCRIPT_DIR"/generate_index.sh
\ No newline at end of file