makeTags 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #! /bin/sh -
  2. #
  3. # Gets information from packages to create a checklist for
  4. # the installer of Dragora (also know as "tagfiles")
  5. #
  6. # Copyright (c) 2019 Matias Fonzo, <selk@dragora.org>.
  7. #
  8. # Licensed under the Apache License, Version 2.0 (the "License");
  9. # you may not use this file except in compliance with the License.
  10. # You may obtain a copy of the License at
  11. #
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. #
  14. # Unless required by applicable law or agreed to in writing, software
  15. # distributed under the License is distributed on an "AS IS" BASIS,
  16. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. # See the License for the specific language governing permissions and
  18. # limitations under the License.
  19. # USAGE: makeTags [directory]
  20. # e.g: makeTags i586/tools
  21. set -e
  22. getSize()
  23. {
  24. lzip_output="$(plzip -tvvv "$1" 2>&1)"
  25. # To obtain the uncompressed, compressed size
  26. echo $lzip_output | awk '{ print $8 $10 }' | \
  27. while IFS=, read -r decompressed compressed
  28. do
  29. echo "Decompressed size $(( $decompressed / 1024 ))K, Compressed size $(( ${compressed%.} / 1024 ))K"
  30. done
  31. unset lzip_output
  32. }
  33. searchpath="$1"
  34. searchpath="${searchpath:-.}"
  35. echo "Deleting any previous (.tmp) tagfile ..."
  36. find $searchpath -type f -name 'tagfile*' -exec rm -f '{}' +
  37. umask 022
  38. # Search all .tlz packages
  39. for meta in $(find $searchpath -type f -name '*.tlz')
  40. do
  41. # Ignore some package names
  42. case $meta in
  43. *_pass?*)
  44. echo " ${meta}: Ignored."
  45. continue;
  46. ;;
  47. esac
  48. if test ! -e "${meta}.txt"
  49. then
  50. echo "Error ${meta##*/} does not have a meta tag file." 1>&2
  51. exit 99;
  52. fi
  53. meta="${meta}.txt"
  54. directory=$(dirname -- "$meta")
  55. category="${directory##*/}"
  56. # Determine output level for those series with sub-directories
  57. case $directory in
  58. */modules/* | */xorg/*)
  59. output_level=../
  60. parent_level="$(dirname -- $directory)"
  61. parent_level="$(basename -- $parent_level)"
  62. parent_level=${parent_level}_
  63. ;;
  64. esac
  65. echo "Extracting information from $meta ..."
  66. . $meta
  67. (
  68. cd -- "$directory"
  69. echo " Adding information to ${output_level}tagfile-${parent_level}${category}.tmp"
  70. echo "${pkgname}:${blurb}:ON:Version ${pkgversion} - $(getSize $(basename -- "${meta%.txt}"))" \
  71. >> "${output_level}tagfile-${parent_level}${category}.tmp"
  72. )
  73. unset output_level parent_level
  74. done
  75. echo "Removing temporal tagfile(s) and sorting the final ones ..."
  76. for tagfile in ./*/*/tagfile*.tmp
  77. do
  78. LC_COLLATE=C sort -- "$tagfile" > "${tagfile%.tmp}"
  79. rm -f -- "$tagfile"; # Delete temporary tagfile.
  80. done
  81. echo "All done."