diff moefetch.sh @ 223:04ad0b0a3c63

revert back to [
author edhoprima@gmail.com <edhoprima@gmail.com>
date Thu, 02 Jul 2009 21:32:45 +0000
parents e3fb9507cf7f
children 0ac1805621d4
line wrap: on
line diff
--- a/moefetch.sh	Thu Jul 02 20:37:41 2009 +0000
+++ b/moefetch.sh	Thu Jul 02 21:32:45 2009 +0000
@@ -135,7 +135,7 @@
 Count_Files() {
 	_i=0
 	for _f in "${*}/"* "${*}/".*; do 
-		if test "${_f}" != "${*}/"'*' || test -e "${_f}"; then 
+		if [ "${_f}" != "${*}/*" ] || [ -e "${_f}" ]; then 
 			_i=$((_i + 1))
 		fi
 	done
@@ -146,7 +146,7 @@
 Check_Tools() {
 	# verify all programs required do indeed exist
 	#MD5
-	if test -z "${MD5}"; then
+	if [ -z "${MD5}" ]; then
 		case "$(uname)" in
 			*BSD) MD5="md5 -r";;
 			Linux|SunOS) MD5="md5sum";;
@@ -164,7 +164,7 @@
 
 # verify required folders exist and writeable
 Check_Folders(){
-	test -O "${BASE_DIR}" || Err_Fatal "You don't own ${BASE_DIR}. Please fix ${BASE_DIR} or run this script in your own directory."
+	[ -O "${BASE_DIR}" ] || Err_Fatal "You don't own ${BASE_DIR}. Please fix ${BASE_DIR} or run this script in your own directory."
 	for directory in temp trash deleted "${SITE_DIR}/${TARGET_DIR}"; do
 		if [ ! -d "${BASE_DIR}/${directory}" ]; then
 			mkdir -p "${BASE_DIR}/${directory}" || Err_Impossible
@@ -174,7 +174,7 @@
 			chmod -R u=rwX,g=rwX,o=rwX "${BASE_DIR}/${directory}" || Err_Impossible
 		fi
 	done
-	test "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}")" -eq 0 && ISNEW=1
+	[ "$(Count_Files "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}")" -eq 0 ] && ISNEW=1
 	for i in error ok list newlist templist; do
 		touch "${TEMP_PREFIX}-${i}" || Fatal_Err "Error creating ${TEMP_PREFIX}-${i}. This shouldn't happen"
 	done
@@ -189,17 +189,17 @@
 	trash_dir="${BASE_DIR}/trash/${trash_dir}/$(date -u "+${SITE_DIR}-${TARGET_DIR}-%Y%m%d-%H.%M")"
 	trashes="These files have been moved to ${trash_dir}:"
 	has_trash=
-	if test ! -d "${trash_dir}"; then
+	if [ ! -d "${trash_dir}" ]; then
 		mkdir -p "${trash_dir}" || Err_Impossible
 	else
-		if test ! -o "${trash_dir}"; then
+		if [ ! -O "${trash_dir}" ]; then
 			chmod -R u=rwX,g=rwX,o=rwX "${BASE_DIR}/${directory}" || Err_Impossible
 		fi
 	fi
 	for trash in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
 	do
 		is_trash=
-		if test -d "${trash}" || test -n "$(Is_NotMD5 "$(basename "${trash}")")" || test -z "$(grep "$(basename "${trash}")" "${TEMP_PREFIX}-list")"; then
+		if [ -d "${trash}" ] || [ -n "$(Is_NotMD5 "$(basename "${trash}")")" ] || [ -z "$(grep "$(basename "${trash}")" "${TEMP_PREFIX}-list")" ]; then
 			is_trash=1
 			has_trash=1
 			mv -f "${trash}" "${trash_dir}" || Err_Impossible
@@ -210,13 +210,13 @@
 	done
 	rmdir "${trash_dir}" 2>/dev/null
 	Progress_Done
