changeset 195:652d9e268cee

test migration to printf
author edhoprima@gmail.com <edhoprima@gmail.com>
date Mon, 29 Jun 2009 11:59:49 +0000
parents a8da49424468
children 4d28f3a957ee
files moefetch.sh
diffstat 1 files changed, 8 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/moefetch.sh	Mon Jun 29 10:54:33 2009 +0000
+++ b/moefetch.sh	Mon Jun 29 11:59:49 2009 +0000
@@ -60,7 +60,7 @@
 
 # fatal error handler
 Err_Fatal() {
-	echo "Fatal error: ${1}"
+	printf "\nFatal error: ${1}"
 	exit 1
 }
 
@@ -83,13 +83,12 @@
 
 # generate link by transforming xml
 Generate_Link() {
-	cd "${BASE_DIR}/temp"
-	echo
-	echo "Fetching xml file"
-	wget "http://${SITE}/post/index.xml?tags=${TAGS}&offset=0&limit=100000" -O "${SITE_DIR}-${TARGET_DIR}-xml" -e continue=off
-	echo "Processing XML file..."
+	printf "\nFetching xml file\n"
+	wget "http://${SITE}/post/index.xml?tags=${TAGS}&offset=0&limit=100000" -O "${TEMP_PREFIX}-xml" -e continue=off
+	printf "Processing XML file..."
 	# xslt evilry
-	xsltproc - "${SITE_DIR}-${TARGET_DIR}-xml" <<EOF | sed 's/.*\(http.*\)\(\/[a-f0-9]\{32\}\).*\.\([jp][pn]g\)/\1\2.\3/g' | grep ^http > "${SITE_DIR}-${TARGET_DIR}-list"
+	> "${TEMP_PREFIX}-list"
+	xsltproc - "${TEMP_PREFIX}-xml" <<EOF | sed 's/.*\(http.*\)\(\/[a-f0-9]\{32\}\).*\.\([^\.]*\)/\1\2.\3/g' | grep ^http > "${TEMP_PREFIX}-list" 2>/dev/null
 <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
 <xsl:output method="xml" indent="yes"/>
 <xsl:template match="post">
@@ -97,7 +96,7 @@
 </xsl:template>
 </xsl:stylesheet>
 EOF
-	NUMFILES=$(echo $(wc -l < "${SITE_DIR}-${TARGET_DIR}-list"))
+	NUMFILES=$(echo $(wc -l < "${TEMP_PREFIX}-list"))
 	[ "${NUMFILES}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site"
 	echo "${NUMFILES} file(s) available on server"
 	#output file: ${TARGET_DIR}-list
@@ -305,6 +304,7 @@
 	# slash is not wanted for folder name
 	TARGET_DIR=$(echo "${TAGS}" | sed -e 's/\//_/g')
 	SITE_DIR=$(echo "${SITE}" | sed -e 's/\/$//g;s/\//_/g')
+	TEMP_PREFIX="${BASE_DIR}/temp/${SITE_DIR}-${TARGET_DIR}"
 }
 
 # initialization