description_of_s_sloccont.sh.txt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. -----------
  2. #!/bin/bash
  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. cd $dir_path
  9. -----------
  10. 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.
  11. -----------
  12. for year_dir in `seq $year_s $year_e`
  13. do
  14. cd $dir_path/$year_dir/03
  15. echo `pwd`
  16. -----------
  17. We start loop for years 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.
  18. -----------
  19. archive_f=`ls -S | grep ".tar." | grep ".orig" | grep -v ".diff" | head -1`
  20. echo $archive_f
  21. -----------
  22. 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)
  23. With echo $archive_f we print on screen value of archive_f variable.
  24. -----------
  25. if [[ $archive_f =~ ".gz" ]]; then
  26. echo "File with GZ extension"
  27. tar xvzf $archive_f
  28. source_dir=`ls --file-type -1 | grep "/" | awk -F '/' '{print $1}'`
  29. cd $dir_path/$year_dir/03/$source_dir
  30. source_dir_path=`pwd`
  31. sec_archive_f=`find $source_dir_path -print | grep -E 'tar.gz|tar.xz|tar.bz2' | grep -v ".diff"`
  32. if [[ $sec_archive_f =~ ".gz" ]]; then
  33. tar xvzf $sec_archive_f
  34. elif [[ $sec_archive_f =~ ".xz" ]]; then
  35. tar xvf $sec_archive_f
  36. else
  37. tar xvjf $sec_archive_f
  38. fi
  39. cd ../
  40. sloccount $source_dir_path > sloccount.log
  41. -----------
  42. Here is section were will be identified typs of archives and which one contain source files (in many cases we have archive in archive)
  43. The other "elif" sections are similar with this "if" section. In this "if" section we will check tar archives with .gz extension
  44. if [[ $archive_f =~ ".gz" ]]; then
  45. and in elif sections will check achive files with .xz extension and .bz2 extension.
  46. So if archive is with .gz extension then we will unpack archive in line
  47. tar xvzf $archive_f
  48. After that in new created directory from archive we will have source files of package or another archive (tar.gz, tar.xz or tar.bz2), we will do that here
  49. source_dir=`ls --file-type -1 | grep "/" | awk -F '/' '{print $1}'`
  50. cd $dir_path/$year_dir/03/$source_dir
  51. source_dir_path=`pwd`
  52. sec_archive_f=`find $source_dir_path -print | grep -E 'tar.gz|tar.xz|tar.bz2' | grep -v ".diff"`
  53. If we will find another archive in source directory we will check what kind of archive is and we will unpack in next if and elif statements
  54. if [[ $sec_archive_f =~ ".gz" ]]; then
  55. tar xvzf $sec_archive_f
  56. elif [[ $sec_archive_f =~ ".xz" ]]; then
  57. tar xvf $sec_archive_f
  58. else
  59. tar xvjf $sec_archive_f
  60. fi
  61. After all this checks we will change one directory up and we will do slocount on source directory.
  62. All this will apply for principal archive with .xz or .bz2 extension.
  63. After this script will do same verifications for month 07.