-	test -n "${has_trash}" && echo "${trashes}"
+	[ -n "${has_trash}" ] && echo "${trashes}"
 }
 
 # check files correctness
 Check_Files() {
-	if test ! -n "${ISNEW}"; then
-		test -z "${NOCLEAN}" && Cleanup_Repository
+	if [ ! -n "${ISNEW}" ]; then
+		[ -z "${NOCLEAN}" ] && Cleanup_Repository
 		printf "Checking for errors... "
 		Progress_Init
 		files_error="These files do not match its md5:"
@@ -227,13 +227,13 @@
 		> "${TEMP_PREFIX}-ok"
 		for file in "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/"*
 		do
-			if test "${file}" != "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/*"; then
-				if test -n "$(Is_NotMD5 "$(basename "${file}")")" || test -d "${file}"; then
+			if [ "${file}" != "${BASE_DIR}/${SITE_DIR}/${TARGET_DIR}/*" ]; then
+				if [ -n "$(Is_NotMD5 "$(basename "${file}")")" ] || [ -d "${file}" ]; then
 					files_notdanbooru="${files_notdanbooru}
   $(basename "${file}")"
 					has_err_filename=1
 				else
-					if test "$(${MD5} "${file}" | cut -d ' ' -f 1)" = "$(basename "${file}" | cut -d '.' -f 1)"; then
+					if [ "$(${MD5} "${file}" | cut -d ' ' -f 1)" = "$(basename "${file}" | cut -d '.' -f 1)" ]; then
 						echo "$(basename "${file}")" >> "${TEMP_PREFIX}-ok"
 					else
 						rm "${file}" || Err_Fatal "Error removing ${file}"
@@ -247,14 +247,14 @@
 			Progress_Anim
 		done
 		Progress_Done
-		if test ! -n "${has_err_md5}" && test ! -n "${has_err_filename}"; then
+		if [ ! -n "${has_err_md5}" ] && [ ! -n "${has_err_filename}" ]; then
 			echo "All files OK"
 		else
-			if test -n "${has_err_md5}"; then
+			if [ -n "${has_err_md5}" ]; then
 				echo "${files_error}"
 				echo "$(echo $(wc -l < "${TEMP_PREFIX}-error")) file(s) removed"
 			fi
-			test -n "${has_err_filename}" && echo "${files_notdanbooru}" 
+			[ -n "${has_err_filename}" ] && echo "${files_notdanbooru}" 
 		fi
 		echo "$(echo $(wc -l < "${TEMP_PREFIX}-ok")) file(s) available locally"
 
@@ -269,7 +269,7 @@
 		Progress_Done
 		echo "$(echo $(wc -l < "${TEMP_PREFIX}-newlist")) file(s) to be downloaded"		
 	else
-		if test -n "${ISQUICK}"; then
+		if [ -n "${ISQUICK}" ]; then
 			echo "Quick mode selected. Skipping check"
 		else
 			echo "Empty local repository"
@@ -280,7 +280,7 @@
 
 # start downloading the images
 Fetch_Images() {
-	if test "$(echo $(wc -l < "${TEMP_PREFIX}-newlist"))" -eq 0; then
+	if [ "$(echo $(wc -l < "${TEMP_PREFIX}-newlist"))" -eq 0 ]; then
 		echo "No new file"
 	else
 		printf "Starting wget... "
@@ -292,7 +292,7 @@
 # initialize base variables and initial command check
 Init(){
 	# path initialization
-	test -n "${ADDITIONAL_PATH}" && PATH="${ADDITIONAL_PATH}:${PATH}"
+	[ -n "${ADDITIONAL_PATH}" ] && PATH="${ADDITIONAL_PATH}:${PATH}"
 	export PATH
 	
 	# misc variables
@@ -331,12 +331,12 @@
 		esac
 		shift
 	done
-	test -n "${SITE}" || SITE=${DEFAULT_SITE}
-	test -n "${TAGS}" || Err_Fatal "No tag specified"
+	[ -n "${SITE}" ] || SITE=${DEFAULT_SITE}
+	[ -n "${TAGS}" ] || Err_Fatal "No tag specified"
 	# Get base folder - default, current folder or fallback to ${HOME}
-	test -n "${BASE_DIR}" || BASE_DIR=${PWD}
-	test -n "${BASE_DIR}" || BASE_DIR=${HOME}
-	test -n "$(echo "${BASE_DIR}" | cut -c1 | grep \/)" || BASE_DIR="/${BASE_DIR}"	
+	[ -n "${BASE_DIR}" ] || BASE_DIR=${PWD}
+	[ -n "${BASE_DIR}" ] || BASE_DIR=${HOME}
+	[ -n "$(echo "${BASE_DIR}" | cut -c1 | grep \/)" ] || BASE_DIR="/${BASE_DIR}"	
 
 	echo "Tags: ${TAGS}"
 	# slash is not wanted for folder name