description_of_s_pkgdiff.sh.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #!/bin/bash
  2. echo "This script MUST BE runned after s_sloccount.sh script!"
  3. read -p "Enter package name: " name
  4. echo "Package name is $name"
  5. read -p "Enter path for package source files (ex: /home/jon/$name): " dir_path
  6. year_s=2005
  7. year_e=2018
  8. ---------------------------------------
  9. In first section of script we declare wich language we use (bash), we enter path of package that will be analize with slocount (variable dir_path) and we declare variables for start year (year_s) and end year (year_e) that will be parsed in package directory. We change working directory in path dir_path.
  10. ---------------------------------------
  11. pc_date=`date '+%Y%m%d%H%M'`
  12. cd $dir_path
  13. touch -f "$dir_path/pkgdiff_$pc_date.files"
  14. ---------------------------------------
  15. In the above section we set a new variabe pc_date that will be used for creation of new file named pkgdiff_$pc_date.files.
  16. ---------------------------------------
  17. for year_dir in `seq $year_s $year_e`
  18. do
  19. cd $dir_path/$year_dir/03
  20. echo `pwd`
  21. ---------------------------------------
  22. We start loop for years (03 and 07 - i describe only for 03, for 07 is the same) directory parsing and we change directory in every year to 03 directory (month directory). In evrey year will have 2 subdirectory (03 and 07). With line echo `pwd` we will print our path (just for control). The loop itself has two similar sections for month 03 and for month 07.
  23. ---------------------------------------
  24. archive_f=`ls -S | grep ".tar." | grep ".orig" | grep -v ".diff" | head -1`
  25. path_archive_f=`readlink -f $archive_f`
  26. ---------------------------------------
  27. At this section to archive_f variable will take the value from "ls -S" (-S param is for sort descending, largest first) output, and we will do grep on this output after 3 diferent strings (".tar.", ".orig", ".diff") and after that we print only first line (head -1)
  28. With echo $archive_f we print on screen value of archive_f variable.
  29. ---------------------------------------
  30. source_dir=`ls --file-type -1 | grep "/" | awk -F '/' '{print $1}'`
  31. cd $dir_path/$year_dir/03/$source_dir
  32. source_dir_path=`pwd`
  33. sec_archive_f=`find $source_dir_path -print | grep -E 'tar.gz|tar.xz|tar.bz2' | grep -v ".diff"`
  34. path_sec_archive_f=`readlink -f $sec_archive_f`
  35. count_dir=`ls $dir_path/$year_dir/03/$source_dir | wc -l`
  36. if [[ $count_dir -lt 3 ]]; then
  37. echo $path_sec_archive_f >> $dir_path/pkgdiff_$pc_date.files
  38. else
  39. echo $path_archive_f >> $dir_path/pkgdiff_$pc_date.files
  40. fi
  41. cd ../
  42. --------------------------------------
  43. Here is section after typs of archives and which one contain source files will be identified we will check how many directorys contain path of our package:
  44. count_dir=`ls $dir_path/$year_dir/03/$source_dir | wc -l`
  45. After that if count of dir is lower than 3, the path stored in variable $path_sec_archive_f will be written in pkgdiff_$pc_date.files (that was declared in the begining) and if count of dir will be greater than 3, the path stored in variable $path_archive_f will be written in pkgdiff_$pc_date.files.
  46. if [[ $count_dir -lt 3 ]]; then
  47. echo $path_sec_archive_f >> $dir_path/pkgdiff_$pc_date.files
  48. else
  49. echo $path_archive_f >> $dir_path/pkgdiff_$pc_date.files
  50. fi
  51. --------------------------------------
  52. cd $dir_path
  53. done
  54. chmod 444 pkgdiff_$pc_date.files
  55. for i in `seq 1 27`
  56. do
  57. mkdir report_$i
  58. j=$(( $i+1 ))
  59. var_pdif_1=`sed -n "$i"p pkgdiff_$pc_date.files`
  60. var_pdif_2=`sed -n "$j"p pkgdiff_$pc_date.files`
  61. if [[ ( -z $var_pdif_1 ) || ( -z $var_pdif_2 ) ]]; then
  62. cd report_$i
  63. echo "One or both pkgdiff variable are empty" > sources_files_comp.log
  64. else
  65. cd report_$i
  66. echo $var_pdif_1 >> sources_files_comp.log
  67. echo $var_pdif_2 >> sources_files_comp.log
  68. pkgdiff $var_pdif_1 $var_pdif_2
  69. fi
  70. cd $dir_path
  71. done
  72. --------------------------------------
  73. In above section after we change rights on pkgdiff_$pc_date.files only for reading we create a new loop where i variable can be in range 1 to 27 (this mean (2018-2005)x2months) and we create 2 new variables var_pdif_1 and var_pdif_2 (pkgdiff need 2 variables to compare). In this 2 variables will be stored paths from
  74. pkgdiff_$pc_date.files.
  75. var_pdif_1=`sed -n "$i"p pkgdiff_$pc_date.files`
  76. var_pdif_2=`sed -n "$j"p pkgdiff_$pc_date.files`
  77. If variables are empty (for some years can be empty) output will be "One or both pkgdiff variable are empty" and will be written in sources_files_comp.log
  78. If variables contain paths of sources files, this paths will be written in sources_files_comp.log and after that we run pkgdiff with those 2 paths as variables of pkgdiff application.