diff --git a/Formula/cowponder.rb b/Formula/cowponder.rb index e353f0c..45e630f 100644 --- a/Formula/cowponder.rb +++ b/Formula/cowponder.rb @@ -1,8 +1,8 @@ class Cowponder < Formula desc "Simple terminal command to display random philosophical thoughts from a cow" homepage "https://github.com/maxcai314/homebrew-cowponder" - url "https://max.xz.ax/cowponder/cowponder-homebrew-v0.0.2.tar.gz" - sha256 "9c0fdb7a962c858e69c3d10a6583da79217e13e6dc95fa7418e9e1e7830a0d44" + url "https://max.xz.ax/cowponder/cowponder-homebrew-v0.0.3.tar.gz" + sha256 "f9ba2818473e0b74d311a809a1c884ecedfeddfe3b62bf7dc898539a3d4e4ab5" depends_on "cowsay" depends_on "python@3" diff --git a/resources/Makefile b/resources/Makefile index a8e4296..306a2cc 100644 --- a/resources/Makefile +++ b/resources/Makefile @@ -1,7 +1,13 @@ CONTENTS_DIR := ./contents BUILD_DIR := . INSTALL_DIR := /var/www/max/cowponder -TARBALL_FILE := cowponder-homebrew-v0.0.2.tar.gz +TARBALL_FILE := cowponder-homebrew-v0.0.3.tar.gz + +PACKAGE_FILE := ../Formula/cowponder.rb + +# ANSI color codes +BLUE := \033[0;34m +RESET := \033[0m .PHONY: all clean install @@ -10,9 +16,22 @@ all: $(BUILD_DIR)/$(TARBALL_FILE) install: $(BUILD_DIR)/$(TARBALL_FILE) cp $^ $(INSTALL_DIR) +clean: + rm -f $(BUILD_DIR)/$(TARBALL_FILE) + +# build package and update checksum in ../Formula/cowponder.rb $(BUILD_DIR)/$(TARBALL_FILE): $(CONTENTS_DIR) tar -czvf $@ -C $^ . - shasum -a 256 $(BUILD_DIR)/$(TARBALL_FILE) -clean: - rm -f $(BUILD_DIR)/$(TARBALL_FILE) + new_checksum="$$(shasum -a 256 $@ | cut -d ' ' -f 1)" && \ + echo && printf "new checksum: $(BLUE)$$new_checksum$(RESET)\n" && echo && \ + awk -v new_checksum="$$new_checksum" '{ \ + if ($$1 == "sha256") { \ + print " sha256 \"" new_checksum "\""; \ + } else { \ + print; \ + } \ + }' $(PACKAGE_FILE) > $(PACKAGE_FILE).temp && \ + mv $(PACKAGE_FILE).temp $(PACKAGE_FILE) + + @echo "updated new checksum in $(BLUE)../Formula/cowponder.rb$(RESET)" diff --git a/resources/contents/cowponder b/resources/contents/cowponder index 2d97f62..0844848 100755 --- a/resources/contents/cowponder +++ b/resources/contents/cowponder @@ -1,7 +1,6 @@ #!/usr/bin/python3 import argparse -import requests import subprocess from random import SystemRandom from os import path, popen @@ -42,7 +41,6 @@ is the same software as cowponder and shares a thoughtbook. ap.add_argument("-v", "--version", action='store_true', help=argparse.SUPPRESS) ap.add_argument("-u", "--update", action='store_true', help=argparse.SUPPRESS) ap.add_argument("-a", "--add", help=argparse.SUPPRESS) -ap.add_argument("-h", "--help", action="store_true", help=argparse.SUPPRESS) arglist = 'bdgpsy' for i in arglist: ap.add_argument("-"+i, action="store_true", help=argparse.SUPPRESS) @@ -51,36 +49,18 @@ for i in arglist: args = vars(ap.parse_args()) -if args["help"]: - print(ap.description) - exit() - if args['version']: subprocess.run(["brew", "info", "cowponder"]) # print("cowponder version 0.0.1") exit() -if args['update']: - try: - response = requests.get('https://max.xz.ax/cowponder/cowthoughts.txt') - if response.status_code == 200: - with open(cowthoughts_path, 'w') as f: - f.write(response.text) - print("updated thoughtbook (moo)") - exit() - else: - print("failed to download cowthoughts.txt") - print("no changes written to local cowthoughts file") - exit() - except Exception as e: - print(f"Error while downloading cowthoughts.txt: {e}") - exit() +if thought := args["add"]: + subprocess.run(["ponder", "--add", thought]) + exit() -if thought := args['add']: - with open(cowthoughts_path, "a") as f: - print(thought, file=f) - subprocess.run(['cowthink', '"' + thought + '" added to thoughtbook']) - exit() +if args["update"]: + subprocess.run(["ponder", "--update"]) + exit() thought = subprocess.check_output("ponder", shell=True, stderr=subprocess.STDOUT, text=True) diff --git a/resources/cowponder-homebrew-v0.0.2.tar.gz b/resources/cowponder-homebrew-v0.0.2.tar.gz deleted file mode 100644 index 115b3c2..0000000 Binary files a/resources/cowponder-homebrew-v0.0.2.tar.gz and /dev/null differ diff --git a/resources/cowponder-homebrew-v0.0.3.tar.gz b/resources/cowponder-homebrew-v0.0.3.tar.gz new file mode 100644 index 0000000..bbfb578 Binary files /dev/null and b/resources/cowponder-homebrew-v0.0.3.tar.gz differ