Normalise JSON. Update todo
[PreCom.git] / cache-update-adapter.sh
1 #!/bin/bash
2 #
3 # widget: gauge
4 # description: Modifies updates ITG's cache with output
5 # tailiored to dialogs gauge widget.
6
7 while getopts ":d:" opt; do
8 case $opt in
9 d)
10 cache_dir=$OPTARG
11 ;;
12 \?)
13 echo "Invalid option: -$OPTARG" >&2
14 exit 1
15 ;;
16 :)
17 echo "Option -$OPTARG requires an argument." >&2
18 exit 1
19 ;;
20 esac
21 done
22
23 if [[ -z "$cache_dir" ]] || [[ "${cache_dir}xxx" = "xxx" ]]; then
24 echo "Cache directory not supplied.";
25 exit 1
26 fi
27
28 [[ ! -d "$cache_dir" ]] && echo 100 && exit 0
29
30 num=$(wc -l < /tmp/newsongs.txt)
31 num_processed=0
32
33 if [[ $num -gt 0 ]]; then
34 while read line; do
35 read -r changes filename <<< "$line"
36 #todo: change directory to be arg'able
37 cacheline=$(grep -F "$filename" ${cache_dir}/*)
38 IFS=":" read -r cachepath otherjunk <<< "$cacheline"
39
40 if [[ ! -z "$cachepath" ]]; then
41 rm "$cachepath"
42 fi
43 ((num_processed++))
44
45 printf '%i %i' $num_processed $num | mawk -Winteractive '{ pc=100*$1/$2; i=int(pc); print (pc-i<0.5)?i:i+1 }'
46 done < /tmp/newsongs.txt
47 else
48 echo 100
49 fi
50