comparison moefetch.sh @ 205:2e866999c042

now with useless animation
author edhoprima@gmail.com <edhoprima@gmail.com>
date Mon, 29 Jun 2009 17:03:35 +0000
parents fb02adf58c00
children a44ba2e495a1
comparison
equal deleted inserted replaced
204:fb02adf58c00 205:2e866999c042
101 [ "${NUMFILES}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site" 101 [ "${NUMFILES}" -gt 0 ] || Err_Fatal "Error in processing list or no files can be found with specified tag(s) or site"
102 echo " ${NUMFILES} file(s) available on server" 102 echo " ${NUMFILES} file(s) available on server"
103 #output file: ${TARGET_DIR}-list 103 #output file: ${TARGET_DIR}-list
104 } 104 }
105 105
106 Progress_Init() {
107 _last="-"
108 printf "${_last}"
109 }
110
111 Progress_Anim() {
112 case "${_last}" in
113 /) _last="-";;
114 -) _last=\\;;
115 \\) _last=\|;;
116 \|) _last="/";;
117 esac
118 printf "\b${_last}"
119 }
120
121 Progress_Done() { printf "\bdone\n"; }
122
106 # getting rid of ls (as per suggestion) 123 # getting rid of ls (as per suggestion)
107 Count_Files() { 124 Count_Files() {
108 _i=0 125 _i=0
109 for _f in "${*}/"* "${*}/".*; do 126 for _f in "${*}/"* "${*}/".*; do
110 if [ "${_f}" != '*' ] || [ -e "${_f}" ]; then 127 if [ "${_f}" != '*' ] || [ -e "${_f}" ]; then
157 Cleanup_Repository() { 174 Cleanup_Repository() {
158 175
159 # THE FILES 176 # THE FILES
160 177
161 # current dir: ${BASE_DIR}/${SITE_DIR}/${TARGET_DIR} 178 # current dir: ${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}
162 printf "Cleaning up repository folder" 179 printf "Cleaning up repository folder..."
180 Progress_Init
163 TRASH_DIR=$(date -u "+${SITE_DIR}-${TARGET_DIR}-%Y%m%d-%H.%M") 181 TRASH_DIR=$(date -u "+${SITE_DIR}-${TARGET_DIR}-%Y%m%d-%H.%M")
164 mkdir -p "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Unable to create trash folder" 182 mkdir -p "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Unable to create trash folder"
165 for TRASH in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"* 183 for TRASH in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
166 do 184 do
167 ISTRASH= 185 ISTRASH=
176 fi 194 fi
177 if [ "${ISTRASH}" ]; then 195 if [ "${ISTRASH}" ]; then
178 mv -f "${TRASH}" "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Error deleting files" 196 mv -f "${TRASH}" "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Error deleting files"
179 echo "Moved $(echo "${TRASH}" | sed -e "${SED_GET_FILENAME}") to ${BASE_DIR}/trash/${TRASH_DIR}" 197 echo "Moved $(echo "${TRASH}" | sed -e "${SED_GET_FILENAME}") to ${BASE_DIR}/trash/${TRASH_DIR}"
180 fi 198 fi
181 printf "." 199 Progress_Anim
182 done 200 done
183 echo "done"
184 rmdir "${BASE_DIR}/trash/${TRASH_DIR}" 2>/dev/null 201 rmdir "${BASE_DIR}/trash/${TRASH_DIR}" 2>/dev/null
202 Progress_Done
185 } 203 }
186 204
187 # check files correctness 205 # check files correctness
188 Check_Files() { 206 Check_Files() {
189 if [ ! "${ISNEW}" ]; then 207 if [ ! "${ISNEW}" ]; then
190 [ "${NOCLEAN}" ] || Cleanup_Repository 208 [ "${NOCLEAN}" ] || Cleanup_Repository
191 printf "Checking for errors" 209 printf "Checking for errors..."
210 Progress_Init
192 > "${TEMP_PREFIX}-error" 211 > "${TEMP_PREFIX}-error"
193 for FILE in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"* 212 for FILE in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
194 do 213 do
195 if [ "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then 214 if [ "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME};${SED_IS_MD5_FILE}" | grep -v ^$)" ]; then
196 printf "\nNot a valid danbooru file: $(echo ${FILE} | sed -e "${SED_GET_FILENAME}")\n" 215 printf "\nNot a valid danbooru file: $(echo ${FILE} | sed -e "${SED_GET_FILENAME}")\n${_last}"
197 else 216 else
198 if [ "$(${MD5} "${FILE}" | cut -d ' ' -f1 -)" != "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME}" | cut -d '.' -f1)" ] 217 if [ "$(${MD5} "${FILE}" | cut -d ' ' -f1 -)" != "$(echo "${FILE}" | sed -e "${SED_GET_FILENAME}" | cut -d '.' -f1)" ]
199 then 218 then
200 echo "${FILE}" >> "${TEMP_PREFIX}-error" 219 echo "${FILE}" >> "${TEMP_PREFIX}-error"
201 echo 220 echo
202 echo "Error: $(echo "${FILE}" | sed -e "${SED_GET_FILENAME}")" 221 echo "Error: $(echo "${FILE}" | sed -e "${SED_GET_FILENAME}")"
203 fi 222 fi
204 printf "." 223 Progress_Anim
205 fi 224 fi
206 done 225 done
207 echo "done" 226 Progress_Done
208 TOTAL_ERROR=$(echo $(wc -l < "${TEMP_PREFIX}-error")) 227 TOTAL_ERROR=$(echo $(wc -l < "${TEMP_PREFIX}-error"))
209 if [ "${TOTAL_ERROR}" -eq 0 ]; then 228 if [ "${TOTAL_ERROR}" -eq 0 ]; then
210 echo "All files OK" 229 echo "All files OK"
211 else 230 else
212 printf "${TOTAL_ERROR} file(s) broken: removing..." 231 printf "${TOTAL_ERROR} file(s) broken: removing..."
214 echo " ${TOTAL_ERROR} file(s) removed" 233 echo " ${TOTAL_ERROR} file(s) removed"
215 fi 234 fi
216 echo "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}") file(s) available locally" 235 echo "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}") file(s) available locally"
217 236
218 printf "Generating list of new files..." 237 printf "Generating list of new files..."
238 Progress_Init
219 # THE FILES 239 # THE FILES
220 #ls "../${TARGET_DIR}" | grep -vf "${TARGET_DIR}-error" > "${TARGET_DIR}-ok" 240 #ls "../${TARGET_DIR}" | grep -vf "${TARGET_DIR}-error" > "${TARGET_DIR}-ok"
221 # 241 #
222 find "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" | comm -1 -3 "${TEMP_PREFIX}-error" - | sed -e "${SED_GET_FILENAME}" > "${TEMP_PREFIX}-ok" 242 find "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}" | comm -1 -3 "${TEMP_PREFIX}-error" - | sed -e "${SED_GET_FILENAME}" > "${TEMP_PREFIX}-ok"
223 cat "${TEMP_PREFIX}-list" > "${TEMP_PREFIX}-templist" 243 cat "${TEMP_PREFIX}-list" > "${TEMP_PREFIX}-templist"
224 while read -r IS_OK; do 244 while read -r IS_OK; do
225 cat "${TEMP_PREFIX}-templist" | grep -v "${IS_OK}" > "${TEMP_PREFIX}-newlist" 245 cat "${TEMP_PREFIX}-templist" | grep -v "${IS_OK}" > "${TEMP_PREFIX}-newlist"
226 cat "${TEMP_PREFIX}-newlist" > "${TEMP_PREFIX}-templist" 246 cat "${TEMP_PREFIX}-newlist" > "${TEMP_PREFIX}-templist"
227 printf "." 247 Progress_Anim
228 done < "${TEMP_PREFIX}-ok" 248 done < "${TEMP_PREFIX}-ok"
249 Progress_Done
229 #cat "${TEMP_PREFIX}-list" | egrep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist" 250 #cat "${TEMP_PREFIX}-list" | egrep -vf "${TEMP_PREFIX}-ok" > "${TEMP_PREFIX}-newlist"
230 echo " done"
231 echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded" 251 echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded"
232 252
233 else 253 else
234 if [ "${ISQUICK}" ]; then 254 if [ "${ISQUICK}" ]; then
235 echo "quick mode selected. Skipping check" 255 echo "quick mode selected. Skipping check"