4 [ "${*}" ] && printf "%s\n\n" "${*}"
6 Usage: $(basename "${0}") <id>
8 Given an ID number from the site:
9 * downloads and stashes the full-size image in the md5 directory
10 * adds whatever tags are found into the tag area
12 -p <poolname> Associates the downloaded image with a pool
13 -i <indexnum> Used with -p to indicate the position in the pool
15 -t Refresh the tags, not the picture
16 -f <filename> If the image is deleted, provide the local filename
22 while getopts p:i:tf: OPT
25 p) pool="${OPTARG}" ;;
26 i) indx="${OPTARG}" ;;
28 f) hash="${OPTARG}" ;;
32 shift $(( $OPTIND - 1 ))
36 [ -z "$(echo "${id}" | tr -d '[0-9]')" ] || pebkac "ID should be an integer"
38 taggery_name="$(basename "${0}")"
39 taggery_profile="$(dirname "${0}")/lib/profiles/${taggery_name}"
40 [ -f "${taggery_profile}" ] || pebkac "Unsupported profile: ${taggery_name}"
41 . "${taggery_profile}"
43 # Set up temporary area
44 mkdir -p "$(dirname "${0}")/tmp"
45 TMPDIR="$(dirname "${0}")/tmp"
48 kvs="${TMPDIR}/.${taggery_name}.kvdb"
49 . "$(dirname "${0}")/lib/kvs.sh"
52 . "$(dirname "${0}")/lib/taggery.sh"
53 image_url() { taggery_image_url "${@}"; }
54 image_tags() { taggery_image_tags "${@}"; }
56 cd "$(dirname "${0}")"
58 file="$(image_url "${id}")"
59 tags="$(image_tags "${id}")"
61 [ "${file}" -o "${hash}" ] || { echo "No download URL (deleted?) and -f not provided" >&2; kill -ABRT $$; exit 1; }
62 [ "${tags}" ] || { echo "No tags found" >&2; kill -ABRT $$; exit 1; }
66 name="$(basename "${file}")"
75 if [ -e "md5/${name}" ]
77 echo "Filename md5/${name} already exists"
79 wget -O "md5/${name}" "${file}"
84 if [ "${nabbed}" -o "${tags}" ]
89 tag="$(echo "${tag}" | sed -e 's/\//%47/g; s/[\]/\\&/g')"
91 ln -sf "../../md5/${name}" "tag/${tag}/"
95 # Even if we didn't download it, try to link it into the pool
97 plnm="pool/${pool}/${indx}.${extn}"
100 echo "Filename ${plnm} already exists"
102 mkdir -p "pool/${pool}"
103 ln -svf "../../md5/${name}" "${plnm}"