-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild-genlog
More file actions
73 lines (68 loc) · 2.52 KB
/
build-genlog
File metadata and controls
73 lines (68 loc) · 2.52 KB
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
#!/bin/bash
## generating devices logs for build-json
SCRIPTNAME=$(basename $BASH_SOURCE)
## import vars
source build-config.txt
## temp vars
product_device=(${DEVICES//,/ })
IN=0
NUM=0
## remove old logs
if [ -f "$TMPDIR/${product_device[0]}.txt" ]
then
if [ "$1" = "del" ]
then
while [ 1 ]
do
if [ -z ${product_device[$IN]} ]
then IN=0 && break
else rm $TMPDIR/${product_device[$IN]}.txt $TMPDIR/re_${product_device[$IN]}.txt && IN=$IN+1
fi
done
else echo 'Old device logs found, use '"'$SCRIPTNAME del'"' to delete. Exit.' && exit 0
fi
fi
## bash function
sort_list_function () {
## list
i=0
while read line
do array_zip[ $i ]="$line"; (( i++ ))
done < <(find $ROMDIR -type f \( -name "*.zip" \) -printf "%f\n" | grep ${product_device[$IN]})
i=0
while read line
do array_img[ $i ]="$line"; (( i++ ))
done < <(find $ROMDIR -type f \( -name "*.img" \) -printf "%f\n" | grep ${product_device[$IN]})
## sort list
IFS=$'\n'; sorted_zip=($(sort <<<"${array_zip[*]}")); sorted_img=($(sort <<<"${array_img[*]}")); unset IFS
}
## start
sort_list_function
## generate log
while [ 1 ]
do
if [ $NUM -eq 0 ]
then echo "Generate log, total builds of ${product_device[$IN]}: ${#array_img[@]}, total devices: ${#product_device[@]}"
fi
if [ -z ${sorted_img[$NUM]} ]
then
cp $TMPDIR/${product_device[$IN]}.txt $TMPDIR/re_${product_device[$IN]}.txt
ex -s +%g/^/m0 +wq $TMPDIR/re_${product_device[$IN]}.txt
(( IN++ )) && NUM=0
if [ -z ${product_device[$IN]} ]; then break; fi
## call function
sort_list_function
else
IFS='-'; read -a segment_zip <<< "${sorted_zip[$NUM]}"; read -a segment_img <<< "${sorted_img[$NUM]}"; unset IFS
## data
date -d ${segment_zip[2]} +%Y-%m-%d >> $TMPDIR/${product_device[$IN]}.txt
date -d ${segment_zip[2]} +%s >> $TMPDIR/${product_device[$IN]}.txt
sha256sum $ROMDIR/${sorted_zip[$NUM]} | awk '{print $1}' >> $TMPDIR/${product_device[$IN]}.txt
du -b $ROMDIR/${sorted_zip[$NUM]} | awk '{print $1}' >> $TMPDIR/${product_device[$IN]}.txt
echo ${sorted_zip[$NUM]} >> $TMPDIR/${product_device[$IN]}.txt
sha256sum $ROMDIR/${sorted_img[$NUM]} | awk '{print $1}' >> $TMPDIR/${product_device[$IN]}.txt
du -b $ROMDIR/${sorted_img[$NUM]} | awk '{print $1}' >> $TMPDIR/${product_device[$IN]}.txt
echo ${sorted_img[$NUM]} >> $TMPDIR/${product_device[$IN]}.txt
(( NUM++ ))
fi
done