-
Notifications
You must be signed in to change notification settings - Fork 2
/
yumlog2gource.sh
executable file
·908 lines (783 loc) · 24.8 KB
/
yumlog2gource.sh
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
#!/bin/bash
# pacmanlog2gource - converts a copy of /var/log/pacman.log into a format readable by gource
# Copyright (C) 2011-2012 Matthias Krüger
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 1, or (at your option)
# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA
# Regarding usage of the arch logo, I asked in #archlinux on irc.freeode.net on
# Friday, May 25th 2012 , around 12:00 CEST
#11:59 < matthiaskrgr> I made a script which visualizes the pacman logfile (package updates removals etc)
#12:00 < matthiaskrgr> looks like this http://www.youtube.com/watch?v=lCBjzC78t4o
#[...]
#12:00 < matthiaskrgr> and I wondered if I was allowed to display a little arch linux icon at the lower right corner
#12:00 < allanbrokeit> I had seen that on the forums
#[...]
#12:00 < matthiaskrgr> or if there were any problems with it
#12:00 < allanbrokeit> matthiaskrgr: I'd say that is fine
#12:00 < matthiaskrgr> ok thanks :)
#12:01 < matthiaskrgr> I'll quote you in some code comment, just in case... ;)
#12:01 < allanbrokeit> matthiaskrgr: https://wiki.archlinux.org/index.php/DeveloperWiki:TrademarkPolicy
#[...]
#12:02 < allanbrokeit> I'd say this falls in the advocacy section
# set -x
# variables
DATADIR=~/.pacmanlog2gource
exit_() {
if [ ! `echo "$*" | grep -o "^-.[^\ ]*n\|\-n"` ] ; then
if [ -f ${DATADIR}/lock ] ; then
rm ${DATADIR}/lock
fi
exit $*
fi
}
sizecalc() {
outputunit=b
input=$1
if [ ${input} == 0 ] ; then
echo -n "0 b"
else
outputval=${input}
((outputkilo=${outputval}/1024))
if [ ! "${outputkilo}" == 0 ] ; then
outputunit=kb
outputval=${outputkilo}
((outputmega=${outputkilo}/1024))
if [ ! "${outputmega}" == 0 ] ; then
outputunit=Mb
outputval=${outputmega}
((outputgiga=${outputmega}/1024))
if [ ! "${outputgiga}" == 0 ] ; then
outputunit=Gb
outputval=${outputgiga}
fi
fi
fi
echo "${outputval} ${outputunit}"
fi
}
YUMLOG=/var/log/yum.log
LOGTOBEPROCESSED=${DATADIR}/yum_purged.log
LOGNOW=${DATADIR}/yum_now.log
LOG=${DATADIR}/yum_gource_tree.log
UPDATE="true"
COLOR="true"
FFMPEGPOST="false"
GOURCEPOST="false"
INFORMATION="false"
LOGO="false"
QUIET="false"
RED='\e[1;31m'
GREEN='\e[3;32m'
GREENUL='\e[4;32m'
WHITEUL='\e[4;02m'
NC='\e[0m'
TIMECOUNTCOOKIE=0
VERSION="2.0.0"
FILENAMES=' '
if [ `echo "$*" | grep -o "^-.[^\ ]*d\|\-d"` ] ; then
echo "Debug mode..."
set -x
fi
# check if we already have the datadir, if we don't have it, create it
if [ ! -d "${DATADIR}" ] ; then
# workaround to not have colors displayed if we use -c option
if [[ `echo "$*" | grep -o "^-.[^\ ]*c\|\-c"` ]] ; then
echo -e "No directory ${DATADIR} found, creating one."
else
echo -e "No directory ${WHITEUL}${DATADIR}${NC} found, creating one."
fi
# if we cannot create the datadir (wtf!?), complain
if mkdir "${DATADIR}" ; then
:
else
echo -e "ERROR: Unable to create ${DATADIR}" >&2
exit_ 1
fi
fi
if [ -f ${DATADIR}/lock ] ; then
echo "FATAL: lockfile exists."
echo "Please wait until current instance of pacmanlog2gource is done and re-run or"
echo "remove ${DATADIR}/lock manually and re-run."
exit 4
fi
if [ ! `echo "$*" | grep -o "^-.[^\ ]*n\|\-n"` ] ; then
touch ${DATADIR}/lock
fi
# create a checksum of the log-generating part of the script
PATHTOSCRIPT=$0
COMPATIBILITY_CHECKSUM=`cat ${PATHTOSCRIPT} | sed -e '/COMPATIBILITY_CHECKSUM/d' | awk '/#checksumstart/,/#checksumstop/' | md5sum | cut -d' ' -f1`
OLD_CHECKSUM_FILE=${DATADIR}/checksum
OLD_CHECKSUM=`touch ${OLD_CHECKSUM_FILE} ; cat ${OLD_CHECKSUM_FILE}`
if [ -f ${DATADIR}/version ] ; then
rm ${DATADIR}/version
OLD_CHECKSUM="icanhazregenerationplz"
fi
if [[ ! `echo - "$*" | grep -o "^-.[^\ ]*n\|\-n\|^-.[^\ ]*h\|\-h\|^-.[^\ ]*i\|-i"` ]] ; then
if [ ! -z ${OLD_CHECKSUM} ] ; then
if [[ ${OLD_CHECKSUM} == ${COMPATIBILITY_CHECKSUM} ]] ; then
:
else
if [[ `echo "$*" | grep -o "^-.[^\ ]*c\|\-c"` ]] ; then
echo "Logfile generation has changed!"
echo "To avoid incompatibility, the log is now regenerated!"
else
echo -e "${RED}Logfile generation has changed!${NC}"
echo -e "${RED}To avoid incompatibility, the log is now regenerated!${NC}"
fi
rm ${LOGNOW} ${LOG}
echo "${COMPATIBILITY_CHECKSUM}" > ${OLD_CHECKSUM_FILE}
fi
else
echo "${COMPATIBILITY_CHECKSUM}" > ${OLD_CHECKSUM_FILE}
fi
fi
# create empty logfile if non exists
if [ ! -f ${LOGNOW} ] ; then
touch ${LOGNOW}
fi
# timer functions
timestart()
{
TSG=`date +%s.%N`
}
timeend()
{
TEG=`date +%s.%N`
TDG=`calc -p $TEG - $TSG`
}
makelog_pre() {
# check if yum is currently in use
if [ -f "/var/run/yum.pid" ] ; then
echo "ERROR, yum is currently in use, please wait and re-run when yum is done." >&2
exit_ 3
fi
# check if we have a yum logfile
if [ ! -f "${YUMLOG}" ] ; then
echo "ERROR, could not find ${YUMLOG}, exiting..."
exit_ 4
fi
# start the timer
timestart
# copy the yum log as yum_tmp.log to our datadir
cp ${YUMLOG} ${DATADIR}/yum_tmp.log
echo -e "Getting diff between ${WHITEUL}${YUMLOG}${NC} and an older local copy."
# we only want to proceed new entries, old ones are already included in the log
diff -u ${LOGNOW} ${YUMLOG} | awk /'^+'/ | sed -e 's/^+//' > ${DATADIR}/process.log
######################
# core of the script #
######################
# get lines and size of the pacman log
ORIGSIZE=`du -b ${DATADIR}/process.log | cut -f1`
ORIGLINES=`wc ${DATADIR}/process.log -l | cut -d' ' -f1`
ORIGSIZE_OUT=`sizecalc ${ORIGSIZE}`
echo -e "Purging the diff (${ORIGLINES} lines, ${ORIGSIZE_OUT}) and saving the result to ${WHITEUL}${DATADIR}${NC}."
sed -e 's/\[/\n[/g' -e '/^$/d' ${DATADIR}/process.log | awk '/ Installed| Updated| Erased/' > ${LOGTOBEPROCESSED}
PURGEDONESIZE=`du -b ${LOGTOBEPROCESSED} | cut -f1`
PURGEDONESIZE_OUT=`sizecalc ${PURGEDONESIZE}`
CURLINE=1
LINEPRCOUT=1
MAXLINES=`wc -l ${LOGTOBEPROCESSED} | cut -d' ' -f1`
PURGELINEPERC=`calc -p "${MAXLINES}/${ORIGLINES}*100-100"`
echo -e "Processing ${MAXLINES} lines of purged log (${PURGEDONESIZE_OUT})..."
if [ ! ${MAXLINES} == "0" ] ; then
echo -e "Purging efficiency: ${PURGELINEPERC:1:5}% \n" | sed s/\ -/\ /
else
echo ""
fi
cp ${LOGTOBEPROCESSED} ${DATADIR}/tmp
} # makelog_pre
makelog_quiet() {
########################
## processing the log ##
########################
while read line ; do
#checksumstart
# the unix time string
linearray=(${line})
#UNIXDATE="${line2[1]:1:16}"
UNIXDATE=`date +"%s" -d "${line:0:15}"`
# put installed/removed/upgraded information in there again, we translated these later with sed in one rush
STATE="${linearray[3]}"
# package name
PKG="${linearray[4]}"
PKG=`echo ${PKG} | grep -o "^[a-Z,0-9,-,\.]*"`
case ${PKG} in
lib*)
case ${PKG} in
libreoffice*)
case ${PKG} in
*extension*)
PKG="libreoffice/extension/${PKG}.libreoffice|18A303"
;;
*)
PKG="libreoffice/${PKG}.libreoffice|18A303"
;;
esac
;;
*32*)
PKG="lib/32/${PKG}.lib|585858"
;;
*)
PKG="lib/${PKG}.lib|585858"
;;
esac
;;
*xorg*)
PKG="xorg/${PKG}.xorg|ED541C"
;;
*ttf*)
PKG="ttf/${PKG}.ttf|000000"
;;
*xfce*)
case ${PKG} in
*plugin*)
PKG="xfce/plugins/${PKG}.xfce|00CED1"
;;
*)
PKG="xfce/${PKG}.xfce|00CED1"
;;
esac
;;
*sdl*)
PKG="sdl/${PKG}.sdl|E0FFFF"
;;
*xf86*)
PKG="xorg/xf86/${PKG}.xorg|ED541C"
;;
*perl*)
PKG="perl/${PKG}.perl|FF0000"
;;
*gnome*)
PKG="gnome/${PKG}.gnome|5C3317"
;;
*gtk*)
PKG="gtk/${PKG}.gtk|FFFF00"
;;
*gstreamer*)
PKG="gstreamer/${PKG}.gstreamer|FFFF66"
;;
*kde*)
case ${PKG} in
*kdegames*)
PKG="kde/games/${PKG}.kde|0000CC"
;;
*kdeaccessibility*)
PKG="kde/accessebility/${PKG}.kde|0000CC"
;;
*kdeadmin*)
PKG="kde/admin/${PKG}.kde|0000CC"
;;
*kdeartwork*)
PKG="kde/artwork/${PKG}.kde|0000CC"
;;
*kdebase*)
PKG="kde/base/${PKG}.kde|0000CC"
;;
*kdeedu*)
PKG="kde/edu/${PKG}.kde|0000CC"
;;
*kdegames*)
PKG="kde/games/${PKG}.kde|0000CC"
;;
*kdegraphics*)
PKG="kde/graphics/${PKG}.kde|0000CC"
;;
*kdemultimedia*)
PKG="kde/multimedia/${PKG}.kde|0000CC"
;;
*kdenetwork*)
PKG="kde/network/${PKG}.kde|0000CC"
;;
*kdepim*)
PKG="kde/pim/${PKG}.kde|0000CC"
;;
*kdeplasma*)
PKG="kde/plasma/${PKG}.kde|0000CC"
;;
*kdesdk*)
PKG="kde/sdk/${PKG}.kde|0000CC"
;;
*kdetoys*)
PKG="kde/toys/${PKG}.kde|0000CC"
;;
*kdeutils*)
PKG="kde/utils/${PKG}.kde|0000CC"
;;
*kdewebdev*)
PKG="kde/webdev/${PKG}.kde|0000CC"
;;
*)
PKG="kde/${PKG}.kde|0000CC"
;;
esac
;;
*python*|py*)
PKG="python/${PKG}.python|2F4F4F"
;;
*lxde*|lx*)
PKG="lxde/${PKG}.lxde|8C8C8C"
;;
*php*)
PKG="php/${PKG}.php|6C7EB7"
;;
vim*)
PKG="vim/${PKG}.vim|00FF66"
;;
*texlive*)
PKG="texlive/${PKG}.texlive|660066"
;;
*alsa*)
PKG="alsa/${PKG}.alsa|C8DEC9"
;;
*compiz*)
PKG="compiz/${PKG}.compiz|FF0066"
;;
*dbus*)
PKG="dbus/${PKG}.dbus|99FFFF"
;;
gambas*)
case ${PKG} in
gambas2*)
PKG="gambas/2/${PKG}.gambas|996633"
;;
gambas3*)
PKG="gambas/3/{PKG}.gambas|996633"
;;
*)
PKG="gambas/${PKG}.gambas|996633"
;;
esac
;;
*qt*)
PKG="qt/${PKG}.qt|91219E"
;;
*firefox*|*thunderbird*|*seamonky*)
PKG="mozilla/${PKG}.mozilla|996633"
;;
*)
esac
# this is an awful hack to get the vars via multitasking, but it works :)
echo "$UNIXDATE" > /dev/null &
echo "$STATE" > /dev/null &
echo "$PKG" > /dev/null &
wait
# write the important stuff into our logfile
echo "${UNIXDATE}|root|${STATE}|${PKG}" >> ${LOG}
done < ${DATADIR}/tmp
} # makelog_quiet
makelog() {
while [ "$CURLINE" -le "$MAXLINES" ]; do
########################
## processing the log ##
########################
# to read the file via loop
IFS=$'\n'
set -f
for i in $(<${DATADIR}/tmp); do
# the unix time string
UNIXDATE=`date +"%s" -d "${i:0:16}"`
# put installed/removed/upgraded information in there again, we translated these later with sed in one rush
STATE=`echo $i |cut -d' ' -f4`
# package name
PKG=`echo ${i} | cut -d' ' -f5`
PKG=`echo ${PKG} | grep -o "^[a-Z,0-9,-,\.]*"`
case ${PKG} in
lib*)
case ${PKG} in
libreoffice*)
case ${PKG} in
*extension*)
PKG="libreoffice/extension/${PKG}.libreoffice|18A303"
;;
*)
PKG="libreoffice/${PKG}.libreoffice|18A303"
;;
esac
;;
*32*)
PKG="lib/32/${PKG}.lib|585858"
;;
*)
PKG="lib/${PKG}.lib|585858"
;;
esac
;;
*xorg*)
PKG="xorg/${PKG}.xorg|ED541C"
;;
*ttf*)
PKG="ttf/${PKG}.ttf|000000"
;;
*xfce*)
case ${PKG} in
*plugin*)
PKG="xfce/plugins/${PKG}.xfce|00CED1"
;;
*)
PKG="xfce/${PKG}.xfce|00CED1"
;;
esac
;;
*sdl*)
PKG="sdl/${PKG}.sdl|E0FFFF"
;;
*xf86*)
PKG="xorg/xf86/${PKG}.xorg|ED541C"
;;
*perl*)
PKG="perl/${PKG}.perl|FF0000"
;;
*gnome*)
PKG="gnome/${PKG}.gnome|5C3317"
;;
*gtk*)
PKG="gtk/${PKG}.gtk|FFFF00"
;;
*gstreamer*)
PKG="gstreamer/${PKG}.gstreamer|FFFF66"
;;
*kde*)
case ${PKG} in
*kdegames*)
PKG="kde/games/${PKG}.kde|0000CC"
;;
*kdeaccessibility*)
PKG="kde/accessebility/${PKG}.kde|0000CC"
;;
*kdeadmin*)
PKG="kde/admin/${PKG}.kde|0000CC"
;;
*kdeartwork*)
PKG="kde/artwork/${PKG}.kde|0000CC"
;;
*kdebase*)
PKG="kde/base/${PKG}.kde|0000CC"
;;
*kdeedu*)
PKG="kde/edu/${PKG}.kde|0000CC"
;;
*kdegames*)
PKG="kde/games/${PKG}.kde|0000CC"
;;
*kdegraphics*)
PKG="kde/graphics/${PKG}.kde|0000CC"
;;
*kdemultimedia*)
PKG="kde/multimedia/${PKG}.kde|0000CC"
;;
*kdenetwork*)
PKG="kde/network/${PKG}.kde|0000CC"
;;
*kdepim*)
PKG="kde/pim/${PKG}.kde|0000CC"
;;
*kdeplasma*)
PKG="kde/plasma/${PKG}.kde|0000CC"
;;
*kdesdk*)
PKG="kde/sdk/${PKG}.kde|0000CC"
;;
*kdetoys*)
PKG="kde/toys/${PKG}.kde|0000CC"
;;
*kdeutils*)
PKG="kde/utils/${PKG}.kde|0000CC"
;;
*kdewebdev*)
PKG="kde/webdev/${PKG}.kde|0000CC"
;;
*)
PKG="kde/${PKG}.kde|0000CC"
;;
esac
;;
*python*|py*)
PKG="python/${PKG}.python|2F4F4F"
;;
*lxde*|lx*)
PKG="lxde/${PKG}.lxde|8C8C8C"
;;
*php*)
PKG="php/${PKG}.php|6C7EB7"
;;
vim*)
PKG="vim/${PKG}.vim|00FF66"
;;
*texlive*)
PKG="texlive/${PKG}.texlive|660066"
;;
*alsa*)
PKG="alsa/${PKG}.alsa|C8DEC9"
;;
*compiz*)
PKG="compiz/${PKG}.compiz|FF0066"
;;
*dbus*)
PKG="dbus/${PKG}.dbus|99FFFF"
;;
gambas*)
case ${PKG} in
gambas2*)
PKG="gambas/2/${PKG}.gambas|996633"
;;
gambas3*)
PKG="gambas/3/{PKG}.gambas|996633"
;;
*)
PKG="gambas/${PKG}.gambas|996633"
;;
esac
;;
*qt*)
PKG="qt/${PKG}.qt|91219E"
;;
*firefox*|*thunderbird*|*seamonky*)
PKG="mozilla/${PKG}.mozilla|996633"
;;
*)
esac
# this is an awful hack to get the vars via multitasking, but it works :)
echo "$UNIXDATE" > /dev/null &
echo "$STATE" > /dev/null &
echo "$PKG" > /dev/null &
wait
# write the important stuff into our logfile
echo "${UNIXDATE}|root|${STATE}|${PKG}" >> ${DATADIR}/yum_gource_tree.log
# here we print how log the script already took to run and try to estimate how log it will run until everything is done
# but we only update this every 1000 lines to avoid unnecessary stdout spamming
# this will mostly be printed when initially obtaining the log
if [ "${LINEPERCOUT}" == "1000" ] ; then
LINECOUNTCOOKIE=1
# can we use expr here, or something more simple?
LINEPERC=`calc -p "${CURLINE} / ${MAXLINES} *100" | sed -e 's/\~//'`
timeend
# same as echo ${TDG} | grep -o "[0-9]*\.\?[0-9]\?[0-9]" # | head -n1
TGDOUT=`echo ${TDG} | awk 'match($0,/[0-9]*.?[0-9]?[0-9]/) {print substr($0,RSTART,RLENGTH)}'`
TIMEDONEONE=`calc -p "100 / ${LINEPERC:0:4} *${TDG}" | sed 's/\~//'`
TIMEDONEFINAL=`calc -p "${TIMEDONEONE} - ${TDG}" | sed 's/\~//' | awk 'match($0,/[0-9]*.?[0-9]?[0-9]/) {print substr($0,RSTART,RLENGTH)}'`
echo "Already ${LINEPERC:0:4}% done after ${TGDOUT}s."
echo -e "Done in approximately ${TIMEDONEFINAL}s.\n"
LINEPERCOUT=0
fi
# switch to next line and re-start the loop
let CURLINE=${CURLINE}+1
let LINEPERCOUT=${LINEPERCOUT}+1
done
# file loop stuff..
set +f
unset IFS
done
} # makelog
makelog_post() {
# was the package installed/removed/upgraded? here we actually translate this important information
sed -e 's/|Installed:|/|A|/' -e 's/|Updated:|/|M|/' -e 's/|Erased:|/|D|/' ${LOG} > ${DATADIR}/tmp2.log
mv ${DATADIR}/tmp2.log ${DATADIR}/yum_gource_tree.log &
mv ${DATADIR}/yum_tmp.log ${LOGNOW} &
rm ${DATADIR}/yum_purged.log ${DATADIR}/process.log ${DATADIR}/tmp &
wait
# take the existing log and remove the paths so we have our pie-like log again which I had at the beginning of the developmen process of this script :)
# yes, this may look stupid, first writing a package category and then removing it afterwards, but I think its faster to edit the entire file in one rush
# instead of writing every single line into a file
sed -e 's/D|.*\//D\|/' -e 's/M|.*\//M\|/' -e 's/A|.*\//A\|/' ${DATADIR}/yum_gource_tree.log > ${DATADIR}/yum_gource_pie.log
# how log did the script take to run?
timeend
if [[ ${LINECOUNTCOOKIE} == "1" ]] ; then
TIMEFINAL=`echo "${TDG}" | awk 'match($0,/[0-9]*\.?[0-9]?[0-9]/) {print substr($0,RSTART,RLENGTH)}'`
else
TIMEFINAL=`echo "${TDG}" | awk 'match($0,/[0-9]*.[0-9]{5}/) {print substr($0,RSTART,RLENGTH)}'`
fi
if [[ ${MAXLINES} == "0" ]] ; then
LINESPERSEC="0"
else
LINESPERSEC=`calc -p "${MAXLINES}/${TIMEFINAL}"`
fi
echo -e "100 % done after ${RED}${TIMEFINAL}${NC}s."
echo -e "${RED}${LINESPERSEC:0:6}${NC} lines per second.\n"
rm ${DATADIR}/lock # remove lockfile
} # makelog_post
#checksumstop
help() {
echo -e "-n do${WHITEUL}N${NC}'t update the log"
echo -e "-c don't use ${WHITEUL}C${NC}olors for shell output"
echo -e "-g start ${WHITEUL}G${NC}ource afterwards"
echo -e "-f capture the video using ${WHITEUL}F${NC}fmpeg"
echo -e "-p makes use of -g and uses ${WHITEUL}P${NC}ie log"
echo -e "-a skip ${WHITEUL}A${NC}rchitecture in title"
echo -e "-o skip h${WHITEUL}O${NC}stname in title"
echo -e "-t skip ${WHITEUL}T${NC}imestaps in title"
echo -e "-i show some ${WHITEUL}I${NC}nformation regarding pacmanlog2gource"
echo -e "-m skip package na${WHITEUL}M${NC}es"
echo -e "-l show ${WHITEUL}icon${NC} in lower right corner"
echo -e "-L show ${WHITEUL}logo${NC} in lower right corner"
echo -e "-q don't estimate when log conversion is finished, and be faster"
echo -e "-d show ${WHITEUL}D${NC}ebug information (set -x)"
echo -e "-h show this ${WHITEUL}H${NC}elp"
}
logbeginningdate=`head -n1 ${LOGNOW} | sed -e '/^$/d' | cut -d' ' -f1,2,3 | sed -e 's/\[//'`
logbeginning=`date +"%d %b %Y" -d "${logbeginningdate}"`
logenddate=`sed -e '/^$/d' ${LOGNOW} | tail -n1 | cut -d' ' -f1,2,3 | sed -e 's/\[//'`
logend=`date +"%d %b %Y" -d "${logenddate}"`
cpucores=`getconf _NPROCESSORS_ONLN`
gourcebinarypath=`whereis gource | cut -d' ' -f2`
# gourcename_version=`pacman -Qo ${gourcebinarypath} | cut -d' ' -f"5 6"`
LOGTIMES=", ${logbeginning} - ${logend}"
HOSTNAME=", hostname: `hostname`"
ARCH=", `uname -m`"
while getopts "nchgfpaotimdlLq" opt; do
case "$opt" in
"n")
echo "Log not updated." >&2
UPDATE="false"
;;
"c")
RED=''
GREEN=''
GREENUL=''
WHITEUL=''
NC=''
echo "Skipping colors in output."
echo "NOTE: this won't affect stdout of gource or ffmpeg."
;;
"h")
UPDATE="false"
help
exit_ 0
;;
"g")
GOURCEPOST="true"
;;
"f")
FFMPEGPOST="true"
GOURCEPOST="true"
;;
"p")
LOG=${DATADIR}/pacman_gource_pie.log
GOURCEPOST="true"
;;
"a")
ARCH=''
;;
"o")
HOSTNAME=''
;;
"t")
LOGTIMES=''
;;
"i")
echo "ERROR: gource version output not supported yet"
UPDATE="false"
INFORMATION="true"
;;
"m")
FILENAMES=",filenames"
GOURCEPOST="true"
echo "Filenames will be skipped in the video." >&2
;;
"l")
GOURCEPOST=true
LOGOIMAGE="--logo ${DATADIR}/archlinux-icon-crystal-64.png"
if [ ! -f ${DATADIR}/archlinux-icon-crystal-64.png ] ; then
if [ -f /usr/share/archlinux/icons/archlinux-icon-crystal-64.svg ] ; then # if we don't have the icon locally...
echo -e "${RED}Icon found locally, converting...${NC}"
convert -background none /usr/share/archlinux/icons/archlinux-icon-crystal-64.svg ${DATADIR}/archlinux-icon-crystal-64.png
else # ....download it
echo -e "${RED}Icon not found locally, downloading icons...${NC}"
mkdir ${DATADIR}/tmp
cd ${DATADIR}/tmp
wget --continue "ftp://ftp.archlinux.org/other/artwork/archlinux-artwork-1.6.tar.gz" ./archlinux-artwork-1.6.tar.gz || echo -e "${RED}Could not download file, no image will be displayed.${NC}" ; LOGOIMAGE=" "
echo -e "${RED}Extracting archive....${NC}"
tar -zxvf archlinux-artwork-1.6.tar.gz
echo -e "${RED}Converting icon...${NC}"
convert -background none ./archlinux-artwork-1.6/icons/archlinux-icon-crystal-64.svg ../archlinux-icon-crystal-64.png
cd ../
echo -e "${RED}Removing unwanted files...${NC}"
rm -rf ./tmp
fi
echo -e "${RED}Done${NC}"
fi
;;
"L")
GOURCEPOST=true
LOGOIMAGE="--logo ${DATADIR}/archlogo.png"
if [ ! -f ${DATADIR}/archlogo.png ] ; then
echo -e "${RED}Logo not found locally, downloading...${NC}"
cd ${DATADIR}
wget --continue "http://www.archlinux.org/static/archnavbar/archlogo.png" || echo -e "${RED}Could not download file, no image will be displayed.${NC}" ; LOGOIMAGE=" "
echo -e "${RED}Done${NC}"
fi
;;
"d")
# DEBUG="true"
# echo "Entering debug mode..." >&2
;;
"q")
QUIET="true"
echo "Entering quiet mode, this should be faster than default mode"
echo "but doesn't estimate when log genration will be finished."
;;
"?")
UPDATE="false"
echo "Pacmanlog2gource: invalid option!" >&2
echo "Please try pacmanlog2gource -h for possible options." >&2
exit_ 1
;;
*)
echo "Pacmanlog2gource: unknown error while processing options." >&2
exit_ 1
;;
esac
done
TITLE="Pacmanlog2gource${LOGTIMES}${HOSTNAME}${ARCH}"
if [ ${INFORMATION} == "true" ] ; then
if [ "$*" == "-i" ] ; then
ARGS=""
else
ARGS="`echo "${*}" | sed -e 's/i//'`"
fi
echo -e "The command which will be run using ${GREEN}pacmanlog2gource ${ARGS}${NC}is"
if [ ${FFMPEGPOST} != "true" ] ; then
echo -e "${GREEN}gource ${GREENUL}${DATADIR}/pacman_gource_tree.log${NC}${GREEN} -1200x720 -c 1.1 --title \"${TITLE}\" --key --camera-mode overview --highlight-all-users --file-idle-time 0 -auto-skip-seconds 0.001 --seconds-per-day 0.3 --hide progress,mouse${FILENAMES} --stop-at-end --max-files 99999999999 --max-file-lag 0.00001 --max-user-speed 300 --user-friction 2 ${LOGOIMAGE} --bloom-multiplier 1.3 ${NC}"
else
echo -e "${GREEN}gource ${GREENUL}${DATADIR}/pacman_gource_tree.log${NC}${GREEN} -1200x720 -c 1.1 --title \"${TITLE}\" --key --camera-mode overview --highlight-all-users --file-idle-time 0 -auto-skip-seconds 0.001 --seconds-per-day 0.3 --hide progress,mouse${FILENAMES} --stop-at-end --max-files 99999999999 --max-file-lag 0.00001 --max-user-speed 300 --user-friction 2 ${LOGOIMAGE} --bloom-multiplier 1.3 --output-ppm-stream - | ffmpeg -f image2pipe -vcodec ppm -i - -y -vcodec libx264 -preset medium -crf 22 -pix_fmt yuv420p -threads ${cpucores} -b:v 3000k -maxrate 8000k -bufsize 10000k ${GREENUL}pacmanlog2gource_`date +%b\_%d\_%Y`.mp4${NC}"
fi
echo -e "Logfiles are stored in ${WHITEUL}${DATADIR}/pacman_gource_tree.log${NC} and ${WHITEUL}${DATADIR}/pacman_gource_pie.log${NC}."
echo -e "Pacmanlog2gource version: ${VERSION}"
echo -e "Gource version: ${gourcename_version}"
echo "Feel free to comment https://bbs.archlinux.org/viewtopic.php?pid=1105145"
echo "or fork https://github.com/matthiaskrgr/pacmanlog2gource"
exit_ 0
fi
if [ ${UPDATE} == "true" ] ; then
makelog_pre
if [ ${QUIET} == "true" ] ; then
makelog_quiet
else
makelog
fi
makelog_post
echo -e "Output files are ${WHITEUL}${DATADIR}/yum_gource_tree.log${NC}"
echo -e "\t and ${WHITEUL}${DATADIR}/yum_gource_pie.log${NC}.\n\n"
fi
if [ ${GOURCEPOST} == "true" ] ; then
if [ ${FFMPEGPOST} == "true" ] ; then
echo -e "<output of ${GREEN}ffmpeg${NC}>"
gource ${LOG} -1200x720 -c 1.1 --title "${TITLE}" --key --camera-mode overview --highlight-all-users --file-idle-time 0 -auto-skip-seconds 0.001 --seconds-per-day 0.3 --hide progress,mouse${FILENAMES} --stop-at-end --max-files 99999999999 --max-file-lag 0.00001 --max-user-speed 300 --user-friction 2 ${LOGOIMAGE} --bloom-multiplier 1.3 --output-ppm-stream - | ffmpeg -f image2pipe -vcodec ppm -i - -y -vcodec libx264 -preset medium -crf 22 -pix_fmt yuv420p -threads ${cpucores} -b:v 3000k -maxrate 8000k -bufsize 10000k pacmanlog2gource_`date +%b\_%d\_%Y`.mp4
echo -e "</output of ${GREEN}ffmpeg${NC}>"
else
echo -e "To record the video to a mp4 file using ffmpeg, run ${GREEN}pacmanlog2gource -f${NC} ."
gource ${LOG} -1200x720 -c 1.1 --title "${TITLE}" --key --camera-mode overview --highlight-all-users --file-idle-time 0 -auto-skip-seconds 0.001 --seconds-per-day 0.3 --hide progress,mouse${FILENAMES} --stop-at-end --max-files 99999999999 --max-file-lag 0.00001 --max-user-speed 300 --user-friction 2 ${LOGOIMAGE} --bloom-multiplier 1.3
fi
else
echo -e "To visualize the log, run ${GREEN}pacmanlog2gource -g${NC}"
fi
echo -e "For more information run ${GREEN}pacmanlog2gource -i${NC} or ${GREEN}pacmanlog2gource -h${NC}"
echo "Thanks for using pacmanlog2gource!"
exit_ 0