comparison moefetch.sh @ 229:b03fef57b465

- Fixed getopts, now that I remember where I take the code from
author edhoprima@gmail.com <edhoprima@gmail.com>
date Sun, 27 Dec 2009 19:18:02 +0000
parents 5d3a0645b504
children e922fb1e858f
comparison
equal deleted inserted replaced
228:5d3a0645b504 229:b03fef57b465
136 <xsl:value-of select="@file_url" /> 136 <xsl:value-of select="@file_url" />
137 </xsl:template> 137 </xsl:template>
138 </xsl:stylesheet> 138 </xsl:stylesheet>
139 EOF 139 EOF
140 __tempnum=$(echo $(wc -l < "${TEMP_PREFIX}-templist")) 140 __tempnum=$(echo $(wc -l < "${TEMP_PREFIX}-templist"))
141 __iternum=$((__iternum + 1)) 141 __iternum=$((${__iternum} + 1))
142 cat "${TEMP_PREFIX}-templist" >> "${TEMP_PREFIX}-list" 142 cat "${TEMP_PREFIX}-templist" >> "${TEMP_PREFIX}-list"
143 echo "${__tempnum} file(s) available" 143 echo "${__tempnum} file(s) available"
144 done 144 done
145 numfiles=$(echo $(wc -l < "${TEMP_PREFIX}-list")) 145 numfiles=$(echo $(wc -l < "${TEMP_PREFIX}-list"))
146 echo "${numfiles} file(s) available on server" 146 echo "${numfiles} file(s) available on server"
168 # getting rid of ls (as per suggestion) 168 # getting rid of ls (as per suggestion)
169 Count_Files() { 169 Count_Files() {
170 numfiles=0 170 numfiles=0
171 for dircontent in "${*}/"* "${*}/".*; do 171 for dircontent in "${*}/"* "${*}/".*; do
172 if [ "${dircontent}" != "${*}/*" ] || [ -e "${dircontent}" ]; then 172 if [ "${dircontent}" != "${*}/*" ] || [ -e "${dircontent}" ]; then
173 numfiles=$((numfiles + 1)) 173 numfiles=$((${numfiles} + 1))
174 fi 174 fi
175 done 175 done
176 echo $((numfiles - 2)) 176 echo $((${numfiles} - 2))
177 } 177 }
178 178
179 # check tools availability 179 # check tools availability
180 Check_Tools() { 180 Check_Tools() {
181 # verify all programs required do indeed exist 181 # verify all programs required do indeed exist
339 *) 339 *)
340 Err_Help 340 Err_Help
341 ;; 341 ;;
342 esac 342 esac
343 shift 343 shift
344 SITE=
345 TAGS=
346 __has_pass=0 344 __has_pass=0
347 __has_user=0 345 __has_user=0
346 #copypasta from http://mywiki.wooledge.org/BashFAQ/035
347 __optnum=1
348 while getopts "s:(site)n(noclean)u:(user)p:(password)" opt 348 while getopts "s:(site)n(noclean)u:(user)p:(password)" opt
349 do 349 do
350 case "$opt" in 350 case "$opt" in
351 s) SITE="$OPTARG";; 351 s) SITE="$OPTARG";;
352 n) NOCLEAN=1;; 352 n) NOCLEAN=1;;
357 u) 357 u)
358 LOGIN_USER="$OPTARG" 358 LOGIN_USER="$OPTARG"
359 __has_user=1 359 __has_user=1
360 ;; 360 ;;
361 esac 361 esac
362 done 362 __optnum="${OPTIND}"
363 done
364 shift $((${__optnum}-1))
363 TAGS="$@" 365 TAGS="$@"
364 [ -n "${SITE}" ] || SITE=${DEFAULT_SITE} 366 [ -n "${SITE}" ] || SITE=${DEFAULT_SITE}
365 [ -n "${TAGS}" ] || Err_Fatal "No tag specified" 367 [ -n "${TAGS}" ] || Err_Fatal "No tag specified"
366 # Get base folder - default, current folder or fallback to ${HOME} 368 # Get base folder - default, current folder or fallback to ${HOME}
367 [ -n "${BASE_DIR}" ] || BASE_DIR=${PWD} 369 [ -n "${BASE_DIR}" ] || BASE_DIR=${PWD}
378 } 380 }
379 381
380 # global variables goes here 382 # global variables goes here
381 init_globals() 383 init_globals()
382 { 384 {
385 cd . # Reset ${PWD}
383 _version="0.3-beta3" # version of this script 386 _version="0.3-beta3" # version of this script
384 _use_login=0 # variable to check whether a login is used or not 387 _use_login=0 # variable to check whether a login is used or not
388 SITE=
389 TAGS=
385 } 390 }
386 391
387 main() 392 main()
388 { 393 {
389 #initialize global variables 394 #initialize global variables