diff moefetch.sh @ 202:3dbb5a6678f9

egrep is not grep
author edhoprima@gmail.com <edhoprima@gmail.com>
date Mon, 29 Jun 2009 16:13:22 +0000
parents 30d2fb656029
children 94a585031e3b
line wrap: on
line diff
--- a/moefetch.sh	Mon Jun 29 15:40:28 2009 +0000
+++ b/moefetch.sh	Mon Jun 29 16:13:22 2009 +0000
@@ -47,7 +47,6 @@
 ###  - unified repository to save bandwidth
 ###  - bug stomping
 ###  - sanity checking
-###  - replace grep -vf with POSIX compatible command
 ### WILL BE FOR 0.3
 
 # useless welcome message. Also version
@@ -90,7 +89,7 @@
 	printf "Processing XML file..."
 	# xslt evilry
 	> "${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
+	xsltproc - "${TEMP_PREFIX}-xml" <<EOF | sed 's/.*\(http.*\)\(\/[a-f0-9]\{32\}\).*\.\([^\.]*\)/\1\2.\3/g' | egrep ^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">
@@ -128,21 +127,11 @@
 	fi
 	MD5_COMMAND=$(echo ${MD5} | cut -d' ' -f1)
 	# basic tools
-	COMMANDS="cut sed wc wget xsltproc xargs rm mkdir chown comm grep date ${MD5_COMMAND}"
+	COMMANDS="cut sed wc wget xsltproc xargs rm mkdir chown comm egrep grep date ${MD5_COMMAND}"
 	for COMMAND in ${COMMANDS}
 	do
 		 [ "$(command -v "${COMMAND}")" ] || Err_Fatal "${COMMAND} doesn't exist in ${PATH}"
 	done
-
-	# grep checking
-	# originally created for workaround on solaris
-	#if [ `uname` = "SunOS" ]; then
-	FAIL=
-	echo "blah" > superrandomtestfile
-	echo "blah" > superrandomtestfile.2
-	grep -f superrandomtestfile.2 superrandomtestfile > /dev/null 2>&1 || FAIL=1
-	rm -f superrandomtestfile superrandomtestfile.2
-	[ "${FAIL}" ] && Err_Fatal "Your grep is not compatible. Please install or set path of correct grep"
 }
 
 # verify required folders exist and writeable
@@ -179,7 +168,7 @@
 		if [ -d "${TRASH}" ]; then
 			ISTRASH=1
 		else
-			if [ "$(echo "${TRASH}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then
+			if [ "$(echo "${TRASH}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | egrep -v ^$)" ]; then
 				ISTRASH=1
 			else
 				[ "$(cat "${TEMP_PREFIX}-list" | sed -e "${SED_GET_FILENAME}" | grep $(echo "${TRASH}" | sed -e "${SED_GET_FILENAME}"))" ] || ISTRASH=1
@@ -202,7 +191,7 @@
 		> "${TEMP_PREFIX}-error"
 		for FILE in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
 		do
-			if [ "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then
+			if [ "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | egrep -v ^$)" ]; then
 				echo
 				echo "Not a valid danbooru file: $(echo ${FILE} | sed -e "${SED_GET_FILENAME}")"
 			else
@@ -233,11 +222,11 @@
 		#
 		find "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" | comm -1 -3 "${TEMP_PREFIX}-error" - | sed -e "${SED_GET_FILENAME}" > "${TEMP_PREFIX}-ok"
 		cat "${TEMP_PREFIX}-list" > "${TEMP_PREFIX}-templist"
-		while read -r IS_OK; do
-			cat "${TEMP_PREFIX}-templist" | grep -v "${IS_OK}" > "${TEMP_PREFIX}-newlist"
-			cat "${TEMP_PREFIX}-newlist" > "${TEMP_PREFIX}-templist"
-		done < "${TEMP_PREFIX}-ok"
-		#cat "${TEMP_PREFIX}-list" | grep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist"
+		#while read -r IS_OK; do
+		#	cat "${TEMP_PREFIX}-templist" | grep -v "${IS_OK}" > "${TEMP_PREFIX}-newlist"
+		#	cat "${TEMP_PREFIX}-newlist" > "${TEMP_PREFIX}-templist"
+		#done < "${TEMP_PREFIX}-ok"
+		cat "${TEMP_PREFIX}-list" | egrep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist"
 		echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded"
 		
 	else