fixed various quoting issues and some bugs related to write code while half asleep

This commit is contained in:
Olaf Bohlen
2023-01-02 12:58:57 +01:00
parent 631cfd7a2b
commit 411862b8ba

View File

@@ -13,13 +13,15 @@ typeset -A receiptversion
CURLOPTS="-s --cacert ${CACRT} -H 'Accept: application/json' -H 'User-Agent: ksh93 receipt processor 0.1' -H 'Authorization: Bearer ${TOKEN}'" CURLOPTS="-s --cacert ${CACRT} -H 'Accept: application/json' -H 'User-Agent: ksh93 receipt processor 0.1' -H 'Authorization: Bearer ${TOKEN}'"
updatedreceipts=""
while sleep 5; do while sleep 5; do
# MAIN loop # MAIN loop
# we will later store here modified receipt uids, so we clear it for every run
updatedreceipts=""
# get a CookieReceiptList item from the API and store the json in a variable # get a CookieReceiptList item from the API and store the json in a variable
respjson=$(curl -XGET ${CURLOPTS} '${APIURL}/apis/de.eenfach.olbohlen/v1/namespaces/${NAMESPACE}/cookiereceipts?limit=500') respjson=$(eval curl -XGET ${CURLOPTS} "${APIURL}/apis/de.eenfach.olbohlen/v1/namespaces/${NAMESPACE}/cookiereceipts?limit=500")
# check if we got the expected resource: # check if we got the expected resource:
kind=$(echo "${respjson}" | jq .kind) kind=$(echo "${respjson}" | jq .kind)
@@ -29,7 +31,7 @@ while sleep 5; do
fi fi
# how many receipts are there? # how many receipts are there?
numreceipts=$(echo "${respjson}" | jq .items[].metadata.name | wc -l) numreceipts=$(echo "${respjson}" | jq .items\[\].metadata.name | wc -l)
# populate the in memory arrays with json metadata, we need # populate the in memory arrays with json metadata, we need
# - the name # - the name
@@ -38,54 +40,53 @@ while sleep 5; do
# for every receipt to figure out if we need to process them # for every receipt to figure out if we need to process them
i=0 i=0
while [ ${i} -lt ${numreceipts} ]; do while [ ${i} -lt ${numreceipts} ]; do
##foo[${xid}]=$(echo "${RESPJSON}" | jq .items[1].metadata.name) receiptuid=$(echo "${respjson}" | jq -r .items[${i}].metadata.uid)
receiptuid=$(echo "${respjson}" | jq .items[${i}].metadata.uid) receiptname[${receiptuid}]=$(echo "${respjson}" | jq -r .items[${i}].metadata.name)
receiptname[${receiptuid}]=$(echo "${respjson}" | jq .items[${i}].metadata.name)
#receiptversion[${receiptuid}]=$(echo "${respjson}" | jq .items[${i}].metadata.resourceVersion)
# check if we already have processed this version of the receipt, if not # check if we already have processed this version of the receipt, if not
# store the uid of that receipt in the updatedreceipts var # store the uid of that receipt in the updatedreceipts var
newversion=$(echo "${respjson}" | jq .items[${i}].metadata.resourceVersion) newversion=$(echo "${respjson}" | jq -r .items[${i}].metadata.resourceVersion)
if [ "x${newversion}" != "x${receiptversion[${receiptuid}]}" ]; then if [ "x${newversion}" != "x${receiptversion[${receiptuid}]}" ]; then
# we have an update! # we have an update!
updatedreceipts="${updatedreceipts} ${newversion}" updatedreceipts="${updatedreceipts} ${receiptuid}"
receiptsversion[${receiptuid}]="${newversion}" receiptversion[${receiptuid}]="${newversion}"
fi fi
i=$(( ${i} + 1 )) i=$(( ${i} + 1 ))
done done
# now that we have a list of updated receipts, we are going to process them # now that we have a list of updated receipts, we are going to process them
for r in ${updatedreceipts}; do for r in ${updatedreceipts}; do
# get the name for the UID and fetch only that object # get the name for the UID and fetch only that object
receipt=$( curl -XGET ${CURLOPTS} '${APIURL}/apis/de.eenfach.olbohlen/v1/namespaces/${NAMESPACE}/cookiereceipts/${receiptname[${r}]}' ) receipt=$(eval curl -XGET ${CURLOPTS} '${APIURL}/apis/de.eenfach.olbohlen/v1/namespaces/${NAMESPACE}/cookiereceipts/${receiptname[${r}]}' )
# receipt contains now the json for one receipt, now we parse that # receipt contains now the json for one receipt, now we parse that
# we set scale to Fahrenheit if sanescale is false, else scale will use Celsius # we set scale to Fahrenheit if sanescale is false, else scale will use Celsius
scale_b=$( echo "${receipt}" | jq .spec.sanescale ) scale_b=$( echo "${receipt}" | jq -r .spec.sanescale )
if [ "x${sanescale}" == "xfalse" ]; then if [ "x${sanescale}" == "xfalse" ]; then
scale=Fahrenheit scale=Fahrenheit
fi fi
temperature=$( echo ${receipt} | jq .spec.temperature ) temperature=$( echo ${receipt} | jq -r .spec.temperature )
preheat_b=$( echo "${receipt}" | jq .spec.preheat ) preheat_b=$( echo "${receipt}" | jq -r .spec.preheat )
if [ "x${preheat_b}" == "xtrue" ]; then if [ "x${preheat_b}" == "xtrue" ]; then
printf "Pre: we heat up the oven to %s degrees %s\n" "${temperature}" "${scale:-Celsius}" printf "Pre: we heat up the oven to %s degrees %s\n" "${temperature}" "${scale:-Celsius}"
fi fi
# how many ingredients do we have? # how many ingredients do we have?
num_in=$(echo "${receipt}" | jq .spec.ingredients[].name | wc -l) num_in=$(echo "${receipt}" | jq .spec.ingredients\[\].name | wc -l)
# list up that we fetch needed ingredients # list up that we fetch needed ingredients
i=0 i=0
while [ ${i} -lt ${num_in} ]; do while [ ${i} -lt ${num_in} ]; do
in_name=$( echo "${receipt}" | jq .spec.ingredients[${i}].name ) in_name=$( echo "${receipt}" | jq -r .spec.ingredients[${i}].name )
in_amount=$( echo "${receipt}" | jq .spec.ingredients[${i}].amount ) in_amount=$( echo "${receipt}" | jq -r .spec.ingredients[${i}].amount )
in_unit=$( echo "${receipt}" | jq .spec.ingredients[${i}].unit ) in_unit=$( echo "${receipt}" | jq -r .spec.ingredients[${i}].unit )
in_remarks=$( echo "${receipt}" | jq .spec.ingredients[${i}].remarks ) in_remarks=$( echo "${receipt}" | jq -r .spec.ingredients[${i}].remarks )
printf "Fetching %s%s of %s" ${in_amount} ${in_unit} ${in_name} printf "Fetching %s%s of %s" "${in_amount}" "${in_unit}" "${in_name}"
if [ "x${in_remarks}" != "xnull" ]; then if [ "x${in_remarks}" != "xnull" ]; then
printf " (%s)" ${in_remarks} printf " (%s)" "${in_remarks}"
fi fi
printf "\n" printf "\n"
sleep 1 sleep 1
@@ -98,14 +99,14 @@ while sleep 5; do
# an "order" attribute in each list item, and we select on that. # an "order" attribute in each list item, and we select on that.
# first again, we need the amount of instructions... # first again, we need the amount of instructions...
num_steps=$(echo "${receipt}" | jq .spec.steps[].order | wc -l) num_steps=$(echo "${receipt}" | jq .spec.steps\[\].order | wc -l)
# now let's iterate over that # now let's iterate over that
i=0 i=1
while [ ${i} -lt ${num_steps} ]; do while [ ${i} -lt ${num_steps} ]; do
instruction=$( echo "${receipt}" | jq ".spec.steps[] | select(.order == ${i}) | { instruction | join (' ')" ) instruction=$( echo "${receipt}" | jq '.spec.steps[] | select(.order == '${i}') | { instruction | join (" ")' )
##echo "${receipt}" | jq '.spec.steps[] | select(.order == 5) | { instruction } | join (" ")'
printf "Step %i/%i: %s..." $(( ${i} + 1 )) ${num_steps} "${instruction}" printf "Step %i/%i: %s..." ${i} ${num_steps} "${instruction}"
sleep $(( ${RANDOM} % 6 + 1 )) sleep $(( ${RANDOM} % 6 + 1 ))
printf "done\n" printf "done\n"
sleep 1 sleep 1