├── .dir-locals.el ├── .github └── workflows │ ├── freight-man-pages.yml │ └── freight-tests.yml ├── .gitignore ├── .travis.yml ├── Dockerfile ├── LICENSE ├── Makefile ├── NOTES ├── README.md ├── bin ├── freight ├── freight-add ├── freight-cache ├── freight-clear-cache └── freight-init ├── debian ├── .gitignore ├── changelog ├── compat ├── control └── rules ├── etc ├── bash_completion.d │ └── freight ├── freight.conf.example └── profile.d │ └── freight.sh ├── lib └── freight │ ├── apt.sh │ └── conf.sh ├── man ├── man1 │ ├── freight-add.1 │ ├── freight-add.1.ronn │ ├── freight-cache.1 │ ├── freight-cache.1.ronn │ ├── freight-clear-cache.1 │ ├── freight-clear-cache.1.ronn │ ├── freight-init.1 │ ├── freight-init.1.ronn │ ├── freight.1 │ └── freight.1.ronn └── man5 │ ├── freight.5 │ └── freight.5.ronn └── test ├── apt_add.bats ├── apt_cache.bats ├── apt_cache_source.bats ├── apt_helpers.bash ├── fixtures ├── apt.conf ├── first_key.gpg ├── gpg.conf ├── gpg2.conf ├── passphrase ├── second_key.gpg ├── source-git_1.0-1.dsc ├── source-git_1.0-1.git ├── source_1.0-1.dsc ├── source_1.0-1.tar.bz2 ├── source_1.0-1.tar.gz ├── source_1.0-1.tar.lzma ├── source_1.0-1.tar.xz ├── source_1.0.orig.tar.gz └── test_1.0_all.deb └── freight_helpers.bash /.dir-locals.el: -------------------------------------------------------------------------------- 1 | ;;; Directory Local Variables 2 | ;;; For more information see (info "(emacs) Directory Variables") 3 | 4 | ((sh-mode . ((sh-basic-offset . 4)))) 5 | -------------------------------------------------------------------------------- /.github/workflows/freight-man-pages.yml: -------------------------------------------------------------------------------- 1 | name: freight-man-pages 2 | on: [push, pull_request] 3 | jobs: 4 | generate-manpages: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - uses: actions/checkout@v2 8 | - name: Install prerequisites 9 | run: >- 10 | sudo apt-get update 11 | 12 | sudo apt-get install -y 13 | ronn 14 | 15 | - name: Generate manpages 16 | run: make man 17 | -------------------------------------------------------------------------------- /.github/workflows/freight-tests.yml: -------------------------------------------------------------------------------- 1 | name: freight-tests 2 | on: [push, pull_request] 3 | jobs: 4 | perform-bash-ci: 5 | runs-on: ubuntu-latest 6 | env: 7 | GPG_TTY: $(tty) 8 | steps: 9 | - uses: actions/checkout@v2 10 | - run: find bin lib -type f | xargs shellcheck -s sh 11 | - run: make check 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.html 3 | *.deb 4 | *.dsc 5 | *.debian.tar.gz 6 | *.diff.gz 7 | *.orig.tar.gz 8 | *.tar.gz 9 | *~ 10 | .idea/ 11 | etc/freight.conf 12 | var 13 | test/tmp 14 | !test/fixtures/* 15 | debian/freight* 16 | debian/files 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | env: 3 | - SH=dash 4 | - SH=bash 5 | script: 6 | - find bin lib -type f | xargs shellcheck -s sh 7 | - shfmt -i 4 -ci -p -l -s -w lib/ bin/ 8 | - git diff --exit-code 9 | - make check 10 | notifications: 11 | irc: "chat.freenode.net#freight" 12 | dist: xenial 13 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:lunar 2 | 3 | RUN apt update && apt install -y git make gnupg 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2010 Richard Crowley. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | 2. Redistributions in binary form must reproduce the above 11 | copyright notice, this list of conditions and the following 12 | disclaimer in the documentation and/or other materials provided 13 | with the distribution. 14 | 15 | THIS SOFTWARE IS PROVIDED BY RICHARD CROWLEY ``AS IS'' AND ANY EXPRESS 16 | OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL RICHARD CROWLEY OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 25 | THE POSSIBILITY OF SUCH DAMAGE. 26 | 27 | The views and conclusions contained in the software and documentation 28 | are those of the authors and should not be interpreted as representing 29 | official policies, either expressed or implied, of Richard Crowley. 30 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | VERSION=0.3.12 2 | BUILD=1 3 | 4 | SH=dash 5 | 6 | prefix=/usr/local 7 | bindir=${prefix}/bin 8 | libdir=${prefix}/lib 9 | sysconfdir=${prefix}/etc 10 | mandir=${prefix}/share/man 11 | 12 | all: 13 | 14 | clean: 15 | rm -rf *.deb deb man/man*/*.html test/tmp 16 | find . -name '*~' -delete 17 | 18 | install: install-bin install-lib install-man install-sysconf 19 | 20 | install-bin: 21 | find bin -type f -printf %P\\0 | xargs -0r -I__ install -D bin/__ $(DESTDIR)$(bindir)/__ 22 | 23 | install-lib: 24 | find lib -type f -printf %P\\0 | xargs -0r -I__ install -m644 -D lib/__ $(DESTDIR)$(libdir)/__ 25 | 26 | install-man: 27 | find man -type f -name \*.[12345678] -printf %P\\0 | xargs -0r -I__ install -m644 -D man/__ $(DESTDIR)$(mandir)/__ 28 | find man -type f -name \*.[12345678] -printf %P\\0 | xargs -0r -I__ gzip -f $(DESTDIR)$(mandir)/__ 29 | 30 | install-sysconf: 31 | find etc -type f -not -name freight.conf -printf %P\\0 | xargs -0r -I__ install -m644 -D etc/__ $(DESTDIR)$(sysconfdir)/__ 32 | 33 | uninstall: uninstall-bin uninstall-lib uninstall-man uninstall-sysconf 34 | 35 | uninstall-bin: 36 | find bin -type f -printf %P\\0 | xargs -0r -I__ rm -f $(DESTDIR)$(bindir)/__ 37 | rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(bindir) || true 38 | 39 | uninstall-lib: 40 | find lib -type f -printf %P\\0 | xargs -0r -I__ rm -f $(DESTDIR)$(libdir)/__ 41 | find lib -depth -mindepth 1 -type d -printf %P\\0 | xargs -0r -I__ rmdir $(DESTDIR)$(libdir)/__ || true 42 | rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(libdir) || true 43 | 44 | uninstall-man: 45 | find man -type f -name \*.[12345678] -printf %P\\0 | xargs -0r -I__ rm -f $(DESTDIR)$(mandir)/__.gz 46 | find man -depth -mindepth 1 -type d -printf %P\\0 | xargs -0r -I__ rmdir $(DESTDIR)$(mandir)/__ || true 47 | rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(mandir) || true 48 | 49 | uninstall-sysconf: 50 | find etc -type f -printf %P\\0 | xargs -0r -I__ rm -f $(DESTDIR)$(sysconfdir)/__ 51 | find etc -depth -mindepth 1 -type d -printf %P\\0 | xargs -0r -I__ rmdir $(DESTDIR)$(sysconfdir)/__ || true 52 | rmdir -p --ignore-fail-on-non-empty $(DESTDIR)$(sysconfdir) || true 53 | 54 | build: 55 | make install prefix=/usr sysconfdir=/etc DESTDIR=deb 56 | fpm -s dir -t deb \ 57 | -n freight -v $(VERSION) --iteration $(BUILD) -a all \ 58 | -d coreutils -d dash -d dpkg -d gnupg -d grep \ 59 | -m "Richard Crowley " \ 60 | --url "https://github.com/freight-team/freight" \ 61 | --description "A modern take on the Debian archive." \ 62 | -C deb . 63 | make uninstall prefix=/usr sysconfdir=/etc DESTDIR=deb 64 | 65 | man: 66 | find man -name \*.ronn | xargs -n1 ronn --manual=Freight --style=toc 67 | 68 | docs: 69 | for SH in $$(find bin lib -type f -not -name \*.html); do \ 70 | shocco $$SH >$$SH.html; \ 71 | done 72 | 73 | gh-pages: man 74 | mkdir -p gh-pages 75 | find man -name \*.html | xargs -I__ mv __ gh-pages/ 76 | git checkout -q gh-pages 77 | cp -R gh-pages/* ./ 78 | rm -rf gh-pages 79 | git add . 80 | git commit -m "Rebuilt manual." 81 | git push origin gh-pages 82 | git checkout -q master 83 | 84 | test/tmp/bats: 85 | git clone --depth 1 https://github.com/bats-core/bats-core.git test/tmp/bats 86 | 87 | test/tmp/bats-assert: 88 | git clone --depth 1 https://github.com/jasonkarns/bats-assert.git test/tmp/bats-assert 89 | 90 | test/tmp/bin: 91 | mkdir -p test/tmp/bin 92 | 93 | test/tmp/bin/sh: test/tmp/bin 94 | ln -sf $$(which $(SH)) test/tmp/bin/sh 95 | 96 | check: test/tmp/bats test/tmp/bats-assert test/tmp/bin/sh 97 | PATH=test/tmp/bin/:$$PATH test/tmp/bats/bin/bats test/ 98 | 99 | .PHONY: all clean install uninstall build man docs gh-pages check 100 | -------------------------------------------------------------------------------- /NOTES: -------------------------------------------------------------------------------- 1 | Store repositories in a root as /var/lib/freight///. 2 | "Compile" to /var/cache/freight. 3 | 4 | freight-add /... 5 | Copy and hard link into place in each / 6 | If you do backups, make sure to use the -H option to rsync(1). 7 | Don't have to copy if we're on the same device. 8 | (Optionally) remove files from each distro that start with "_". 9 | 10 | freight-cache /... 11 | Sort the packages in each distro. 12 | Build a Packages file for each architecture mentioned. 13 | Grab the control file from each package. 14 | Augment it with Size, MD5Sum, SHA1, SHA256, and Filename. 15 | Make sure Package is first, Version is second, and Description is last. 16 | gzip every Packages file. 17 | Build the Release file for each architecture mentioned. 18 | Build the Release file with the checksums for each contained Release and Packages file. 19 | gpg sign the Release file. 20 | 21 | Default directories? 22 | /var/lib/freight// 23 | /var/cache/freight///{dists,pool} 24 | 25 | For Debian-style, all that's important is the dists/ hierarchy? 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Freight 2 | 3 | [![IRC channel](https://kiwiirc.com/buttons/irc.freenode.net/freight.png)](https://kiwiirc.com/client/irc.freenode.net/?#freight) 4 | [![Build Status](https://travis-ci.org/freight-team/freight.svg?branch=master)](https://travis-ci.org/freight-team/freight) 5 | 6 | A modern take on the Debian archive. 7 | 8 | This repository has been forked (in the traditional sense of the word) from 9 | Richard Crowley's [freight](https://github.com/rcrowley/freight) repository. A 10 | fork had become necessary because the main project was not actively maintained 11 | and serious issues had started to crop up. While fixes and improvements were 12 | available in various freight GitHub forks, they were not merged to the main 13 | project. This fork and the associated GitHub organization, 14 | [freight-team](https://github.com/freight-team), attempts to fix these issues. 15 | 16 | ## Usage 17 | 18 | Install Freight and create a minimal configuration in `/usr/local/etc/freight.conf` or `/etc/freight.conf` as appropriate containing the name of your GPG key: 19 | 20 | GPG="example@example.com" 21 | 22 | Add packages to particular distros: 23 | 24 | freight add foobar_1.2.3-1_all.deb apt/squeeze apt/lucid apt/natty 25 | 26 | Build the cache of all the files needed to be accepted as a Debian archive: 27 | 28 | freight cache 29 | 30 | If your system has GnuPG 2.x make sure that a gpg-agent is running and that you 31 | have installed a pinentry package (e.g. pinentry-curses) that suits your needs. 32 | On freight 0.3.11 and older you may also need to set the GPG_TTY environment 33 | variable like this: 34 | 35 | export GPG_TTY=$(tty) 36 | 37 | Serve `/var/cache/freight` via your favorite web server and install it as an APT source: 38 | 39 | echo "deb http://example.com $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/example.list 40 | sudo wget -O /etc/apt/trusted.gpg.d/example.gpg http://example.com/keyring.gpg 41 | sudo apt-get update 42 | sudo apt-get -y install foobar 43 | 44 | Make sure your webserver is configured to follow symlinks inside of the hosted directory. 45 | 46 | ## Installation 47 | 48 | ### From source 49 | 50 | git clone https://github.com/freight-team/freight.git 51 | cd freight && make && sudo make install 52 | 53 | ### From a Debian archive 54 | 55 | wget -O - https://swupdate.openvpn.net/repos/repo-public.gpg|sudo apt-key add - 56 | echo "deb http://build.openvpn.net/debian/freight_team $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/freight.list 57 | sudo apt-get update 58 | sudo apt-get -y install freight 59 | 60 | ### From a custom-made Debian package 61 | 62 | You need `build-essential` package installed. Clone the freight repository, build a package and install it: 63 | 64 | git clone https://github.com/freight-team/freight.git 65 | cd freight && dpkg-buildpackage -uc -us -b 66 | sudo dpkg -i ../freight_-_all.deb 67 | 68 | ### From Fedora/EPEL repositories 69 | 70 | EL users must first [configure EPEL](http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F). 71 | 72 | yum -y install freight 73 | 74 | ## Documentation 75 | 76 | * [Debian packaging for busy people](http://rcrowley.org/articles/packaging.html) 77 | 78 | There's also [French documentation](http://blog.valouille.fr/2014/03/creer-un-depot-debian-signe-avec-freight/) assembled by Valérian Beaudoin. 79 | 80 | ## Manuals 81 | 82 | * [`freight`(1)](http://freight-team.github.io/freight/freight.1.html) 83 | * [`freight-add`(1)](http://freight-team.github.io/freight/freight-add.1.html) 84 | * [`freight-cache`(1)](http://freight-team.github.io/freight/freight-cache.1.html) 85 | * [`freight-clear-cache`(1)](http://freight-team.github.io/freight/freight-clear-cache.1.html) 86 | * [`freight-init`(1)](http://freight-team.github.io/freight/freight-init.1.html) 87 | * [`freight`(5)](http://freight-team.github.io/freight/freight.5.html) 88 | 89 | ## Contribute 90 | 91 | Freight is [BSD-licensed](https://github.com/freight-team/freight/blob/master/LICENSE) 92 | 93 | * Source code: 94 | * Issue tracker: 95 | * Wiki: 96 | 97 | ### Static analysis and code style 98 | 99 | [Shellcheck](https://www.shellcheck.net/) and [shfmt](https://github.com/mvdan/sh) are used to ensure consistency, please see the Travis configuration for the actual tests. 100 | 101 | ### Test suite 102 | 103 | The Freight test suite can be executed by running `make check` from any git checkout of this repository. git and GnuPG are required for most tests, and extended tests require apt. 104 | 105 | Contributions should include a new test case where possible by extending one or more of the `test/*.bats` files. 106 | 107 | #### Running tests in Docker 108 | 109 | It's easy to run the full test suite in Docker. The following command will build 110 | a Docker image with the necessary packages and run `make check` inside a Docker 111 | container: 112 | 113 | ```sh 114 | docker run -ti --rm -v $(pwd):/freight -u $(id -u) -w /freight $(docker build -q .) make check 115 | ``` 116 | -------------------------------------------------------------------------------- /bin/freight: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # `freight` dispatches to `freight-*` commands. 4 | 5 | set -e 6 | 7 | # Just like the DevStructure tools, which try to be just like Git, accept 8 | # a subcommand that really just completes the name of a real command. 9 | COMMAND=$0-$1 10 | [ -x "$COMMAND" ] && { 11 | shift 12 | exec "$COMMAND" "$@" 13 | } 14 | 15 | # Be helpful in this case since no subcommand was found. 16 | echo "Usage: $(basename "$0") [...]" >&2 17 | echo "Common commands: add cache init" >&2 18 | echo "See all available commands by typing \"$(basename "$0")-\"" >&2 19 | exit 1 20 | 21 | # vim: et:ts=4:sw=4 22 | -------------------------------------------------------------------------------- /bin/freight-add: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # shellcheck disable=SC1090 3 | 4 | # Add a package to the Freight library. 5 | 6 | #/ Usage: freight add [-c ] [-v] [-h] /... 7 | #/ -c , --conf= config file to parse 8 | #/ -v, --verbose verbose mode 9 | #/ -e, --add-error exit with error if package already added 10 | #/ -h, --help show this help message 11 | 12 | set -e 13 | 14 | usage() { 15 | grep "^#/" "$0" | cut -c"4-" >&2 16 | exit "$1" 17 | } 18 | while [ "$#" -gt 0 ]; do 19 | case "$1" in 20 | -c | --conf) CONF="$2" shift 2 ;; 21 | -c*) CONF="$(echo "$1" | cut -c"3-")" shift ;; 22 | --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift ;; 23 | -v | --verbose) VERBOSE=1 shift ;; 24 | -e | --add-error) FREIGHT_ADD_ERROR="YES" shift ;; 25 | -h | --help) usage 0 ;; 26 | -*) 27 | echo "# [freight] unknown switch: $1" >&2 28 | usage 1 29 | ;; 30 | *) break ;; 31 | esac 32 | done 33 | 34 | . "$(dirname "$(dirname "$0")")/lib/freight/conf.sh" 35 | 36 | # The non-option argument(s) following the last option are package files. 37 | # Binary packages have only one but source packages require two or three. 38 | # When the last of these is found, the remaining arguments are each assumed 39 | # to be `/` pairs for this (source) package. 40 | while [ "$#" -gt 0 ]; do 41 | case "$1" in 42 | *.deb | *.ddeb | *.udeb | *.dsc | *.orig.tar.gz | *.orig.tar.bz2 | *.orig.tar.xz | *.orig.tar.lzma | *.diff.gz | *.debian.tar.gz | *.debian.tar.bz2 | *.debian.tar.xz | *.debian.tar.lzma | *.tar.gz | *.tar.bz2 | *.tar.xz | *.tar.lzma | *.git) 43 | # shellcheck disable=SC2153 44 | PATHNAMES="$PATHNAMES $1" shift 45 | ;; 46 | *.build | *.changes) shift ;; 47 | *) break ;; 48 | esac 49 | done 50 | [ -z "$PATHNAMES" ] && usage 1 51 | [ -z "$*" ] && usage 1 52 | 53 | # Create a working directory on the same device as the Freight library and 54 | # copy this package there. This used to be a link but is now a copy because 55 | # later Freight commands will rely on the link count being reduced to one. 56 | mkdir -p "$VARLIB" 57 | TMP="$(mktemp -d "$VARLIB/freight.$$.XXXXXXXXXX")" 58 | # shellcheck disable=SC2064 59 | trap "rm -rf \"$TMP\"" EXIT INT TERM 60 | for PATHNAME in $PATHNAMES; do 61 | cp "$PATHNAME" "$TMP/" 62 | done 63 | 64 | # Enter the Freight library directory so that items in `$@` may be given as 65 | # absolute paths or as partial paths of the form `/` that 66 | # are ultimately taken relative to the Freight library. 67 | cd "$VARLIB" 68 | 69 | # Add a file to the Freight library. The arguments are FILENAME, DIRNAME, and 70 | # PATHNAME. The first two are given fairly directly to ln(1); the final one 71 | # is used to create appropriate success or failure messages. 72 | add() { 73 | if ln "$TMP/$1" "$2/$1" 2>"$TMP/ln"; then 74 | echo "# [freight] added $3 to $2${4+" as "}$4" >&2 75 | else 76 | if grep -q "File exists" "$TMP/ln"; then 77 | echo "# [freight] $2 already has $3${4+" as "}$4" >&2 78 | else 79 | cat "$TMP/ln" >&2 80 | fi 81 | if [ -n "$FREIGHT_ADD_ERROR" ]; then 82 | exit 2 83 | fi 84 | fi 85 | } 86 | 87 | # Hard link this package into every `/` given in `$@`. 88 | # These links will later be used to compile the `Release` and `Packages` 89 | # files in the Freight cache. 90 | for PATHNAME in $PATHNAMES; do 91 | FILENAME="$(basename "$PATHNAME")" 92 | for DIRNAME in "$@"; do 93 | mkdir -p "$DIRNAME" 94 | case "$FILENAME" in 95 | *_*_*.deb | *_*_*.ddeb | *_*_*.udeb) add "$FILENAME" "$DIRNAME" "$PATHNAME" ;; 96 | *.deb | *.ddeb | *.udeb) 97 | . "$(dirname "$(dirname "$0")")/lib/freight/apt.sh" 98 | dpkg-deb -I "$TMP/$FILENAME" "control" >"$TMP/$FILENAME-control" 99 | DEBNAME="$( 100 | apt_binary_name "$TMP/$FILENAME-control" 101 | )_$( 102 | apt_binary_version "$TMP/$FILENAME-control" 103 | )_$( 104 | apt_binary_arch "$TMP/$FILENAME-control" 105 | ).${FILENAME##*.}" 106 | add "$FILENAME" "$DIRNAME" "$PATHNAME" "$DEBNAME" 107 | ;; 108 | *) add "$FILENAME" "$DIRNAME" "$PATHNAME" ;; 109 | esac 110 | done 111 | done 112 | 113 | # vim: et:ts=4:sw=4 114 | -------------------------------------------------------------------------------- /bin/freight-cache: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # shellcheck disable=SC1090 3 | 4 | # Rebuild the Freight cache from the Freight library. The cache contains 5 | # actual repositories that are suitable targets for `apt-get` (and maybe 6 | # more in the future). 7 | 8 | #/ Usage: freight cache [-k] [-g ] [-p ] [-a ] [-c ] [-v] [-h] [/][...] 9 | #/ -k, --keep keep unreferenced versions of packages 10 | #/ -g , --gpg= GPG key to use, may be given multiple times 11 | #/ -p , 12 | #/ --passphrase-file= path to file containing the passphrase of the GPG key 13 | #/ -a , 14 | #/ --digest-algo= digest algorithm that GPG should use, e.g SHA512 15 | #/ -c , --conf= config file to parse 16 | #/ -v, --verbose verbose mode 17 | #/ -h, --help show this help message 18 | 19 | set -e 20 | 21 | usage() { 22 | grep "^#/" "$0" | cut -c"4-" >&2 23 | exit "$1" 24 | } 25 | while [ "$#" -gt 0 ]; do 26 | case "$1" in 27 | -k | --keep) KEEP=1 shift ;; 28 | -g | --gpg) 29 | if [ -z "$GPG" ]; then 30 | GPG=$2 31 | else 32 | GPG="$GPG $2" 33 | fi 34 | shift 2 35 | ;; 36 | -g*) 37 | if [ -z "$GPG" ]; then 38 | GPG=$(echo "$1" | cut -c"3-") 39 | else 40 | GPG="$GPG $(echo "$1" | cut -c"3-")" 41 | fi 42 | shift 43 | ;; 44 | --gpg=*) 45 | if [ -z "$GPG" ]; then 46 | GPG=$(echo "$1" | cut -c"7-") 47 | else 48 | GPG="$GPG $(echo "$1" | cut -c"7-")" 49 | fi 50 | shift 51 | ;; 52 | -p | --passphrase-file) GPG_PASSPHRASE_FILE="$2" shift 2 ;; 53 | -p*) GPG_PASSPHRASE_FILE="$(echo "$1" | cut -c"3-")" shift ;; 54 | --passphrase-file=*) GPG_PASSPHRASE_FILE="$(echo "$1" | cut -c"19-")" shift ;; 55 | -a | --digest-algo) GPG_DIGEST_ALGO="$2" shift 2 ;; 56 | -a*) GPG_DIGEST_ALGO="$(echo "$1" | cut -c"3-")" shift ;; 57 | --digest-algo=*) GPG_DIGEST_ALGO="$(echo "$1" | cut -c"15-")" shift ;; 58 | -c | --conf) CONF="$2" shift 2 ;; 59 | -c*) CONF="$(echo "$1" | cut -c"3-")" shift ;; 60 | --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift ;; 61 | -v | --verbose) VERBOSE=1 shift ;; 62 | -h | --help) usage 0 ;; 63 | -*) 64 | echo "# [freight] unknown switch: $1" >&2 65 | usage 1 66 | ;; 67 | *) break ;; 68 | esac 69 | done 70 | 71 | LIB="$(cd "$(dirname "$(dirname "$0")")/lib/freight" && pwd)" 72 | # shellcheck source=/dev/null 73 | . "$LIB/conf.sh" 74 | 75 | # If `GPG_PASSPHRASE_FILE` is set the specified file should exist and be 76 | # readable by the user running Freight. 77 | [ -z "$GPG_PASSPHRASE_FILE" ] || [ -r "$GPG_PASSPHRASE_FILE" ] || echo "# [freight] could not read passphrase file: $GPG_PASSPHRASE_FILE." >&2 78 | 79 | # If `GPG_DIGEST_ALGO` is unset, force it to the freight default of SHA512 80 | [ -z "$GPG_DIGEST_ALGO" ] && GPG_DIGEST_ALGO="SHA512" 81 | 82 | # Create a working directory on the same device as the Freight cache. 83 | mkdir -p "$VARCACHE" 84 | TMP="$(mktemp -d "$VARCACHE/work.$$.XXXXXXXXXX")" 85 | # shellcheck disable=SC2064 86 | trap "rm -rf \"$TMP\"" EXIT INT TERM 87 | 88 | # Enter the Freight library directory so that items in `$@` may be given as 89 | # absolute paths or as partial paths of the form `/` that 90 | # are ultimately taken relative to the Freight library. 91 | mkdir -p "$VARLIB" 92 | cd "$VARLIB" 93 | 94 | # Rebuild each distro serially. 95 | if [ -z "$*" ]; then 96 | DIRS="$( 97 | find "$VARLIB"/ -mindepth 2 -maxdepth 2 -type d -printf "%P\n" | 98 | grep -v '^\.' | 99 | tr "\n" " " 100 | )" 101 | else 102 | DIRS=$* 103 | fi 104 | for DIR in $DIRS; do 105 | 106 | # Parse the manager and distro out of the Freight library path. 107 | DIR="$(readlink -f "$DIR")" 108 | DIR="${DIR##"$(readlink -f "$VARLIB")/"}" 109 | MANAGER="$(dirname "$DIR")" 110 | DIST="$(basename "$DIR")" 111 | 112 | # Should we follow symbolic links when finding components to cache? 113 | [ "$SYMLINKS" = "on" ] && FIND_L="-L" || FIND_L="" 114 | 115 | # From here the process is customized on a per-manager basis. The 116 | # sorted list of package filenames comes on `stdin` and the name of 117 | # the distro is the only argument. From there, each manager can do 118 | # whatever it wants. 119 | . "$LIB/$MANAGER.sh" 120 | SORT="$(sort -V <"/dev/null" 2>"/dev/null" && echo "sort -V" || echo "sort")" 121 | # shellcheck disable=SC2086 122 | find $FIND_L "$DIR" -type "f" -printf "%P\n" 2>"/dev/null" | 123 | eval "$SORT" | 124 | eval "${MANAGER}_cache" "$DIST" 125 | 126 | # Clean up old packages as dictated by the manager. 127 | if [ -z "$KEEP" ]; then 128 | eval "${MANAGER}_clean" 129 | fi 130 | 131 | done 132 | 133 | # vim: et:ts=4:sw=4 134 | -------------------------------------------------------------------------------- /bin/freight-clear-cache: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | # shellcheck disable=SC1090 3 | 4 | # Clear the cache that is built up during freight-cache runs 5 | # so that it can be regenerated on the next freight-cache invocation. 6 | 7 | #/ Usage: freight clear-cache [-c ] [-v] [-h] [/][...] 8 | #/ -c , --conf= config file to parse 9 | #/ -v, --verbose verbose mode 10 | #/ -h, --help show this help message 11 | 12 | set -e 13 | 14 | usage() { 15 | grep "^#/" "$0" | cut -c"4-" >&2 16 | exit "$1" 17 | } 18 | while [ "$#" -gt 0 ]; do 19 | case "$1" in 20 | -c | --conf) CONF="$2" shift 2 ;; 21 | -c*) CONF="$(echo "$1" | cut -c"3-")" shift ;; 22 | --conf=*) CONF="$(echo "$1" | cut -c"8-")" shift ;; 23 | -v | --verbose) VERBOSE=1 shift ;; 24 | -h | --help) usage 0 ;; 25 | -*) 26 | echo "# [freight] unknown switch: $1" >&2 27 | usage 1 28 | ;; 29 | *) break ;; 30 | esac 31 | done 32 | 33 | . "$(dirname "$(dirname "$0")")/lib/freight/conf.sh" 34 | 35 | # Create a working directory on the same device as the Freight cache. 36 | mkdir -p "$VARCACHE" 37 | TMP="$(mktemp -d "$VARCACHE/work.$$.XXXXXXXXXX")" 38 | # shellcheck disable=SC2064 39 | trap "rm -rf \"$TMP\"" EXIT INT TERM 40 | 41 | # Enter the Freight library directory so that items in `$@` may be given as 42 | # absolute paths or as partial paths of the form `/` that 43 | # are ultimately taken relative to the Freight library. 44 | mkdir -p "$VARLIB" 45 | cd "$VARLIB" 46 | 47 | # Rebuild each distro serially. 48 | if [ -z "$*" ]; then 49 | DIRS="$( 50 | find "$VARLIB" -mindepth 2 -maxdepth 2 -type d -printf "%P\n" | 51 | grep -v '^\.' | 52 | tr "\n" " " 53 | )" 54 | else 55 | DIRS=$* 56 | fi 57 | for DIR in $DIRS; do 58 | 59 | # Parse the manager and distro out of the Freight library path. 60 | DIR="$(readlink -f "$DIR")" 61 | DIR="${DIR##"$VARLIB/"}" 62 | MANAGER="$(dirname "$DIR")" 63 | DIST="$(basename "$DIR")" 64 | 65 | # From here the process is customized on a per-manager basis. 66 | . "$(dirname "$(dirname "$0")")/lib/freight/$MANAGER.sh" 67 | eval "${MANAGER}_clear_cache" "$DIST" 68 | 69 | done 70 | 71 | # vim: et:ts=4:sw=4 72 | -------------------------------------------------------------------------------- /bin/freight-init: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # Initialize a Freight directory (similar to git init). 4 | 5 | #/ Usage: freight init -g [--libdir=] [--cachedir=] [--archs=] [--origin=] [--label=