diff options
author | David Runge <dave@sleepmap.de> | 2021-02-07 15:50:10 +0100 |
---|---|---|
committer | David Runge <dave@sleepmap.de> | 2021-02-07 15:50:10 +0100 |
commit | c328c206598185b05cd0f178ce09a776be61fb76 (patch) | |
tree | 87926caab0a48b277c045010f2775a71454bde0e /.zsh.functions | |
parent | ee6181780964dc4c7c5728da277151e22f7046f4 (diff) | |
download | dotfiles-c328c206598185b05cd0f178ce09a776be61fb76.tar.gz dotfiles-c328c206598185b05cd0f178ce09a776be61fb76.tar.bz2 dotfiles-c328c206598185b05cd0f178ce09a776be61fb76.tar.xz dotfiles-c328c206598185b05cd0f178ce09a776be61fb76.zip |
Add packaging helper functions
.zsh.functions/packaging.zsh:
Add functions useful for packaging, such as for signing packages or
adding packages to a database and for sshfs mounting.
Diffstat (limited to '.zsh.functions')
-rw-r--r-- | .zsh.functions/packaging.zsh | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/.zsh.functions/packaging.zsh b/.zsh.functions/packaging.zsh new file mode 100644 index 0000000..72627c7 --- /dev/null +++ b/.zsh.functions/packaging.zsh @@ -0,0 +1,86 @@ +#!/usr/bin/env zsh + +pkg_sign() { + # sign one or more packages with the key setup in makepkg.conf + local _pkg_list=() + local _arg _pkg + + # get GPGKEY from makepkg.conf + if [[ -f /etc/makepkg.conf ]]; then + source /etc/makepkg.conf 2>/dev/null 1>&2 + fi + if [[ -f "${HOME}/.makepkg.conf" ]]; then + source "${HOME}/.makepkg.conf" 2>/dev/null 1>&2 + fi + if [[ -z "${GPGKEY}" ]]; then + 1>&2 printf "No GPGKEY is setup in makepkg.conf!\n" + return 1 + fi + + # check whether file(s) exists or globs exist + for _arg in "$@"; do + if [[ -f "${_arg}" ]] && [[ "${_arg}" == *.pkg.tar.zst ]]; then + _pkg_list+=( "${_arg}" ) + fi + if [[ -n *"${_arg}"*.pkg.tar.zst(#qN) ]]; then + _pkg_list+=( *"${_arg}"*.pkg.tar.zst ) + fi + done + + # sign package(s) + if (( ${#_pkg_list} > 0 )); then + for _pkg in "${_pkg_list[@]}"; do + gpg --detach-sign --local-user "${GPGKEY}" "$_pkg" + done + return 0 + else + 1>&2 printf "No package can be found for signing!\n" + return 1 + fi +} + +pkg_add() { + # sign one or more packages with the key setup in makepkg.conf + local _pkg_list=() + local _arg + + # get GPGKEY from makepkg.conf + if [[ -f /etc/makepkg.conf ]]; then + source /etc/makepkg.conf 2>/dev/null 1>&2 + fi + if [[ -f "${HOME}/.makepkg.conf" ]]; then + source "${HOME}/.makepkg.conf" 2>/dev/null 1>&2 + fi + if [[ -z "${GPGKEY}" ]]; then + 1>&2 printf "No GPGKEY is setup in makepkg.conf!\n" + return 1 + fi + + # check whether file(s) exists or globs exist + for _arg in "$@"; do + if [[ -f "${_arg}" ]] && [[ "$_arg" == *.pkg.tar.zst ]]; then + _pkg_list+=( "${_arg}" ) + fi + if [[ -n *"${_arg}"*.pkg.tar.zst(#qN) ]]; then + _pkg_list+=( *"${_arg}"*.pkg.tar.zst ) + fi + done + + # add package(s) to repo database + if (( ${#_pkg_list} > 0 )); then + repo-add -R -s -k "${GPGKEY}" "$(dirname "${_pkg_list[1]}")"/*.db.tar.gz "${_pkg_list[@]}" + return 0 + else + 1>&2 printf "No packages to add can be found!\n" + return 1 + fi +} + +sshfs_mount() { + mkdir -p "${HOME}/mounts/$1" + sshfs -C -F "${HOME}/.ssh/config" "$1": "${HOME}/mounts/$1" +} + +sshfs_umount() { + fusermount3 -u "${HOME}/mounts/$1" +} |