changeset 232:5438d80244a3

- version bump
author edhoprima
date Sun, 14 Mar 2010 18:35:03 +0000
parents 4c0fd276665e
children 38d6c17353fb
files moefetch.sh
diffstat 1 files changed, 33 insertions(+), 41 deletions(-) [+]
line wrap: on
line diff
--- a/moefetch.sh	Sat Mar 13 20:42:01 2010 +0000
+++ b/moefetch.sh	Sun Mar 14 18:35:03 2010 +0000
@@ -34,14 +34,6 @@
 
 # not user modifiable from here
 
-### TODO:
-###  - sanity validator(?)
-###  - unified repository to save bandwidth
-###  - bug stomping
-###  - sanity checking
-###  - MOAR comments
-### WILL BE FOR 0.3
-
 # useless welcome message. Also version
 msg_welcome() {
 	echo "moefetch ${_version}
@@ -53,13 +45,13 @@
 safe_path()
 {
 	# It all depends on the first character.
-	__start=$(printf "%s" "$*" | cut -c 1)
-	__path=
-	case "${__start}" in
-		.|/) __path="$*";; # . and / is safe. No change.
-		*) __path="./$*";; # Anything else must be prefixed with ./
+	start=$(printf "%s" "$*" | cut -c 1)
+	path=
+	case "${start}" in
+		.|/) path="$*";; # . and / is safe. No change.
+		*) path="./$*";; # Anything else must be prefixed with ./
 	esac
-	printf "%s" "${__path}" # Return.
+	printf "%s" "${path}" # Return.
 }
 
 # Checks md5. OpenSSL should be available on anything usable.
