#!/bin/sh -e pebkac() { [ "${*}" ] && printf "%s\n\n" "${*}" cat < Given an ID number from the site: * downloads and stashes the full-size image in the md5 directory * adds whatever tags are found into the tag area EOF kill $$ exit 1 } [ "${*}" ] || pebkac id="${1}" [ -z "$(echo "${id}" | tr -d '[0-9]')" ] || pebkac "ID should be an integer" taggery_name="$(basename "${0}")" taggery_profile="$(dirname "${0}")/lib/profiles/${taggery_name}" [ -f "${taggery_profile}" ] || pebkac "Unsupported profile: ${taggery_name}" . "${taggery_profile}" # Load KVS kvs=".${taggery_name}.kvdb" . "$(dirname "${0}")/lib/kvs.sh" # Load Taggery . "$(dirname "${0}")/lib/taggery.sh" image_url() { taggery_image_url "${@}"; } image_tags() { taggery_image_tags "${@}"; } cd "$(dirname "${0}")" file="$(image_url "${id}")" tags="$(image_tags "${id}")" [ "${file}" -a "${tags}" ] || { echo "Nothing found!"; kill $$; exit 1; } name="$(basename "${file}")" [ ! -e "md5/${name}" ] || { echo "Filename md5/${name} already exists!"; kill $$; exit 1; } wget -O "md5/${name}" "${file}" for tag in ${tags} do echo ${tag} tag="$(echo "${tag}" | sed -e 's/\//%47/g; s/[\]/\\&/g')" mkdir -p "tag/${tag}" ln -sf "../../md5/${name}" "tag/${tag}/" done