diff options
Diffstat (limited to '')
-rwxr-xr-x | scripts/paku | 96 |
1 files changed, 76 insertions, 20 deletions
diff --git a/scripts/paku b/scripts/paku index 239f1a5..88fd917 100755 --- a/scripts/paku +++ b/scripts/paku @@ -153,29 +153,85 @@ EOF mv "$NIX_OUT" default.nix } +gen_homebrew() { + for p in $(jq -r '.packages[] | @base64' < paku.json); do + HOMEBREW_OUT="$(mktemp)" + NAME="$(echo "$p" | base64 --decode | jq -r '.name')" + VERSION="$(echo "$p" | base64 --decode | jq -r '.version')" + TYPE="$(echo "$p" | base64 --decode | jq -r '.type')" + + TARBALL_URL="$(tarball_url "$NAME" "$VERSION")" + TARBALL="$(mktemp)" + wget -O "$TARBALL" "$TARBALL_URL" + SHA256="$(sha256sum "$TARBALL" | cut -d\ -f 1)" + DESCRIPTION="$(tar xvf "$TARBALL" -O "$NAME-$VERSION/description")" + + JSON_CHECK_INPUTS="$(echo "$p" | base64 --decode | jq -r '.check_inputs')" + if [ "$JSON_CHECK_INPUTS" = 'null' ]; then + CHECK_INPUTS='' + else + CHECK_INPUTS='' + for check_input in $(echo "$JSON_CHECK_INPUTS" | jq -r '.[]'); do + CHECK_INPUTS="$CHECK_INPUTS + depends_on '$check_input' => :build" + done + CHECK_INPUTS="$CHECK_INPUTS +" + fi + + TEST_SECTION='' + if [ "$TYPE" = 'bin' ]; then + TEST_SECTION=" + + test do + system \"#{bin}/$NAME\", '-V' + end" + fi + + cat <<EOF >>"$HOMEBREW_OUT" +class ${NAME^} < Formula + desc '$DESCRIPTION' + homepage 'https://$NAME.euandreh.xyz' + url '$TARBALL_URL' + sha256 '$SHA256' + license 'AGPL-3.0-or-later' +$CHECK_INPUTS + def install + system './configure', "--prefix=#{prefix}" + system 'make' + system 'make', 'check' + system 'make', 'install' + end$TEST_SECTION +end +EOF + mv "$HOMEBREW_OUT" "Formula/$NAME.rb" + done +} + refresh_packages() { - COUNT="$(jq -r '.packages[].name' < paku.json | wc -l)" - INDEXES="$(seq 0 "$((COUNT - 1))")" + COUNT="$(jq -r '.packages[].name' < paku.json | wc -l)" + INDEXES="$(seq 0 "$((COUNT - 1))")" for N in $INDEXES; do - NAME="$(jq -r ".packages[$N].name" < paku.json)" - cd "../$NAME/" - NEW_VERSION="$(git rev-parse HEAD)" - cd - >/dev/null - jq -r ".packages[$N].version = \"$NEW_VERSION\"" paku.json | sponge paku.json - done + NAME="$(jq -r ".packages[$N].name" < paku.json)" + cd "../$NAME/" + NEW_VERSION="$(git rev-parse HEAD)" + cd - >/dev/null + jq -r ".packages[$N].version = \"$NEW_VERSION\"" paku.json | sponge paku.json + done } while getopts 'gr' flag; do - case "$flag" in - g) - gen_guix - gen_nix - ;; - r) - refresh_packages - ;; - *) - printf 'Unrecognized flag "%s".\n' "$flag" >&2 - ;; - esac + case "$flag" in + g) + gen_guix + gen_nix + gen_homebrew + ;; + r) + refresh_packages + ;; + *) + printf 'Unrecognized flag "%s".\n' "$flag" >&2 + ;; + esac done |