blobs-discover 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #!/bin/bash
  2. # Copyright (C) 2016 Paul Kocialkowski <contact@paulk.fr>
  3. #
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. arguments() {
  17. local project=$1
  18. if [ -z "$project" ]
  19. then
  20. ls -A "$root/$PROJECTS/" | while read project
  21. do
  22. echo "$project"
  23. done
  24. else
  25. shift
  26. project_action_helper "arguments" "$project" "$@"
  27. fi
  28. }
  29. usage() {
  30. tool_usage_actions "$tool" "verify"
  31. tool_usage_arguments "$tool" "$@"
  32. }
  33. update() {
  34. local tool_path=$( tool_path "$tool" )
  35. local sources_path=$( tool_sources_path "$tool" )
  36. local deblob_check_path="$sources_path/deblob-check"
  37. local patches_path="$tool_path/$PATCHES/$WILDDOTPATCH"
  38. wget "https://www.fsfla.org/svn/fsfla/software/linux-libre/scripts/deblob-check" -O "$deblob_check_path"
  39. perl -0777 -i -pe "s/ blobna \(\) \{[^\}]*\}/ blobna () \{\n true\n \}/" "$deblob_check_path"
  40. perl -0777 -i -pe "s/ blobname \(\) \{[^\}]*\}/ blobname () \{\n true\n \}/" "$deblob_check_path"
  41. chmod a+x "$deblob_check_path"
  42. cd "$sources_path"
  43. path_wildcard_expand "$patches_path" | while read patch_path
  44. do
  45. if ! [ -f "$patch_path" ]
  46. then
  47. continue
  48. fi
  49. patch -p1 < "$patch_path"
  50. done
  51. }
  52. verify() {
  53. local project=$1
  54. shift
  55. local project_path=$( project_path "$project" )
  56. local project_sources_path=$( project_sources_path "$project" "$repository" "$@" )
  57. local project_blobs_path=$( project_blobs_path "$project" "$@" )
  58. local project_blobs_ignore_path=$( project_blobs_ignore_path "$project" "$@" )
  59. local project_blobs_discover_path
  60. local ifs_save
  61. local file
  62. local choice
  63. requirements "sort"
  64. if ! [ -z "$project_blobs_path" ]
  65. then
  66. project_blobs_discover_path="$( dirname $project_blobs_path )/$BLOBS_DISCOVER"
  67. else
  68. project_blobs_discover_path="$project_path/$CONFIGS/$BLOBS_DISCOVER"
  69. fi
  70. file_exists_check "$project_blobs_discover_path"
  71. # This it to allow space characters in arguments.
  72. ifs_save=$IFS
  73. IFS=$'\n'
  74. for file in $( cat "$project_blobs_discover_path" )
  75. do
  76. (
  77. IFS=$ifs_save
  78. printf "\nDiscovered blob: $file\n"
  79. $EDITOR "$project_sources_path/$file"
  80. printf "Type \"blob\" to keep or press enter to discard: "
  81. read choice
  82. if [ "$choice" = "blob" ]
  83. then
  84. echo "$file" >> "$project_blobs_path"
  85. else
  86. echo "$file" >> "$project_blobs_ignore_path"
  87. fi
  88. sed "\|^$file$|d" -i "$project_blobs_discover_path"
  89. ) < /dev/tty
  90. done
  91. IFS=$ifs_save
  92. rm "$project_blobs_discover_path"
  93. sort -o "$project_blobs_path" "$project_blobs_path"
  94. sort -o "$project_blobs_ignore_path" "$project_blobs_ignore_path"
  95. }
  96. execute() {
  97. local project=$1
  98. shift
  99. local repository=$project
  100. local repository_path=$( git_project_repository_path "$repository" )
  101. # This assumes that the repository is the project, which is not always the case.
  102. project_sources_directory_missing_empty_error "$project" "$repository"
  103. local sources_path=$( tool_sources_path "$tool" )
  104. local project_path=$( project_path "$project" )
  105. local project_sources_path=$( project_sources_path "$project" "$repository" "$@" )
  106. local project_blobs_path=$( project_blobs_path "$project" "$@" )
  107. local project_blobs_ignore_path=$( project_blobs_ignore_path "$project" "$@" )
  108. local project_blobs_directory_path
  109. if ! [ -z "$project_blobs_path" ]
  110. then
  111. project_blobs_discover_path="$( dirname $project_blobs_path )/$BLOBS_DISCOVER"
  112. else
  113. project_blobs_discover_path="$project_path/$CONFIGS/$BLOBS_DISCOVER"
  114. fi
  115. local deblob_check_path="$sources_path/deblob-check"
  116. if git_project_check "$repository"
  117. then
  118. git_project_checkout "$project" "$repository" "$@"
  119. git_clean "$repository_path"
  120. fi
  121. printf "\nDiscovering new blobs, this may take a while...\n"
  122. files=$( find "$project_sources_path" -type f | grep -vP "\.git/|\.tar|\.patch" )
  123. touch "$project_blobs_discover_path"
  124. echo "$files" | while read file
  125. do
  126. if ! [ -z "$project_blobs_ignore_path" ]
  127. then
  128. match=$( grep "$file" "$project_blobs_ignore_path" || true)
  129. if [ ! -z "$match" ]
  130. then
  131. continue
  132. fi
  133. fi
  134. match=$( "$deblob_check_path" -l -i "" "$file" || true )
  135. if ! [ -z "$match" ]
  136. then
  137. echo "$match" >> "$project_blobs_discover_path"
  138. fi
  139. done
  140. printf "\nDiscovered blobs were stored in $project_blobs_discover_path\n"
  141. }
  142. execute_check() {
  143. local project=$1
  144. shift
  145. local project_path=$( project_path "$project" )
  146. local project_blobs_path=$( project_blobs_path "$project" "$@" )
  147. local project_blobs_ignore_path=$( project_blobs_ignore_path "$project" "$@" )
  148. local project_blobs_discover_path
  149. if ! [ -z "$project_blobs_path" ]
  150. then
  151. project_blobs_discover_path="$( dirname $project_blobs_path )/$BLOBS_DISCOVER"
  152. else
  153. project_blobs_discover_path="$project_path/$CONFIGS/$BLOBS_DISCOVER"
  154. fi
  155. file_exists_check "$project_blobs_discover_path"
  156. }