#!/bin/sh -e pebkac() { [ "${*}" ] && printf "%s\n\n" "${*}" cat < Given a post URL number from the site: * downloads and stashes the full-size image in the md5 directory * adds whatever tags are found into the tag area -n Noop-mode; do not download image nor write tags -p Associates the downloaded image with a pool -i Used with -p to indicate the position in the pool -t Refresh the tags, not the picture -f If the image is deleted, provide the local filename EOF kill $$ exit 1 } while getopts dnp:i:tf: OPT do case "${OPT}" in d) DEBUG=DEBUG ;; n) noop=noop ;; p) pool="${OPTARG}" ;; i) indx="${OPTARG}" ;; t) tags=TAGS ;; f) hash="${OPTARG}" ;; ?) pebkac ;; esac done shift $(( $OPTIND - 1 )) [ "${*}" ] || pebkac url="${1}" #[ -z "$(echo "${id}" | tr -d '[0-9]')" ] || pebkac "ID should be an integer" taggery_base="$(dirname "${0}")" taggery_libs="$(dirname "${0}")/lib" # Try and find the profile that can handle the url profiles="$(cd "${taggery_libs}/profiles"; ls -1 | sed -e 's/.sh$//')" for profile in ${profiles} do . "${taggery_libs}/profiles/${profile}.sh" "${profile}_can_handle" "${url}" || continue taggery_name="${profile}" break done # Set up temporary area #mkdir -p "$(dirname "${0}")/tmp" #TMPDIR="$(dirname "${0}")/tmp" # Load KVS #kvs="${TMPDIR}/.${taggery_name}.kvdb" #. "$(dirname "${0}")/lib/kvs.sh" # Load Taggery . "${taggery_libs}/taggery.sh" id="$(taggery_id "${url}")" name="$(taggery_image_name "${id}")" file="$(taggery_image_url "${id}")" tags="$(taggery_image_tags "${id}")" [ "${file}" ] || name="${hash}" extn="${name#*.}" [ "${DEBUG}" ] && { echo "id: ${id}" echo "name: ${name}" echo "file: ${file}" echo "tags: ${tags}" echo "" kvs_get_all "${taggery_name}/${id}" kill -KILL $$ } [ "${file}" -o "${hash}" ] || { echo "No download URL (deleted?) and -f not provided" >&2; kill -ABRT $$; exit 1; } [ "${tags}" ] || { echo "No tags found" >&2; kill -ABRT $$; exit 1; } unset nabbed if [ "${file}" ] then if [ -e "${taggery_base}/md5/${name}" ] then echo "Filename ${name} already exists" else if [ "${noop}" ] then echo "taggery_fetch_image(${id})" echo "taggery_image_url => $(taggery_image_url "${id}")" echo "taggery_image_name => $(taggery_image_name "${id}")" else taggery_fetch_image "${id}" nabbed=NABBED fi fi fi if [ "${nabbed}" -o "${tags}" ] then if [ "${noop}" ] then echo "taggery_link_tags(${id}):" echo "${tags}" | sed -e 's/^/ /g' else taggery_link_tags "${id}" fi fi # Even if we didn't download it, try to link it into the pool [ -z "${noop}" ] && [ "${pool}" ] && { plnm="${taggery_base}/pool/${pool}/${indx}.${extn}" if [ -e "${plnm}" ] then echo "Filename ${plnm} already exists" else mkdir -p "${taggery_base}/pool/${pool}" ln -svf "../../md5/${name}" "${plnm}" fi }