comparison 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
comparison
equal deleted inserted replaced
199:b9b90671616a 200:8efa600ebfdb
98 </xsl:template> 98 </xsl:template>
99 </xsl:stylesheet> 99 </xsl:stylesheet>
100 EOF 100 EOF
101 NUMFILES=$(echo $(wc -l < "${TEMP_PREFIX}-list")) 101 NUMFILES=$(echo $(wc -l < "${TEMP_PREFIX}-list"))
102 [ "${NUMFILES}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site" 102 [ "${NUMFILES}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site"
103 echo "${NUMFILES} file(s) available on server" 103 echo " ${NUMFILES} file(s) available on server"
104 #output file: ${TARGET_DIR}-list 104 #output file: ${TARGET_DIR}-list
105 }
106
107 # getting rid of ls (as per suggestion)
108 Count_Files() {
109 _i=0
110 for _f in "${*}/"* "${*}/".*; do
111 if [ "${_f}" != '*' ] || [ -e "${_f}" ]; then
112 _i=$((_i + 1))
113 fi
114 done
115 echo $((_i - 2))
105 } 116 }
106 117
107 # check tools availability 118 # check tools availability
108 Check_Tools() { 119 Check_Tools() {
109 # verify all programs required do indeed exist 120 # verify all programs required do indeed exist
144 if [ ! -O "${BASE_DIR}/${FOLDER}" ]; then 155 if [ ! -O "${BASE_DIR}/${FOLDER}" ]; then
145 echo "You don't own the ${BASE_DIR}/${FOLDER}, applying globally writeable permission on it" 156 echo "You don't own the ${BASE_DIR}/${FOLDER}, applying globally writeable permission on it"
146 chmod -R u=rwX,g=rwX,o=rwX "${BASE_DIR}/${FOLDER}" || Err_Fatal "Error changing ownership. This shouldn't happen" 157 chmod -R u=rwX,g=rwX,o=rwX "${BASE_DIR}/${FOLDER}" || Err_Fatal "Error changing ownership. This shouldn't happen"
147 fi 158 fi
148 done 159 done
149 [ "$(echo $(ls "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" | wc -l))" -eq 0 ] && ISNEW=1 160 [ "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}")" -eq 0 ] && ISNEW=1
150 for i in error ok list newlist; do 161 for i in error ok list newlist; do
151 touch "${TEMP_PREFIX}-${i}" || Fatal_Err "Error creating ${TEMP_PREFIX}-${i}. This shouldn't happen" 162 touch "${TEMP_PREFIX}-${i}" || Fatal_Err "Error creating ${TEMP_PREFIX}-${i}. This shouldn't happen"
152 done 163 done
153 # 164 #
154 } 165 }
186 # check files correctness 197 # check files correctness
187 Check_Files() { 198 Check_Files() {
188 if [ ! "${ISNEW}" ]; then 199 if [ ! "${ISNEW}" ]; then
189 [ "${NOCLEAN}" ] || Cleanup_Repository 200 [ "${NOCLEAN}" ] || Cleanup_Repository
190 echo "Checking for errors..." 201 echo "Checking for errors..."
191 cd "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}"
192 > "${TEMP_PREFIX}-error" 202 > "${TEMP_PREFIX}-error"
193 for FILE in * 203 for FILE in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
194 do 204 do
195 if [ "$(echo "${FILE}" | sed -e "${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then 205 if [ "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then
196 echo 206 echo
197 echo "Not a valid danbooru file: ${FILE}" 207 echo "Not a valid danbooru file: $(echo ${FILE} | sed -e "${SED_GET_FILENAME}")"
198 else 208 else
199 if [ "$(${MD5} "${FILE}" | cut -d ' ' -f1 -)" != "$(echo "${FILE}" | cut -d '.' -f1)" ] 209 if [ "$(${MD5} "${FILE}" | cut -d ' ' -f1 -)" != "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME}" | cut -d '.' -f1)" ]
200 then 210 then
201 echo "${FILE}" >> "${TEMP_PREFIX}-error" 211 echo "${FILE}" >> "${TEMP_PREFIX}-error"
202 echo 212 echo
203 echo "Error: ${FILE}" 213 echo "Error: $(echo "${FILE}" | sed -e "${SED_GET_FILENAME}")"
204 fi 214 fi
205 printf "." 215 printf "."
206 fi 216 fi
207 done 217 done
208 echo 218 echo
209 TOTAL_ERROR=$(echo "$(wc -l < "${TEMP_PREFIX}-error")") 219 TOTAL_ERROR=$(echo $(wc -l < "${TEMP_PREFIX}-error"))
210 echo "${TOTAL_ERROR} file(s) error" 220 echo "${TOTAL_ERROR} file(s) error"
211 echo "Removing error files" 221 echo "Removing error files"
212 if [ "${TOTAL_ERROR}" -eq 0 ]; then 222 if [ "${TOTAL_ERROR}" -eq 0 ]; then
213 echo "No error file. 0 file removed" 223 echo "No error file. 0 file removed"
214 else 224 else
215 cat "${TEMP_PREFIX}-error" | xargs rm 225 cat "${TEMP_PREFIX}-error" | xargs rm
216 echo "${TOTAL_ERROR} file(s) removed" 226 echo "${TOTAL_ERROR} file(s) removed"
217 fi 227 fi
218 echo "$(echo $(ls | wc -l)) file(s) available locally" 228 echo "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}") file(s) available locally"
219
220 # current dir: ${BASE_DIR}/temp
221 cd "${BASE_DIR}/temp"
222 229
223 echo "Generating list of new files..." 230 echo "Generating list of new files..."
224 # THE FILES 231 # THE FILES
225 #ls "../${TARGET_DIR}" | grep -vf "${TARGET_DIR}-error" > "${TARGET_DIR}-ok" 232 #ls "../${TARGET_DIR}" | grep -vf "${TARGET_DIR}-error" > "${TARGET_DIR}-ok"
226 # 233 #
227 find "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" | sed -e "${SED_GET_FILENAME}" | sort | comm -1 -3 "${TEMP_PREFIX}-error" - > "${TEMP_PREFIX}-ok" 234 find "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" | comm -1 -3 "${TEMP_PREFIX}-error" - | sed -e "${SED_GET_FILENAME}" > "${TEMP_PREFIX}-ok"
228 cat "${TEMP_PREFIX}-list" | grep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist" 235 cat "${TEMP_PREFIX}-list" | grep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist"
229 echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded" 236 echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded"
230 237
231 else 238 else
232 if [ "${ISQUICK}" ]; then 239 if [ "${ISQUICK}" ]; then
233 echo "quick mode selected. Skipping check" 240 echo "quick mode selected. Skipping check"
234 else 241 else
235 echo "Empty local repository" 242 echo "Empty local repository"
236 fi 243 fi
237 cd "${BASE_DIR}/temp" 244 cat "${TEMP_PREFIX}-list" > "${TEMP_PREFIX}-newlist"
238 cat "${SITE_DIR}-${TARGET_DIR}-list" > "${SITE_DIR}-${TARGET_DIR}-newlist"
239 fi 245 fi
240 } 246 }
241 247
242 # start downloading the images 248 # start downloading the images
243 Fetch_Images() { 249 Fetch_Images() {