Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
linux:debian:setup-repository [2023/07/30 12:16] – removed - external edit (Unknown date) 127.0.0.1 | linux:debian:setup-repository [2025/02/11 08:12] (current) – Zyzonix | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ===== Setup Debian Repository (Apache) ===== | ||
+ | |||
+ | This tutorial will cover how to create a debian ('' | ||
+ | ----- | ||
+ | Prerequisites: | ||
+ | <code bash> | ||
+ | |||
+ | ===== Build custom package ===== | ||
+ | |||
+ | ==== Create executeable package ==== | ||
+ | Firstly create directory '' | ||
+ | <code bash> | ||
+ | |||
+ | Enter the directory and create a file called '' | ||
+ | <code bash> | ||
+ | #include < | ||
+ | int main() { | ||
+ | printf(" | ||
+ | return 0; | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Then create an executeable: | ||
+ | <code bash>gcc -o firstpkg main.c</ | ||
+ | |||
+ | The default naming scheme for '' | ||
+ | |||
+ | ''< | ||
+ | |||
+ | We will replace these variables with the following: | ||
+ | <WRAP 30%> | ||
+ | ^ Varibale | ||
+ | | package-name | ||
+ | | version | ||
+ | | release-number | ||
+ | | architecture | ||
+ | </ | ||
+ | The release number is usually set to '' | ||
+ | |||
+ | Next create a directory with replaced variables and the subdirectories '' | ||
+ | <code bash> | ||
+ | <code bash> | ||
+ | <code bash> | ||
+ | |||
+ | Now copy the executeable to the binary directory: | ||
+ | <code bash>cp ~/ | ||
+ | |||
+ | To clearly identify packages, each package requires a '' | ||
+ | <code bash> | ||
+ | |||
+ | Add the following lines to this file: | ||
+ | <code bash> | ||
+ | Package: firstpkg | ||
+ | Version: 0.0.1 | ||
+ | Maintainer: example < | ||
+ | Depends: libc6 | ||
+ | Architecture: | ||
+ | Homepage: http:// | ||
+ | Description: | ||
+ | </ | ||
+ | |||
+ | <callout type=" | ||
+ | |||
+ | ==== Build a .deb package ==== | ||
+ | Now build the package: | ||
+ | <code bash> | ||
+ | |||
+ | If everything worked correctly there should be one file named '' | ||
+ | |||
+ | Finally you can view package information with: | ||
+ | <code bash> | ||
+ | The output of the last command should contain the executeable. | ||
+ | |||
+ | Try to install this package with: | ||
+ | <code bash> | ||
+ | |||
+ | And run it with: | ||
+ | <code bash> | ||
+ | |||
+ | If the output equals '' | ||
+ | |||
+ | Remove it again with: | ||
+ | <code bash> | ||
+ | |||
+ | //This part was sourced from [[https:// | ||
+ | |||
+ | ----- | ||
+ | ===== Setup repository server ===== | ||
+ | |||
+ | Therefore this guide uses the '' | ||
+ | |||
+ | ==== Create directories ==== | ||
+ | The root path should be ''/ | ||
+ | <code bash> | ||
+ | <code bash> | ||
+ | <code bash> | ||
+ | |||
+ | ==== Setup apache2 ==== | ||
+ | This guide uses the '' | ||
+ | <code bash>apt install apache2</ | ||
+ | |||
+ | Next remove the default sites: | ||
+ | <code bash>rm / | ||
+ | <code bash>rm / | ||
+ | |||
+ | And create the new repository site:: | ||
+ | <code bash> | ||
+ | The ''< | ||
+ | |||
+ | Paste this content with changed variables to the site config: | ||
+ | ++++ Show/Hide repository.conf| | ||
+ | <code bash> | ||
+ | < | ||
+ | # The ServerName directive sets the request scheme, hostname and port that | ||
+ | # the server uses to identify itself. This is used when creating | ||
+ | # redirection URLs. In the context of virtual hosts, the ServerName | ||
+ | # specifies what hostname must appear in the request' | ||
+ | # match this virtual host. For the default virtual host (this file) this | ||
+ | # value is not decisive as it is used as a last resort host regardless. | ||
+ | # However, you must set it for any further virtual host explicitly. | ||
+ | |||
+ | # | ||
+ | DocumentRoot </ | ||
+ | ServerName < | ||
+ | ServerAlias < | ||
+ | |||
+ | # Available loglevels: trace8, ..., trace1, debug, info, notice, warn, | ||
+ | # error, crit, alert, emerg. | ||
+ | # It is also possible to configure the loglevel for particular | ||
+ | # modules, e.g. | ||
+ | #LogLevel info ssl:warn | ||
+ | |||
+ | # HTTP Strict Transport Security (63072000 seconds) | ||
+ | Header always set Strict-Transport-Security " | ||
+ | |||
+ | # Setting this header will prevent MSIE from interpreting files as something | ||
+ | # else than declared by the content type in the HTTP headers. | ||
+ | Header setifempty X-Content-Type-Options: | ||
+ | |||
+ | # Setting this header will prevent location disclosure to third party sites, | ||
+ | # e.g. if a user follows a link outside of our SLD. | ||
+ | Header setifempty Referrer-Policy: | ||
+ | |||
+ | # Block pages from loading when they detect reflected XSS attacks | ||
+ | Header setifempty X-XSS-Protection: | ||
+ | |||
+ | < | ||
+ | Allow from all | ||
+ | AllowOverride All | ||
+ | Options Indexes FollowSymlinks | ||
+ | Require all granted | ||
+ | |||
+ | <Files packages-amd64.db> | ||
+ | Require all denied | ||
+ | </ | ||
+ | |||
+ | <Files packages-arm64.db> | ||
+ | Require all denied | ||
+ | </ | ||
+ | |||
+ | <Files packages-armhf.db> | ||
+ | Require all denied | ||
+ | </ | ||
+ | </ | ||
+ | ErrorLog ${APACHE_LOG_DIR}/ | ||
+ | CustomLog ${APACHE_LOG_DIR}/ | ||
+ | </ | ||
+ | </ | ||
+ | ++++ | ||
+ | |||
+ | ==== Create GPG Keys ==== | ||
+ | To securely update from the repository the Releases file will be signed with a [[https:// | ||
+ | |||
+ | These keys will be generated in a safe environment, | ||
+ | <code bash> | ||
+ | The new four '' | ||
+ | |||
+ | Next set the directory for GPG: | ||
+ | <code bash> | ||
+ | |||
+ | Finally generate the keypair with the following settings: | ||
+ | <code bash>gpg --full-generate-key</ | ||
+ | <WRAP 30%> | ||
+ | ^ Request | ||
+ | | Kind of Key | 1 (RSA and RSA) | | ||
+ | | Keysize | ||
+ | | Expiring | ||
+ | </ | ||
+ | A name must be entered, email address and comment can be left empty. | ||
+ | You //can// also enter a password or just skip the prompts, it's your decision. | ||
+ | |||
+ | To view all created keys use this command: | ||
+ | <code bash>gpg --list-secret-keys --keyid-format=long</ | ||
+ | |||
+ | Now create the public key file: | ||
+ | <code bash>gpg --armor --export <ID> > public.key</ | ||
+ | Replace ''< | ||
+ | To make the public key accessible so that it can be installed, copy it to the root-path of the repository, e.g.: | ||
+ | <code bash>cp public.key public.key / | ||
+ | |||
+ | Also export the secret/ | ||
+ | <code bash>gpg --armor --export-secret-keys <ID> > private.key</ | ||
+ | **Remind to store this file carefully!** | ||
+ | |||
+ | The '' | ||
+ | |||
+ | If getting the error '' | ||
+ | <code bash> | ||
+ | |||
+ | //Sourced from [[https:// | ||
+ | |||
+ | ==== Create Release files ==== | ||
+ | To create the Packages, Contents and Release files we use the command '' | ||
+ | |||
+ | '' | ||
+ | ++++ Show/Hide files | | ||
+ | < | ||
+ | **'' | ||
+ | <code bash> | ||
+ | Dir:: | ||
+ | Dir:: | ||
+ | TreeDefault:: | ||
+ | TreeDefault:: | ||
+ | Default:: | ||
+ | Default:: | ||
+ | Default:: | ||
+ | Default:: | ||
+ | |||
+ | Tree " | ||
+ | Sections " | ||
+ | Architectures "armhf amd64 arm64"; | ||
+ | }; | ||
+ | </ | ||
+ | </ | ||
+ | < | ||
+ | **'' | ||
+ | <code bash> | ||
+ | APT:: | ||
+ | Origin " | ||
+ | Label " | ||
+ | Suite " | ||
+ | Codename " | ||
+ | Architectures "amd64 i386 arm64 armhf"; | ||
+ | Components " | ||
+ | Description "My first repository!"; | ||
+ | Version " | ||
+ | }; | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | <callout type=" | ||
+ | ++++ | ||
+ | Now create the '' | ||
+ | <code bash> | ||
+ | |||
+ | Next create the unsigned '' | ||
+ | <code bash> | ||
+ | In this case '' | ||
+ | |||
+ | More information about the Release files can be found here: [[https:// | ||
+ | |||
+ | ==== Sign Release file ==== | ||
+ | Firstly create the '' | ||
+ | <code bash>gpg --yes --pinentry-mode loopback --default-key <ID> -abs -o < | ||
+ | '' | ||
+ | |||
+ | And finally create the '' | ||
+ | <code bash>gpg --yes --pinentry-mode loopback --default-key <ID> --clearsign -o < | ||
+ | This file will later be sourced from APT to index the repository. | ||
+ | |||
+ | |||
+ | ==== Add custom repository ==== | ||
+ | Finally add your local repository. There are several ways: | ||
+ | |||
+ | === Proper way === | ||
+ | Firstly install the key: | ||
+ | <code bash> | ||
+ | The command gets the file, dearmors the downloaded file and saves the content (key) to a file within the keysrings directory. The ''> | ||
+ | |||
+ | Then add the repository to ''/ | ||
+ | <code bash> | ||
+ | |||
+ | Now '' | ||
+ | <code bash> | ||
+ | |||
+ | === Deprecated ways === | ||
+ | The most simple way is to ' | ||
+ | <code bash> | ||
+ | But this will show warnings (! not errors), everytime you update., because it's a legacy method to store keys for apt-repositories. | ||
+ | |||
+ | There' | ||
+ | <code bash> | ||
+ | It works also but isn't expected from the APT developers, consider using the method described above in this guide. | ||
+ | |||
+ | For both methods the repository has to be added this way: | ||
+ | <code bash> | ||
+ | With content: | ||
+ | <code bash> | ||
+ | # local - repository | ||
+ | deb http:// | ||
+ | </ | ||
+ | |||
+ | ==== Repository extensions ==== | ||
+ | There is a little helper when self-hosting a repository, more information can be found here: [[linux: | ||
+ | |||
+ | ----- | ||
+ | ==== Additional settings ==== | ||
+ | < | ||
+ | < | ||
+ | When using a standard dir as '' | ||
+ | <code bash> | ||
+ | find ~/.gnupg -type f -exec chmod 600 {} \; | ||
+ | find ~/.gnupg -type d -exec chmod 700 {} \; | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | **Explanation for '' | ||
+ | |||
+ | Lets start from the back: '' | ||
+ | |||
+ | That means, that the process reading these (gnupg) must run as the owner of these files/ | ||
+ | |||
+ | '' | ||
+ | |||
+ | Both '' | ||
+ | |||
+ | ⇒ Only the owner of the files can read/write them now (=600). Only he can enter into the directory as well (=700) | ||
+ | |||
+ | ⇒ These file rights don't " | ||
+ | |||
+ | More info about permission notation: [[https:// | ||
+ | </ | ||
+ | |||
+ | //Sourced from [[https:// | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | < | ||
+ | Sign '' | ||
+ | <code bash>gpg --yes --pinentry-mode loopback --passphrase-file / | ||
+ | </ | ||
+ | |||
+ | ----- | ||
+ | === Sources === | ||
+ | This guide was sourced from several pages: | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ----- | ||
+ | ==== Other helpful commands ==== | ||
+ | |||
+ | Create Packages file with '' | ||
+ | <code bash> | ||
+ | Create compressed Packages file: | ||
+ | <code bash>cat dists/ | ||
+ | |||
+ | Generate Package files: | ||
+ | <code bash> | ||
+ | |||
+ | Create Release file: | ||
+ | <code bash> | ||
+ | |||
+ | Signing Release file: | ||
+ | <code bash>gpg --default-key <ID> -abs -o Release.gpg Release</ | ||
+ | |||
+ | Signing InRelease file: | ||
+ | <code bash>gpg --default-key <ID> --clearsign -o InRelease Release</ | ||
+ | |||
+ | Apache config to hide .db files from apt-ftparchive, | ||
+ | <code bash> | ||
+ | <Files packages-amd64.db> | ||
+ | Require all denied | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | Automated file signing of password protected keys: [[https:// | ||
+ | |||