diff options
-rw-r--r-- | .SRCINFO | 13 | ||||
-rw-r--r-- | .gitignore | 3 | ||||
-rw-r--r-- | PKGBUILD | 25 | ||||
-rwxr-xr-x | dir-dlagent | 77 |
4 files changed, 118 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO new file mode 100644 index 000000000000..7095098cfcea --- /dev/null +++ b/.SRCINFO @@ -0,0 +1,13 @@ +pkgbase = dir-dlagent + pkgdesc = A makepkg DLAGENT which forwards requests to configured directories + pkgver = 1 + pkgrel = 1 + url = https://aur.archlinux.org/packages/dir-dlagent + arch = any + license = GPL3 + depends = bash + source = dir-dlagent + sha1sums = f3728308f955bf748d2e713ba41712cbcf86fb31 + +pkgname = dir-dlagent + diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000000..924dfb95c209 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +pkg/ +src/ +*.tar.* diff --git a/PKGBUILD b/PKGBUILD new file mode 100644 index 000000000000..d855a6dedc49 --- /dev/null +++ b/PKGBUILD @@ -0,0 +1,25 @@ +# Maintainer: Cody P Schafer < aur [at] codyps.com > +pkgname=dir-dlagent +pkgver=1 +pkgrel=1 +pkgdesc="A makepkg DLAGENT which forwards requests to configured directories" +arch=('any') +url="https://aur.archlinux.org/packages/dir-dlagent" +license=('GPL3') +depends=('bash') +makedepends=() +checkdepends=() +optdepends=() +provides=() +conflicts=() +install= +options=() + +source=( + dir-dlagent +) +package() { + install -d -m 0755 "${pkgdir}/usr/bin" + install -m 755 dir-dlagent "${pkgdir}/usr/bin" +} +sha1sums=('f3728308f955bf748d2e713ba41712cbcf86fb31') diff --git a/dir-dlagent b/dir-dlagent new file mode 100755 index 000000000000..dd59570500ec --- /dev/null +++ b/dir-dlagent @@ -0,0 +1,77 @@ +#! /bin/bash +set -euf -o pipefail +: ${DIR_DLAGENT_DEBUG:=0} + +usage() { + >&2 echo "Usage: $0 dir://dir-spec/path/to/file.txt <output>" + >&2 echo "Usage: $0 %u %o" + exit 1 +} + +debug() { + if [[ "$DIR_DLAGENT_DEBUG" -gt 0 ]]; then + >&2 echo "DEBUG: $@" + fi +} + +# TODO: also use other XDG_CONFIG_DIRS +: ${XDG_CONFIG_HOME:=$HOME/.config} +CONFIG=$XDG_CONFIG_HOME/dir-dlagent.conf +if [[ -e "$CONFIG" ]]; then + source "$CONFIG" +fi + +# TODO: check that `dir=()` exists +# TODO: validate ${dir[@]} + +if [[ $# -ne 2 ]]; then + >&2 echo "Error: got $# arguments instead of 2" + usage +fi + +url="$1" +out="$2" +case "$url" in +dir://*) + base_uri="${url##dir://}" + debug "base_uri=$base_uri" + ;; +*) + >&2 echo "Error: url does not start with dir:// : $url" + exit 1 + ;; +esac + +case "$base_uri" in +*/*) + dir_spec="${base_uri%%/*}" + subpath="${base_uri:${#dir_spec}}" + subpath="${subpath:1}" + debug "dir_spec=$dir_spec" + debug "subpath=$subpath" + ;; +*) + >&2 echo "Error: url does not contain a dir-spec : $url" + exit 1 + ;; +esac + +for e in "${dirs[@]}"; do + this_base="${e%%::*}" + this_path="${e:${#this_base}}" + this_path="${this_path:2}" + debug "checking map '$e' => '$this_base' :: '$this_path'" + if [[ "${this_base}" = "${dir_spec}" ]]; then + src="${this_path}/${subpath}" + debug "Copying file: '${src}' to '${out}'" + cp --no-preserve=all "${src}" "${out}" || { + echo "Error: could not copy file from '${src}' to '${out}'" + exit 1 + } + exit 0 + fi +done + +>&2 echo "Error: no map found for dir-spec $dir_spec in url $url" +>&2 echo "Note: add 'dirs+=(\"$dir_spec::/my/path/here\")' to $CONFIG to fix" +exit 1 |