#!/bin/bash set -ex; DATA_DIR="${XDG_DATA_HOME:-$HOME/.local/share}/pack2task" PACKAGES_DIR="$DATA_DIR/packages" mkdir -p $PACKAGES_DIR URL=$1 host=$(trurl "$URL" -g '{host}') tmpfile=$(mktemp) case "$host" in "www.mondialrelay.fr") query=$(trurl "$URL" -g '{query}') # TODO: Check order of query parameters! tracking_id=$(echo $query | cut -d'&' -f1 | cut -d'=' -f2) postcode=$(echo $query | cut -d'&' -f2 | cut -d'=' -f2) filename="$PACKAGES_DIR"/"mrfr-$(date '+%Y%m%dT%H%M%S').json" echo "{}" > "$filename" jq '.tracker = "MRFR" | .waitingFor = "delivery"' "$filename" > "$tmpfile" mv "$tmpfile" "$filename" jq ".trackerInfo.id = \"$tracking_id\" | .trackerInfo.postcode = \"$postcode\"" "$filename" > "$tmpfile" mv "$tmpfile" "$filename" ;; "www.chronoshop2shop.fr") tracking_id=$(trurl "$URL" -g '{fragment}' | cut -d'/' -f3) filename="$PACKAGES_DIR"/"s2s-$(date '+%Y%m%dT%H%M%S').json" echo "{}" > "$filename" jq '.tracker = "S2S" | .waitingFor = "delivery"' "$filename" > "$tmpfile" mv "$tmpfile" "$filename" jq ".trackerInfo.id = \"$tracking_id\"" "$filename" > "$tmpfile" mv "$tmpfile" "$filename" ;; *) echo "Invalid tracking URL."; exit -1; ;; esac