Mercurial > ec-dotfiles
diff moefetch.sh @ 203:94a585031e3b
speed?
author | edhoprima@gmail.com <edhoprima@gmail.com> |
---|---|
date | Mon, 29 Jun 2009 16:36:16 +0000 |
parents | 3dbb5a6678f9 |
children | fb02adf58c00 |
line wrap: on
line diff
--- a/moefetch.sh Mon Jun 29 16:13:22 2009 +0000 +++ b/moefetch.sh Mon Jun 29 16:36:16 2009 +0000 @@ -51,7 +51,7 @@ # useless welcome message. Also version Msg_Welcome() { - MOEFETCHVERSION="0.2-beta1" + MOEFETCHVERSION="0.2-beta2" cat <<EOF moefetch ${MOEFETCHVERSION} Copyright (c) 2009 edogawaconan <me@myconan.net> @@ -89,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' | egrep ^http > "${TEMP_PREFIX}-list" 2>/dev/null + 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"> @@ -127,7 +127,7 @@ fi MD5_COMMAND=$(echo ${MD5} | cut -d' ' -f1) # basic tools - COMMANDS="cut sed wc wget xsltproc xargs rm mkdir chown comm egrep grep date ${MD5_COMMAND}" + COMMANDS="cut sed wc wget xsltproc xargs rm mkdir chown comm grep date ${MD5_COMMAND}" for COMMAND in ${COMMANDS} do [ "$(command -v "${COMMAND}")" ] || Err_Fatal "${COMMAND} doesn't exist in ${PATH}" @@ -168,7 +168,7 @@ if [ -d "${TRASH}" ]; then ISTRASH=1 else - if [ "$(echo "${TRASH}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | egrep -v ^$)" ]; then + if [ "$(echo "${TRASH}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then ISTRASH=1 else [ "$(cat "${TEMP_PREFIX}-list" | sed -e "${SED_GET_FILENAME}" | grep $(echo "${TRASH}" | sed -e "${SED_GET_FILENAME}"))" ] || ISTRASH=1 @@ -187,13 +187,12 @@ Check_Files() { if [ ! "${ISNEW}" ]; then [ "${NOCLEAN}" ] || Cleanup_Repository - echo "Checking for errors..." + printf "Checking for errors..." > "${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}" | egrep -v ^$)" ]; then - echo - echo "Not a valid danbooru file: $(echo ${FILE} | sed -e "${SED_GET_FILENAME}")" + if [ "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then + printf "\nNot a valid danbooru file: $(echo ${FILE} | sed -e "${SED_GET_FILENAME}")\n" else if [ "$(${MD5} "${FILE}" | cut -d ' ' -f1 -)" != "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME}" | cut -d '.' -f1)" ] then @@ -204,29 +203,30 @@ printf "." fi done - echo + echo " done" TOTAL_ERROR=$(echo $(wc -l < "${TEMP_PREFIX}-error")) - echo "${TOTAL_ERROR} file(s) error" - echo "Removing error files" if [ "${TOTAL_ERROR}" -eq 0 ]; then - echo "No error file. 0 file removed" + echo "All files OK" else + printf "${TOTAL_ERROR} file(s) broken: removing..." cat "${TEMP_PREFIX}-error" | xargs rm - echo "${TOTAL_ERROR} file(s) removed" + echo " ${TOTAL_ERROR} file(s) removed" fi echo "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}") file(s) available locally" - echo "Generating list of new files..." + printf "Generating list of new files..." # THE FILES #ls "../${TARGET_DIR}" | grep -vf "${TARGET_DIR}-error" > "${TARGET_DIR}-ok" # 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" | egrep -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" + printf "." + done < "${TEMP_PREFIX}-ok" + #cat "${TEMP_PREFIX}-list" | egrep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist" + echo " done" echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded" else @@ -244,7 +244,7 @@ if [ "$(echo $(wc -l < "${TEMP_PREFIX}-newlist"))" -eq 0 ]; then echo "No new file" else - echo "Starting wget" + printf "Starting wget..." cd "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" wget -e continue=on -bi "${TEMP_PREFIX}-newlist" -o "${TEMP_PREFIX}.log" fi