@@ -120,13 +112,13 @@
 Generate_Link() {
 	echo "
 Fetching XML file"
-	__tempnum=1000
-	__iternum=1
+	tempnum=1000
+	iternum=1
 	> "${TEMP_PREFIX}-list"
-	while [ "${__tempnum}" -ge 1000 ]; do
-		__url="http://${SITE}/post/index.xml?tags=$(get_cleantags "${TAGS}")&offset=0&limit=1000&page=${__iternum}"
-		[ ${_use_login} -eq 1 ] && __url="${__url}&login=${LOGIN_USER}&password_hash=${LOGIN_PASS}"
-		wget --quiet "${__url}" -O "${TEMP_PREFIX}-xml" -e continue=off || Err_Fatal "Failed download catalog file"
+	while [ "${tempnum}" -ge 1000 ]; do
+		url="http://${SITE}/post/index.xml?tags=$(get_cleantags "${TAGS}")&offset=0&limit=1000&page=${iternum}"
+		[ ${_use_login} -eq 1 ] && url="${url}&login=${LOGIN_USER}&password_hash=${LOGIN_PASS}"
+		wget --quiet "${url}" -O "${TEMP_PREFIX}-xml" -e continue=off || Err_Fatal "Failed download catalog file"
 		printf "Processing XML file... "
 		# xslt evilry
 		xsltproc - "${TEMP_PREFIX}-xml" <<EOF | sed 's/.*\(http.*\)\(\/[a-f0-9]\{32\}\).*\.\([^\.]*\)/\1\2.\3/g' | grep ^http > "${TEMP_PREFIX}-templist"
@@ -137,10 +129,10 @@
 </xsl:template>
 </xsl:stylesheet>
 EOF
-		__tempnum=$(echo $(wc -l < "${TEMP_PREFIX}-templist"))
-		__iternum=$((__iternum + 1))
+		tempnum=$(echo $(wc -l < "${TEMP_PREFIX}-templist"))
+		iternum=$((iternum + 1))
 		cat "${TEMP_PREFIX}-templist" >> "${TEMP_PREFIX}-list"
-		echo "${__tempnum} file(s) available"
+		echo "${tempnum} file(s) available"
 	done
 	numfiles=$(echo $(wc -l < "${TEMP_PREFIX}-list"))
 	echo "${numfiles} file(s) available on server"
@@ -243,42 +235,42 @@
 		[ -z "${NOCLEAN}" ] && Cleanup_Repository
 		printf "Checking for errors... "
 		progress_init
-		__files_error="These files do not match its md5:"
-		__files_notdanbooru="These files are not checked:"
-		__has_err_filename=
-		__has_err_md5=
+		files_error="These files do not match its md5:"
+		files_notdanbooru="These files are not checked:"
+		has_err_filename=
+		has_err_md5=
 		> "${TEMP_PREFIX}-error"
 		> "${TEMP_PREFIX}-ok"
 		for file in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
 		do
 			if [ "${file}" != "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/*" ]; then
 				if [ -n "$(is_not_md5 "${file}")" ] || [ -d "${file}" ]; then
-					__files_notdanbooru="${__files_notdanbooru}
+					files_notdanbooru="${files_notdanbooru}
   $(get_basename "${file}")"
-					__has_err_filename=1
+					has_err_filename=1
 				else
 					if [ "$(get_md5 "${file}")" = "$(get_filename "${file}")" ]; then
 						echo "$(get_basename "${file}")" >> "${TEMP_PREFIX}-ok"
 					else
 						rm "${file}" || Err_Fatal "Error removing ${file}"
 						echo "$(get_basename "${file}")" >> "${TEMP_PREFIX}-error"
-						__files_error="${__files_error}
+						files_error="${files_error}
   $(get_basename "${file}")"
-						__has_err_md5=1
+						has_err_md5=1
 					fi
 				fi
 			fi
 			progress_anim
 		done
 		progress_done
-		if [ ! -n "${__has_err_md5}" ] && [ ! -n "${__has_err_filename}" ]; then
+		if [ ! -n "${has_err_md5}" ] && [ ! -n "${has_err_filename}" ]; then
 			echo "All files OK"
 		else
-			if [ -n "${__has_err_md5}" ]; then
-				echo "${__files_error}"
+			if [ -n "${has_err_md5}" ]; then
+				echo "${files_error}"
 				echo "$(echo $(wc -l < "${TEMP_PREFIX}-error")) file(s) removed"
 			fi
-			[ -n "${__has_err_filename}" ] && echo "${__files_notdanbooru}" 
+			[ -n "${has_err_filename}" ] && echo "${files_notdanbooru}" 
 		fi
 		echo "$(echo $(wc -l < "${TEMP_PREFIX}-ok")) file(s) available locally"
 
@@ -343,8 +335,8 @@
 	shift
 	SITE=
 	TAGS=
-	__has_pass=0
-	__has_user=0
+	has_pass=0
+	has_user=0
   x=1
 	while getopts "s:nu:p:" opt
 	do
@@ -353,11 +345,11 @@
 			n) NOCLEAN=1;;
 			p)
 				LOGIN_PASS=$(printf "%s" "$OPTARG" | openssl dgst -sha1)
-				__has_pass=1
+				has_pass=1
 			;;
 			u)
 				LOGIN_USER="$OPTARG"
-				__has_user=1
+				has_user=1
 			;;
 		esac
     x=$OPTIND
@@ -372,7 +364,7 @@
 	[ -n "${BASE_DIR}" ] || BASE_DIR=${HOME}
 	[ -n "$(echo "${BASE_DIR}" | cut -c1 | grep \/)" ] || BASE_DIR="/${BASE_DIR}"
 	# see if both pass and use are set. If they're set, switch _use_login variable content to 1.
-	[ ${__has_pass} -eq 1 -a ${__has_user} -eq 1 ] && _use_login=1
+	[ ${has_pass} -eq 1 -a ${has_user} -eq 1 ] && _use_login=1
 
 	echo "Tags: ${TAGS}"
 	# slash is not wanted for folder name
@@ -384,7 +376,7 @@
 # global variables goes here
 init_globals()
 {
-	_version="0.3-rc1"	# version of this script
+	_version="1.0-rc2"	# version of this script
 	_use_login=0	# variable to check whether a login is used or not
 }