generateAppList.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/bin/bash
  2. # start script from it's folder
  3. cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null || exit
  4. # Standard file locations
  5. homedir='../../'
  6. . ../env.sh
  7. docIconBlue="![](../build/images/blue_doc_icon.png)"
  8. docIconRed="![](../build/images/red_doc_icon.png)"
  9. scriptIcon="![](../build/images/script_icon.png)"
  10. # Temp helper files
  11. TempList=$(mktemp)
  12. App32=$(mktemp)
  13. App64=$(mktemp)
  14. AppTitle=$(mktemp)
  15. AppType=$(mktemp)
  16. AppArch=$(mktemp)
  17. # Delete TempFiles on exit
  18. CleanExit () {
  19. rm -f "$TempList"
  20. rm -f "$App32"
  21. rm -f "$App64"
  22. rm -f "$AppTitle"
  23. rm -f "$AppType"
  24. rm -f "$AppArch"
  25. }
  26. trap CleanExit 0 1
  27. # Apps Title for both Templates
  28. jq '.templates[].title' "$pt32" | tr -d '"' > "$App32"
  29. jq '.templates[].title' "$pt64" | tr -d '"' > "$App64"
  30. cat "$App32" "$App64" | sort -uf > "$AppTitle"
  31. # Apps Type for both Templates
  32. jq '.templates[].type' "$pt32" | paste -d'|' "$App32" - > "$TempList"
  33. jq '.templates[].type' "$pt64" | paste -d'|' "$App64" - >> "$TempList"
  34. sort -uf "$TempList" > "$AppType"
  35. # Create AppList title
  36. cp -f "$AppList_TEMPLATE" "$AppList"
  37. # Generate App Table
  38. while IFS="" read -u 9 -r App || [ -n "$App" ]
  39. do
  40. # Check System Version
  41. grep -qx "$App" "$App32" && has32='32'
  42. grep -qx "$App" "$App64" && has64='64'
  43. [[ -n "$has32" && -n "$has64" ]] && Arch='32/64 bit' || Arch="$has32$has64 bit"
  44. # Get App Info
  45. info=$(jq ".apps[] | select(.Title==\"$App\")" "$appinfo")
  46. if [ "$info" != "" ] ; then
  47. # Get App Webpage from app info
  48. oweb=$(echo "$info" | jq ".Web" | tr -d '"' )
  49. if [ "$oweb" != "null" ]; then
  50. oweb="[$App]($oweb)"
  51. else
  52. oweb="$App"
  53. fi
  54. # Get App Official Doc from app info
  55. odoc=$(echo "$info" | jq ".OfficialDoc" | tr -d '"' )
  56. if [ "$odoc" != "null" ]; then
  57. odoc="[$docIconBlue]($odoc)"
  58. else
  59. unset odoc
  60. fi
  61. # Get Doc from app info
  62. docID=$(echo "$info" | jq ".DocID")
  63. if [ "$docID" != "null" ]; then
  64. doc=$(jq ".docs[] | select(.ID==$docID) | .File" "$appinfo" | tr -d '"')
  65. doc="[$docIconRed]($Docs$doc)"
  66. else
  67. unset doc
  68. fi
  69. # Get Install Script from app info
  70. scriptID=$(echo "$info" | jq ".ScriptID")
  71. if [ "$scriptID" != "null" ]; then
  72. script=$(jq ".tools[] | select(.ID==$scriptID) | .File" "$appinfo" | tr -d '"')
  73. script="[$scriptIcon]($Scripts$script)"
  74. else
  75. unset script
  76. fi
  77. # Get Extra Script from app info
  78. extraID=$(echo "$info" | jq ".ExtraID")
  79. if [ "$extraID" != "null" ]; then
  80. # If only one entry
  81. if [ "$(echo "$extraID" | wc -l )" == "1" ]; then
  82. extra=$(jq ".tools[] | select(.ID==$extraID) | .File" "$appinfo" | tr -d '"')
  83. extra="[$extra]($Extras$extra)"
  84. # If multiples entries
  85. else
  86. n_ext=$(echo "$extraID" | jq '. | length')
  87. for n in $(seq 0 $(( n_ext - 1 ))); do
  88. extID=$(echo "$extraID" | jq ".[$n]" | tr -d \")
  89. ext=$(jq ".tools[] | select(.ID==$extID) | .File" "$appinfo" | tr -d '"')
  90. if [ "$n" == "0" ]; then
  91. txt="[$ext]($Extras$ext)"
  92. else
  93. txt="$txt<br>[$ext]($Extras$ext)"
  94. fi
  95. done
  96. extra=$txt
  97. fi
  98. else
  99. unset extra
  100. fi
  101. # Get Video from app info
  102. vid=$(echo "$info" | jq ".VideoID")
  103. if [ "$vid" != "null" ] ; then
  104. vidURL=$(jq ".youtube[] | select(.ID==$vid) | .URL" "$appinfo" | tr -d \")
  105. vid="[![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=plastic&logo=youtube&logoColor=white)]($vidURL)"
  106. else
  107. unset vid
  108. fi
  109. else
  110. unset doc script extra vid oweb odoc
  111. fi
  112. # Building App Line
  113. line="|$oweb|$Arch|$(grep "$App|" "$AppType" | cut -d'|' -f2 )| $odoc | $doc | $script | $extra | $vid |"
  114. # Change container type to string (Default to Container when not set)
  115. line="${line//|1|/|Container|}"
  116. line="${line//|null|/|Container|}"
  117. line="${line//|3|/|Stack|}"
  118. # Add line to List
  119. echo "$line" >> "$AppList"
  120. # Unset System variables
  121. unset has32 has64
  122. done 9< "$AppTitle"