aboutsummaryrefslogtreecommitdiffstats
path: root/getallpkginfo.bash
blob: cdfeab5af7fc2d42f61573caab662061e0783788 (plain)
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#!/bin/bash
#
# This script used to update Yocto Packages Report System database.
#
# This script will also send two reminding mails about recipe upgrade to mail list after database update successful, otherwise, send mail to system maint# ainer.
#
# We can decide whether we need to draw a barchart of history record or send report mail to a specific mail address.
#
#/***************************************************************************
# * This software is licensed as described in the file COPYING, which
# * you should have received as part of this distribution. 
# *
# * You may opt to use, copy, modify, merge, publish, distribute and/or sell
# * copies of the Software, and permit persons to whom the Software is
# * furnished to do so, under the terms of the COPYING file.
# *
# ***************************************************************************/



function usage() {
	echo "Usage: $0 <mailaddr> <drawchart>"
	echo ""
	echo "mailaddr: Report mail or Warning mail will send to mailaddr instead of admin mailbox"
	echo "chart: Barchart will be generated if you add the argument \"drawchart\" "
	echo ""
	echo "Without arguments, this script will send mail to default maillist and admin and execute without generate barchart"
	echo ""
}

if [ $# -gt 2 ]; then
	echo " Number of argument isn't right!"
	usage
	exit 1
fi

if [ -n "$1" ]; then
	if ! [ `echo $1 | grep "@"` ]; then
		echo "Mail address isn't right!"
		usage
		exit 1
	else
		sendemailto="$1"
	fi
fi

if [ -n "$2" ]; then
	if [ "$2" != "drawchart" ]; then
		echo "The second argument must be "drawchart"!"
		usage
		exit 1
	else
		drawchart="drawchart"
	fi
fi


#
#This function will draw a barchart contains recipe upgrade history number and manual check history number
#
function drawchart() {
	cd $FunctionHome
	python showchart.py >> $Log 1>&1
	if [ $? -eq 1 ]; then
		echo "REPORT-SYSTEM-UPDATE ERROR: Draw barchart faild!" >> $Log
	fi
}

function bitbake_engine () {
	bitbake universe -c $1 -k 2>&1 > $Log  || echo "REPORT-SYSTEM-UPDATE ERROR: Run bitbake distro_check faild!" >> $Log
	cp $LogHome/$2 $LogRestore
}

function python_engine () {
	cd $FunctionHome
	python $1 1>$LogRestore/$2 2>>$Log || echo "REPORT-SYSTEM-UPDATE ERROR: Run $1 faild!" >> $Log
}

function sendreportmail_upgrade () {
	cd $LogRestore
	echo 'Any problem, please contact Mei Lei <lei.mei@intel.com> ' | mutt -i $1 -s "[Package Report System]Upgrade recipes name list"  -- $2
}

function sendreportmail_manualcheck() {
	cd $LogRestore
	echo 'Any problem, please contact Mei Lei <lei.mei@intel.com> ' | mutt -i $1 -s "[Package Report System]Manual check recipes name list"  -- $2
}

function sendlogmail () {
	cd $LogRestore
	echo 'Any problem, please contact Mei Lei <lei.mei@intel.com> ' | mutt -i $1 -s "Warning! Some failures happened on pkg-report system!"  -- $2

}


#
#you can set your own environment variable
#
#export http_proxy="http://proxy01.pd.intel.com:911"
#export https_proxy="https://proxy01.pd.intel.com:911"
#export ftp_proxy="http://proxy01.pd.intel.com:911"
export WebHome=$(cd `dirname $0` && pwd)
export PokyHome="$WebHome/poky/"
export LogHome="$PokyHome/build/tmp/log/"
export ConfigFile="$WebHome/pokyconfig/"
export LogRestore="$WebHome/log/"
export FunctionHome="$WebHome/python-function/"
export Log="$LogRestore/run_getpkginfoall.log.`date +%Y%m%d`"

#
#generate log file
#
if [ -e $LogRestore/run_getpkginfoall.log ]; then
	rm -f $LogRestore/run_getpkginfoall.log
fi
if [ -e $Log ]; then
	rm -f $Log
fi
touch $LogRestore/run_getpkginfoall.log.`date +%Y%m%d`
ln -sf $Log $LogRestore/run_getpkginfoall.log

#
#Get poky tree
#
cd $WebHome
if [ ! -d poky ]; then
	git clone git://git.pokylinux.org/poky.git >> $Log
	if [ $? -eq 1 ]; then
		echo "REPORT-SYSTEM-UPDATE ERROR: Get a new poky tree failed!" >> $Log
	fi
	cd $PokyHome
        if [ ! -z $USE_MASTER ]; then
                git checkout master
                git reset --hard origin
                git pull
                if [ $? -eq 1 ]; then
                        echo "REPORT-SYSTEM-UPDATE ERROR: Get the latest poky tree failed" >> $Log
                fi
        else
                git fetch git://git.pokylinux.org/poky-contrib.git stage/master_under_test:stage
                git checkout stage
                git pull -f git://git.pokylinux.org/poky-contrib.git stage/master_under_test:stage
                if [ $? -eq 1 ]; then
                        echo "REPORT-SYSTEM-UPDATE ERROR: Get the latest poky tree failed" >> $Log
                fi
        fi
fi

cd $PokyHome
rm -rf build/
. ./oe-init-build-env build
cp  $ConfigFile/auto.conf ./conf/

#
#get original data from poky tasks
#
bitbake_engine "distro_check" "distrocheck.csv"
bitbake_engine "checkpkg" "checkpkg.csv"
bitbake_engine "checklicense" "missinglicense.csv"

#
#handle data so that system can use them smoothly
#
python_engine "upgrade_to_log.py" "upgradeinfo.log"
python_engine "lastchktime_to_log.py" "lastchktimeinfo.log"
python_engine "noupgreason.py" "noupgreasoninfo.log"
python_engine "checkdistro.py" "distroexist.log"
python_engine "checklicense.py" "licensecheck.log"


#
#run recipe_repo.py to get recipe repo address
#
cd $PokyHome
find meta* -iname *.bb>$LogRestore/recipelist.log  
find meta* -iname *.bb | awk -F/ '{print $NF}'| awk -F ".bb" '{print $1}'>$LogRestore/recipename.log
find meta* -iname *.bb | awk -F/ '{print $NF}'| awk -F ".bb" '{print $1}' | awk -F_ '{print $1}'>$LogRestore/pkgPureName.log
cd $FunctionHome
python recipe_repo.py >> $Log 2>&1 || echo "REPORT-SYSTEM-UPDATE ERROR: Run recipe_repo.py faild!" >> $Log

#
#run info_to_db.py to update the database
#
cd $WebHome/newserver/webserver
if [ -e pkginfo.sqlite ]; then
	rm -f pkginfo.sqlite
fi
if [ -e $LogRestore/pkginfo.sqlite.`date +%Y%m%d` ]; then
	rm -f $LogRestore/pkginfo.sqlite.`date +%Y%m%d`
fi
touch $LogRestore/pkginfo.sqlite.`date +%Y%m%d`
ln -sf $LogRestore/pkginfo.sqlite.`date +%Y%m%d` $WebHome/newserver/webserver/pkginfo.sqlite
cd $WebHome/newserver 
python info_to_db.py >> $Log 2>&1 || echo "REPORT-SYSTEM-UPDATE ERROR: Update database faild!" >> $Log

#
#put the sqlite data to a csv spreadsheet
#
cd $WebHome/newserver/webserver
if [ -e report.csv ]; then
	rm -f report.csv
fi
if [ -e report.csv.`date +%Y%m%d` ]; then
	rm -f report.csv.`date +%Y%m%d`
fi
touch $LogRestore/report.csv.`date +%Y%m%d`
ln -sf $LogRestore/report.csv.`date +%Y%m%d` report.csv
cd $FunctionHome
python pkginfo_to_csv.py >> $Log 2>&1 || echo "REPORT-SYSTEM-UPDATE ERROR: Run pkginfo_to_csv.py faild!" >> $Log

#
#check recipes version and give out the list mail which need to be updated
#
cd $FunctionHome
rm $LogRestore/upgradecontent.log $LogRestore/lastchktime.log
python mailaboutupgrade.py >> $Log 2>&1 || echo "REPORT-SYSTEM-UPDATE ERROR: Mail content of upgrade info failed!" >> $Log
python mailaboutchktime.py >> $Log 2>&1 || echo "REPORT-SYSTEM-UPDATE ERROR: Mail content of check time failed!" >> $Log

#
#get based commit info
#
cd $PokyHome
echo "The based commit merge time is:" >> $LogRestore/upgradecontent.log
git log --format=%cd -1 >> $LogRestore/upgradecontent.log
echo "The based commit is:" >> $LogRestore/upgradecontent.log
git log -1 | head -n 3 >> $LogRestore/upgradecontent.log

#
#Collect history date data for select date in history page 
#
cd $LogRestore/
ls pkginfo.sqlite.* | awk -F . '{print $(NF)}' > databaseHistoryDate.log || echo "REPORT-SYSTEM-UPDATE ERROR: Collect history date faild!" >> $Log

#
#use mutt to send list of recipes which need to be updated 
#
cd $FunctionHome
#This checklog.py is very important to decide we will send a report mail or warning mail
python checklog.py
if [ $? -eq 0 ]; then
	#
	#Collect data for bar chart then draw bar chart
	#
	cd $LogRestore/
	date +%Y%m%d >> HistoryDataPre.log
	sed -n '/^PackageName/,/^The based commit merge time is:$/p' upgradecontent.log|grep -v 'The based commit merge time is:'|grep -v '^PackageName'|wc -l >> HistoryDataPre.log
	sed '1,6d' lastchktime.log | wc -l >> HistoryDataPre.log
	tail -18 HistoryDataPre.log > HistoryData.log
	if [ $drawchart = "drawchart" ]; then
		drawchart
	fi
	
	#Replace the old database with latest one
	cd $WebHome/newserver/webserver
	cp pkginfo.sqlite pkginfobackup.sqlite 
	cp report.csv $WebHome
	#Send report mail
	if [ -n "$sendemailto" ]; then
		sendreportmail_upgrade "upgradecontent.log" "$sendemailto"
		sendreportmail_manualcheck "lastchktime.log" "$sendemailto"
	else
		sendreportmail_upgrade "upgradecontent.log" "yocto@linux.intel.com"
		sendreportmail_manualcheck "lastchktime.log" "yocto@linux.intel.com"
		if [ $? -eq 1 ]; then
			echo "REPORT-SYSTEM-UPDATE ERROR: Send mail faild!" >> $Log
		fi
	fi
else
	if [ -n "$sendemailto" ]; then
		sendlogmail "$Log" "$sendemailto"
	else
		sendlogmail "$Log" "lei.mei@intel.com"
		sendlogmail "$Log" "saul.wold@intel.com"
	fi
fi
echo "All tasks finished! You can check the log file $Log" >> $Log