diff --git a/tmp/src/Makefile b/tmp/src/Makefile index cde17fc94..b3ff8c272 100644 --- a/tmp/src/Makefile +++ b/tmp/src/Makefile @@ -44,7 +44,7 @@ CFLAGS= -O3 -g3 --pedantic -Wall # target information # ###################### -TARGETS= winner_name +TARGETS= winner_name ioccc_status ###################################### # all - default rule - must be first # diff --git a/tmp/src/ioccc_status/.gitignore b/tmp/src/ioccc_status/.gitignore new file mode 100644 index 000000000..3617626f6 --- /dev/null +++ b/tmp/src/ioccc_status/.gitignore @@ -0,0 +1 @@ +ioccc_status diff --git a/tmp/src/ioccc_status/Makefile b/tmp/src/ioccc_status/Makefile new file mode 100644 index 000000000..7c2f0aed3 --- /dev/null +++ b/tmp/src/ioccc_status/Makefile @@ -0,0 +1,67 @@ +#!/usr/bin/env make +# +# ioccc_status - quickly update status.json file +# +# Written by Cody Boone Ferguson in 2023 +# +# @xexyl +# https://xexyl.net Cody Boone Ferguson +# https://ioccc.xexyl.net +# +# Share and enjoy! :-) + +############# +# utilities # +############# + +CC= cc +CHMOD= chmod +CP= cp +INSTALL= install +RM= rm +SHELL= bash + +#CFLAGS= -O3 -g3 --pedantic -Wall -Werror +CFLAGS= -O3 -g3 --pedantic -Wall + +###################### +# target information # +###################### + +DESTDIR= ../../bin + +TARGETS= ioccc_status + +###################################### +# all - default rule - must be first # +###################################### + +all: ${TARGETS} + @: + +ioccc_status: ioccc_status.sh + ${RM} -f -v $@ + ${CP} -f -v $? $@ + ${CHMOD} +x $@ + +################################################# +# .PHONY list of rules that do not create files # +################################################# + +.PHONY: all configure clean clobber install + +################################### +# standard Makefile utility rules # +################################### + +configure: + @: + +clean: + @: + +clobber: clean + rm -f ${TARGETS} + +install: all + ${INSTALL} -m 0555 ${TARGETS} ${DESTDIR} diff --git a/tmp/src/ioccc_status/ioccc_status.sh b/tmp/src/ioccc_status/ioccc_status.sh new file mode 100755 index 000000000..474e1a41d --- /dev/null +++ b/tmp/src/ioccc_status/ioccc_status.sh @@ -0,0 +1,180 @@ +#!/usr/bin/env bash +# +# ioccc_status.sh - quickly update status.json file +# +# Written by Cody Boone Ferguson in 2023 +# +# @xexyl +# https://xexyl.net Cody Boone Ferguson +# https://ioccc.xexyl.net +# +# The script is at this just point a proof of concept but it does work, allowing +# one to update the date of the latest news, the date of the status, the status +# version and the status of the contest. It's not required to update all or for +# that matter any of them. +# +# If that is not clear: it might or might not be needed or desired and that is +# perfectly okay. If it's used but modified that's also okay. It gave me +# something to do and whether or not it's useful it has served a purpose. +# +# If -s option is used, the status field is updated, providing that the status +# arg is either "closed" or "open". +# +# If the -d or -n flags are used then it will update the status_date or +# latest_news fields, respectively. +# +# If the -I status_ver option is used the IOCCC_status_version field will be +# updated. +# +export IOCCC_STATUS_VERSION="0.0.1-0 2023-10-02" # major.minor.release-patch YYYY-MM-DD + +USAGE="usage: $(basename "$0") [-h] [-V] [-v level] [-s status] [-d] [-n] [-I status_ver] status.json + + -h print help and exit + -V print version and exit + -v level set verbosity level + -s statue set contest status to open or closed + -d update status_date + -n update latest_news date + -I status_ver update IOCCC_status_version + + NOTE: status_ver must be one of \"open\" or \"closed\" + + status.json the file to update + +status version: $IOCCC_STATUS_VERSION" + +export UPDATE_DATE="" +export UPDATE_NEWS="" +export UPDATE_IOCCC_STATUS_VERSION="" +export IOCCC_STATUS_VERSION="" +export VERBOSITY=0 +export STATUS_JSON_FILE="" +export STATUS_FLAG="" +export STATUS="closed" # default closed + +# parse args +# +while getopts :hVv:s:dnI: flag; do + case "$flag" in + h) echo "$USAGE" 1>&2 + exit 2 + ;; + V) echo "$IOCCC_STATUS_VERSION" 1>&2 + exit 2 + ;; + v) VERBOSITY="$OPTARG"; + ;; + s) STATUS_FLAG="-s" + STATUS="$OPTARG"; + ;; + d) UPDATE_DATE="-d" + ;; + n) UPDATE_NEWS="-n" + ;; + I) UPDATE_IOCCC_STATUS_VERSION="-I" + IOCCC_STATUS_VERSION="$OPTARG" + ;; + :) echo "$0: ERROR: option -$OPTARG requires an argument" 1>&2 + echo 1>&2 + echo "$USAGE" 1>&2 + exit 3 + ;; + *) + ;; + esac +done + +# +# remove the options +# +shift $(( OPTIND - 1 )); +# +# verify arg count +# +if [[ $# -gt 1 ]]; then + echo "$0: ERROR: expected 0 or 1 args, found: $#" 1>&2 + echo "$USAGE" 1>&2 + exit 3 +fi +# +# parse args +# +if [[ $# -gt 0 ]]; then + export STATUS_JSON_FILE="$1" +fi + +# firewall STATUS_JSON_FILE must be a readable file +# +if [[ ! -e $STATUS_JSON_FILE ]]; then + echo "$0: ERROR: status.json does not exist: $STATUS_JSON_FILE" 1>&2 + exit 1 +fi +if [[ ! -f $STATUS_JSON_FILE ]]; then + echo "$0: ERROR: status.json not a file: $STATUS_JSON_FILE" 1>&2 + exit 1 +fi +if [[ ! -r $STATUS_JSON_FILE ]]; then + echo "$0: ERROR: status.json not a readable file: $STATUS_JSON_FILE" 1>&2 + exit 1 +fi + +# check that if -s used that the status ($STATUS) is either 'open' or 'closed' +if [[ -n "$STATUS_FLAG" ]]; then + if [[ "$STATUS" != "open" && "$STATUS" != "closed" ]]; then + echo "$0: ERROR: status must be 'open' or 'closed'" 1>&2 + exit 1 + fi +fi + +if [[ "$VERBOSITY" -gt 1 ]]; then + echo "$0: status.json file: $STATUS_JSON_FILE" 1>&2 + if [[ -n "$STATUS_FLAG" ]]; then + echo "$0: will update contest status to: \"$STATUS\"" 1>&2 + fi + if [[ -n "$UPDATE_DATE" ]]; then + echo "$0: will update status_date to: $(date)" 1>&2 + fi + if [[ -n "$UPDATE_NEWS" ]]; then + echo "$0: will update latest_news to: $(date)" 1>&2 + fi + if [[ -n "$UPDATE_IOCCC_STATUS_VERSION" ]]; then + echo "$0: will update IOCCC_status_version to: $IOCCC_STATUS_VERSION" 1>&2 + fi +fi + +# first status_date if requested +if [[ -n "$UPDATE_DATE" ]]; then + sed -i'' "s/\"status_date\" : \".*[^\"]\"/\"status_date\" : \"$(date)\"/g" "$STATUS_JSON_FILE" + + if [[ "$VERBOSITY" -ge 1 ]]; then + echo "$0: updated status_date to: $(date)" 1>&2 + fi +fi + +# then update latest_news date if requested +if [[ -n "$UPDATE_NEWS" ]]; then + sed -i'' "s/\"latest_news\" : \".*[^\"]\"/\"latest_news\" : \"$(date)\"/g" "$STATUS_JSON_FILE" + + if [[ "$VERBOSITY" -ge 1 ]]; then + echo "$0: updated latest_news to: $(date)" 1>&2 + fi +fi + +# then update IOCCC_STATUS_VERSION if requested +if [[ -n "$UPDATE_IOCCC_STATUS_VERSION" ]]; then + sed -i'' "s/\"IOCCC_status_version\" : \".*[^\"]\"/\"IOCCC_status_version\" : \"$IOCCC_STATUS_VERSION\"/g" "$STATUS_JSON_FILE" + + if [[ "$VERBOSITY" -ge 1 ]]; then + echo "$0: updated IOCCC_status_version to: \"$IOCCC_STATUS_VERSION\"" 1>&2 + fi +fi + +# finally if we need to change the status of the contest do so +if [[ -n "$STATUS_FLAG" ]]; then + sed -i'' "s/\"contest\" : \".*[^\"]\"/\"contest\" : \"$STATUS\"/g" "$STATUS_JSON_FILE" + + if [[ "$VERBOSITY" -ge 1 ]]; then + echo "$0: updated contest status to: \"$STATUS\"" 1>&2 + fi +fi