From 22117579db0d836f4bf5fc27c9b251d3c9581b68 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Mon, 5 Aug 2024 13:36:05 -0400 Subject: [PATCH] Add initial packaging script (currently only for generating source PKGBUILD) --- .gitignore | 1 + packaging/main.sh | 24 ++++++++++++++ packaging/pkgbuild-git-stable.sh | 54 ++++++++++++++++++++++++++++++++ wiki/MUTN/completions.md | 2 +- 4 files changed, 80 insertions(+), 1 deletion(-) create mode 100755 packaging/main.sh create mode 100644 packaging/pkgbuild-git-stable.sh diff --git a/.gitignore b/.gitignore index 39db666..f802307 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ /mutn.exe /libmuttonserver /libmuttonserver.exe +output diff --git a/packaging/main.sh b/packaging/main.sh new file mode 100755 index 0000000..6bacb20 --- /dev/null +++ b/packaging/main.sh @@ -0,0 +1,24 @@ +#!/bin/sh + +# get version number from backend TODO embed Go code that reads the value of LibmuttonVersion +version=$(grep 'LibmuttonVersion = "' ../src/backend/1globals.go | cut -c22-26) + +# get revision number from user input, fallback to 1 if not provided +if [ -z "$2" ]; then + revision=1 +else + revision="$2" +fi + +# ensure output directory exists +mkdir -p ./output + +case "$1" in + pkgbuild-git-stable) + . ./pkgbuild-git-stable.sh + create_pkgbuild_git_stable + ;; + *) + printf '\nusage: package.sh [target] \n\ntargets: pkgbuild-git-stable\n\n' + ;; +esac diff --git a/packaging/pkgbuild-git-stable.sh b/packaging/pkgbuild-git-stable.sh new file mode 100644 index 0000000..cef9f1c --- /dev/null +++ b/packaging/pkgbuild-git-stable.sh @@ -0,0 +1,54 @@ +#!/bin/sh + +create_pkgbuild_git_stable() { + printf '\ngenerating PKGBUILD...\n' + local source="git+https://github.com/rwinkhart/MUTN.git#tag=v\${pkgver}" + printf "# Maintainer: Randall Winkhart +pkgname=mutn +pkgver="$version" +pkgrel="$revision" +pkgdesc='A simple, self-hosted, SSH-synchronized password/note manager based on libmutton' +arch=('x86_64' 'i686' 'i486' 'pentium4' 'aarch64' 'armv7h' 'riscv64') +url='https://github.com/rwinkhart/MUTN' +license=('MIT') +makedepends=(go util-linux) +optdepends=( + 'wl-clipboard: Wayland clipboard support' + 'xclip: X11 clipboard support' + 'bash-completion: Bash completion support' +) +source=(\""$source"\") +sha512sums=(SKIP) + +build() { + # determine microarchitecture feature level + case \$CARCH in + 'x86_64') + lscpuOutput=\$(lscpu | grep Flags) + if [ -z \"\$(echo \$lscpuOutput | grep avx512f)\" ]; then + export GOAMD64=v4 + elif [ -z \"\$(echo \$lscpuOutput | grep avx2)\" ]; then + export GOAMD64=v3 + elif [ -z \"\$(echo \$lscpuOutput | grep sse4_2)\" ]; then + export GOAMD64=v2 + else + export GOAMD64=v1 + fi + ;; + # TODO check aarch64 feature level + esac + + cd \${srcdir}/MUTN + CGO_ENABLED=1 go build -ldflags=\"-s -w\" -trimpath ./mutn.go +} + +package() { + cd \${srcdir}/MUTN + install -Dm755 ./mutn \${pkgdir}/usr/bin/mutn + install -Dm644 ./LICENSE \${pkgdir}/usr/share/licenses/mutn/LICENSE + install -Dm644 ./completions/zsh/_mutn \${pkgdir}/usr/share/zsh/site-functions/_mutn + install -Dm644 ./completions/bash/mutn \${pkgdir}/usr/share/bash-completion/completions/mutn +} +" > output/PKGBUILD + printf '\nPKGBUILD generated\n\n' +} diff --git a/wiki/MUTN/completions.md b/wiki/MUTN/completions.md index 47f8e5a..1271cb5 100644 --- a/wiki/MUTN/completions.md +++ b/wiki/MUTN/completions.md @@ -1,7 +1,7 @@ ## Shell Completions Troubleshooting [Shell completions are provided for ZSH, Bash, and PowerShell 7+](https://github.com/rwinkhart/MUTN/tree/main/completions). ### ZSH completions not working? -Make sure your ~/.zshrc contains the following (if sourcing from default completions location, usually `/usr/share/zsh/functions/Completion/Unix/_mutn`): +Make sure your ~/.zshrc contains the following (if sourcing from default completions location, usually `/usr/share/zsh/site-functions/_mutn`): ```shell autoload -Uz compinit && compinit ```