-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex
executable file
·106 lines (96 loc) · 2.79 KB
/
index
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
STORAGE="2"
[[ "$2" == "" ]] && STORAGE=NAS
URL="http://localhost:8070/files"
START=$(date +%s)
NOW_DATE=$(date +"%Y-%m-%d %T")
NOW_DATE_FN=$(echo $NOW_DATE | tr '[: ]' '_')
if [[ "$1" == "" ]]; then
echo "indexing current folder $(pwd)"
INDEX=/tmp/index_$NOW_DATE_FN
# for macos
#
ls -l -D "%F %T" -F -R > $INDEX
# for linux - format is
#-rwxr-xr-x 1 gorbush wheel 22 2017-09-03 20:37:48 dumper-freebsd.sh*
ls -l -D "%F %T" -F -R > $INDEX
else
#INDEX=/Users/spuliaiev/work_mine/PictureGallery/Trash-2018-06-09__sh.log
INDEX=$1
echo "indexing file $INDEX"
fi
# sample line
FOLDER=
function trim {
printf "%s" "`expr "$1" : "^[[:space:]]*\(.*[^[:space:]]\)[[:space:]]*$"`"
}
function trim2 {
echo $*
}
function uriencode {
s="${1//'%'/%25}"
s="${s//' '/%20}"
s="${s//'"'/%22}"
s="${s//'#'/%23}"
s="${s//'$'/%24}"
s="${s//'&'/%26}"
s="${s//'+'/%2B}"
s="${s//','/%2C}"
# s="${s//'/'/%2F}"
s="${s//':'/%3A}"
s="${s//';'/%3B}"
s="${s//'='/%3D}"
s="${s//'?'/%3F}"
s="${s//'@'/%40}"
s="${s//'['/%5B}"
s="${s//']'/%5D}"
printf %s "$s"
}
#IFS=$'\n'
#for line in $(cat $INDEX)
#do
sent=0
failed=0
exists=0
while read -r line
do
#echo "processing line $line"
# skip sub folders
[[ $line =~ ^d ]] && continue
# new folder definition
[[ $line =~ ^[.]/ ]] && FOLDER="${line#./}" && FOLDER="${FOLDER%:}" && echo " folder=$FOLDER"
# not a file
[[ ! $line =~ ^- ]] && continue
#echo " parsing..."
IFS='\t'
filesize=$(echo "$line" | awk 'BEGIN{FS=" *"} {print $5} ')
filedate=$(echo "$line" | awk 'BEGIN{FS=" *"} {print $6} ')
filetime=$(echo "$line" | awk 'BEGIN{FS=" *"} {print $7} ')
filename=$(echo "$line" | awk 'BEGIN{FS=" *"} {$1=$2=$3=$4=$5=$6=$7="";gsub(/^ +|[ *]+$/,""); print $0} ')
IFS=$'\n'
echo " size=$filesize filedate=$filedate filetime=$filetime name=${filename%\*}"
#FULLURL="$URL/$STORAGE/$filesize/${filedate}T${filetime}/$FOLDER/$filename"
THEURL="$URL/$STORAGE/$filesize/${filedate}T${filetime}/$(uriencode "$FOLDER/$filename")"
#echo " URL =$FULLURL"
#echo " URLE=$THEURL"
httpcode=$(curl -s -X PUT -o /dev/null -w "%{http_code}" "$THEURL")
if [[ "$httpcode" == "200" ]];then
#echo " posted"
sent=$(expr $sent + 1)
else
if [[ "$httpcode" == "303" ]];then
#echo " already exists"
exists=$(expr $exists + 1)
else
echo "error: $httpcode for file $filename in $FOLDER" >> errors_$NOW_DATE_FN.log
echo " curl -s -X PUT -o /dev/null -w \"%{http_code}\" \"$THEURL\"" >> errors_$NOW_DATE_FN.log
failed=$(expr $failed + 1)
fi
fi
done < "$INDEX"
END=$(date +%s)
DIFF=$(( $END - $START ))
echo "Statistics:"
printf " time : %6d seconds" $DIFF
printf " sent : %6d\n" $sent
printf " exists : %6d\n" $exists
printf " failed : %6d\n" $failed