|
1 |
| - |
| 1 | +# logerror "message" "/detailed/log/file" |
2 | 2 | function logerror
|
3 | 3 | {
|
4 |
| - if [ $? -ne 0 ];then |
5 |
| - if [ ! -w ${ZEND_ERROR_LOG} ]; then ZEND_ERROR_LOG=/dev/stdout; fi |
6 |
| - echo "$ZSST_PLUGIN_NAME: $1 executed, return code was not 0." >> ${ZEND_ERROR_LOG} |
| 4 | + # the point of this part is logging to STDOUT in actions |
| 5 | + if [ -z ${ZEND_ERROR_LOG} ]; then |
| 6 | + ZEND_ERROR_LOG=/dev/stdout |
| 7 | + elif [ ! -w ${ZEND_ERROR_LOG} ]; then |
| 8 | + ZEND_ERROR_LOG=/dev/stdout |
| 9 | + fi |
| 10 | + |
| 11 | + echo "$ZSST_PLUGIN_NAME: $1" >> ${ZEND_ERROR_LOG} |
| 12 | + if [ -r "$2" ]; then |
| 13 | + echo "------------- More Details -----------------------" >> ${ZEND_ERROR_LOG} |
| 14 | + cat "$2" >> ${ZEND_ERROR_LOG} |
| 15 | + echo "--------------------------------------------------" >> ${ZEND_ERROR_LOG} |
| 16 | + rm -f "$2" |
7 | 17 | fi
|
| 18 | + |
8 | 19 | }
|
9 | 20 |
|
10 | 21 |
|
11 |
| -# downloadtofile "URL" "outpit file" |
| 22 | +# downloadtofile "URL" "output file" |
12 | 23 | function downloadtofile
|
13 | 24 | {
|
14 |
| -if command -v wget > /dev/null 2>&1 ;then |
15 |
| - if wget -q --spider "$1"; then |
16 |
| - wget -O $2 $1 2>/dev/null |
17 |
| - logerror "wget $1" |
18 |
| - else |
19 |
| - # output for troubleshooting |
20 |
| - wget -nv --spider "$1" |
| 25 | +DL_LOG=/tmp/d0wnl0ad2F1L3.log |
| 26 | + |
| 27 | +if command -v wget &> /dev/null ;then |
| 28 | + if ! wget -O $2 "$1" &> $DL_LOG ; then |
| 29 | + logerror "'wget $1' FAILED" $DL_LOG |
21 | 30 | return 21
|
22 | 31 | fi
|
23 | 32 |
|
24 |
| -elif command -v aria2c > /dev/null 2>&1 ;then |
25 |
| - if aria2c -q --dry-run "$1"; then |
26 |
| - aria2c -j 1 -s 1 -o $2 $1 > /dev/null |
27 |
| - logerror "aria2c $1" |
28 |
| - else |
29 |
| - # output for troubleshooting |
30 |
| - aria2c -q -l - --log-level=warn --dry-run "$1" |
| 33 | +elif command -v aria2c &> /dev/null ;then |
| 34 | + if ! aria2c -j 1 -s 1 -o $2 "$1" &> $DL_LOG ; then |
| 35 | + logerror "'aria2c $1' FAILED" $DL_LOG |
31 | 36 | return 22
|
32 | 37 | fi
|
33 | 38 |
|
34 |
| -elif command -v curl > /dev/null 2>&1 ;then |
35 |
| - if curl -fsLIo /dev/null "$1"; then |
36 |
| - curl -sLo $2 $1 |
37 |
| - logerror "curl $1" |
38 |
| - else |
39 |
| - # output for troubleshooting |
40 |
| - curl -LI "$1" |
| 39 | +elif command -v curl &> /dev/null ;then |
| 40 | + if ! curl -Lo $2 "$1" &> $DL_LOG ; then |
| 41 | + logerror "'curl $1' FAILED" $DL_LOG |
41 | 42 | return 23
|
42 | 43 | fi
|
43 | 44 |
|
44 | 45 | else
|
45 |
| - if [ ! -w ${ZEND_ERROR_LOG} ]; then ZEND_ERROR_LOG=/dev/stdout; fi |
46 |
| - echo "wget, aria2c or curl not found." >> ${ZEND_ERROR_LOG} |
| 46 | + logerror "wget, aria2c or curl not found." |
47 | 47 | return 1
|
48 | 48 | fi
|
| 49 | +rm -f $DL_LOG |
49 | 50 | return 0
|
50 | 51 | }
|
51 | 52 |
|
|
0 commit comments