Mercurial > ec-dotfiles
diff moefetch.sh @ 200:8efa600ebfdb
purge ls
author | edhoprima@gmail.com <edhoprima@gmail.com> |
---|---|
date | Mon, 29 Jun 2009 15:29:08 +0000 |
parents | b9b90671616a |
children | 30d2fb656029 |
line wrap: on
line diff
--- a/moefetch.sh Mon Jun 29 12:29:04 2009 +0000 +++ b/moefetch.sh Mon Jun 29 15:29:08 2009 +0000 @@ -100,10 +100,21 @@ EOF 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" + echo " ${NUMFILES} file(s) available on server" #output file: ${TARGET_DIR}-list } +# getting rid of ls (as per suggestion) +Count_Files() { + _i=0 + for _f in "${*}/"* "${*}/".*; do + if [ "${_f}" != '*' ] || [ -e "${_f}" ]; then + _i=$((_i + 1)) + fi + done + echo $((_i - 2)) +} + # check tools availability Check_Tools() { # verify all programs required do indeed exist @@ -146,7 +157,7 @@ chmod -R u=rwX,g=rwX,o=rwX "${BASE_DIR}/${FOLDER}" || Err_Fatal "Error changing ownership. This shouldn't happen" fi done - [ "$(echo $(ls "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" | wc -l))" -eq 0 ] && ISNEW=1 + [ "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}")" -eq 0 ] && ISNEW=1 for i in error ok list newlist; do touch "${TEMP_PREFIX}-${i}" || Fatal_Err "Error creating ${TEMP_PREFIX}-${i}. This shouldn't happen" done @@ -188,25 +199,24 @@ if [ ! "${ISNEW}" ]; then [ "${NOCLEAN}" ] || Cleanup_Repository echo "Checking for errors..." - cd "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" > "${TEMP_PREFIX}-error" - for FILE in * + for FILE in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"* do - if [ "$(echo "${FILE}" | sed -e "${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then + if [ "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then echo - echo "Not a valid danbooru file: ${FILE}" + echo "Not a valid danbooru file: $(echo ${FILE} | sed -e "${SED_GET_FILENAME}")" else - if [ "$(${MD5} "${FILE}" | cut -d ' ' -f1 -)" != "$(echo "${FILE}" | cut -d '.' -f1)" ] + if [ "$(${MD5} "${FILE}" | cut -d ' ' -f1 -)" != "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME}" | cut -d '.' -f1)" ] then echo "${FILE}" >> "${TEMP_PREFIX}-error" echo - echo "Error: ${FILE}" + echo "Error: $(echo "${FILE}" | sed -e "${SED_GET_FILENAME}")" fi printf "." fi done echo - TOTAL_ERROR=$(echo "$(wc -l < "${TEMP_PREFIX}-error")") + TOTAL_ERROR=$(echo $(wc -l < "${TEMP_PREFIX}-error")) echo "${TOTAL_ERROR} file(s) error" echo "Removing error files" if [ "${TOTAL_ERROR}" -eq 0 ]; then @@ -215,16 +225,13 @@ cat "${TEMP_PREFIX}-error" | xargs rm echo "${TOTAL_ERROR} file(s) removed" fi - echo "$(echo $(ls | wc -l)) file(s) available locally" - - # current dir: ${BASE_DIR}/temp - cd "${BASE_DIR}/temp" + echo "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}") file(s) available locally" echo "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}" | sed -e "${SED_GET_FILENAME}" | sort | comm -1 -3 "${TEMP_PREFIX}-error" - > "${TEMP_PREFIX}-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" | grep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist" echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded" @@ -234,8 +241,7 @@ else echo "Empty local repository" fi - cd "${BASE_DIR}/temp" - cat "${SITE_DIR}-${TARGET_DIR}-list" > "${SITE_DIR}-${TARGET_DIR}-newlist" + cat "${TEMP_PREFIX}-list" > "${TEMP_PREFIX}-newlist" fi }