comparison moefetch.sh @ 191:a4ceb952b05a

more noclean support code
author edhoprima@gmail.com <edhoprima@gmail.com>
date Sun, 28 Jun 2009 17:18:41 +0000
parents 1061a214a1f1
children 47efb7a23425
comparison
equal deleted inserted replaced
190:1061a214a1f1 191:a4ceb952b05a
150 150
151 # THE FILES 151 # THE FILES
152 152
153 # current dir: ${BASE_DIR}/${SITE_DIR}/${TARGET_DIR} 153 # current dir: ${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}
154 echo "Cleaning up repository folder..." 154 echo "Cleaning up repository folder..."
155 TRASH_DIR="${SITE_DIR}-${TARGET_DIR}-`date -u +%Y%m%d-%H.%M`" 155 TRASH_DIR=$(date -u "+${SITE_DIR}-${TARGET_DIR}-%Y%m%d-%H.%M")
156 mkdir -p "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Unable to create trash folder" 156 mkdir -p "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Unable to create trash folder"
157 for TRASH in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"* 157 for TRASH in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
158 do 158 do
159 ISTRASH= 159 ISTRASH=
160 if [ -d "${TRASH}" ]; then 160 if [ -d "${TRASH}" ]; then
161 ISTRASH=1 161 ISTRASH=1
162 else 162 else
163 [ "`echo \"${FILE}\" | sed -e 's/.*\/\([\^\/]*\)/\1/g;s/\([0-9a-f]\{32\}.*\)//g' | grep -v ^$`" ] && ISTRASH=1 163 if [ "$(echo "${FILE}" | sed -e 's/.*\/\([\^\/]*\)/\1/g;s/\([0-9a-f]\{32\}.*\)//g' | grep -v ^$)" ]; then
164 ISTRASH=1
165 else
166 [ "$(cat "${BASE_DIR}/temp/${TARGET_DIR}-list" | sed -e 's/.*\/\([^\/]*\)/\1/g' | grep $(echo "${TRASH}" | sed -e 's/.*\/\([^\/]*\)/\1/g'))" ] || ISTRASH=1
167 fi
164 fi 168 fi
165 if [ "${ISTRASH}" ]; then 169 if [ "${ISTRASH}" ]; then
166 mv -f "${TRASH}" "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Error deleting files" 170 mv -f "${TRASH}" "${BASE_DIR}/trash/${TRASH_DIR}" || Err_Fatal "Error deleting files"
167 echo "Moved ${TRASH} to ${BASE_DIR}/trash/${TRASH_DIR}" 171 echo "Moved ${TRASH} to ${BASE_DIR}/trash/${TRASH_DIR}"
168 fi 172 fi
169 done 173 done
170 rmdir "${BASE_DIR}/trash/${TRASH_DIR}" 2>/dev/null 174 rmdir "${BASE_DIR}/trash/${TRASH_DIR}" 2>/dev/null
175
171 } 176 }
172 177
173 # check files correctness 178 # check files correctness
174 Check_Files() { 179 Check_Files() {
175 if [ ! "${ISNEW}" ]; then 180 if [ ! "${ISNEW}" ]; then
182 if [ "`echo \"${FILE}\" | sed -e 's/\([0-9a-f]\{32\}.*\)//g' | grep -v ^$`" ]; then 187 if [ "`echo \"${FILE}\" | sed -e 's/\([0-9a-f]\{32\}.*\)//g' | grep -v ^$`" ]; then
183 echo "Not a valid danbooru file: ${FILE}" 188 echo "Not a valid danbooru file: ${FILE}"
184 else 189 else
185 if [ "`${MD5} "${FILE}" | cut -d ' ' -f1 -`" != "`echo "${FILE}" | cut -d '.' -f1`" ] 190 if [ "`${MD5} "${FILE}" | cut -d ' ' -f1 -`" != "`echo "${FILE}" | cut -d '.' -f1`" ]
186 then 191 then
192 echo "${FILE}" >> "${BASE_DIR}/temp/${SITE_DIR}-${TARGET_DIR}-error"
187 echo 193 echo
188 echo "${FILE}" >> "${BASE_DIR}/temp/${SITE_DIR}-${TARGET_DIR}-error"
189 echo "Error: ${FILE}" 194 echo "Error: ${FILE}"
190 fi 195 fi
191 printf "." 196 printf "."
192 fi 197 fi
193 done 198 done