generateAppList.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. # Create AppList title
  11. cp -f "$AppList_TEMPLATE" "$AppList"
  12. # Generate App Table
  13. while IFS='' read -u 9 -r appfile || [[ -n $appfile ]]; do
  14. # Clear previous variables
  15. unset doc script extra vid oweb odoc type has32 has64
  16. # Get app json
  17. appconf=$( jq '.' "$appfile" )
  18. # App Title
  19. App=$( echo "$appconf" | jq '.title' | tr -d '"' )
  20. # App Architecture
  21. if echo "$appconf" | jq -e '.image' &> /dev/null || echo "$appconf" | jq -e '.repository.stackfile' &> /dev/null ; then
  22. has32='32'
  23. has64='64'
  24. else
  25. if echo "$appconf" | jq -e '.image32' &> /dev/null || echo "$appconf" | jq -e '.repository.stackfile32' &> /dev/null ; then has32='32' ; fi
  26. if echo "$appconf" | jq -e '.image64' &> /dev/null || echo "$appconf" | jq -e '.repository.stackfile64' &> /dev/null ; then has64='64' ; fi
  27. fi
  28. [[ -n "$has32" && -n "$has64" ]] && Arch='32/64 bit' || Arch="$has32$has64 bit"
  29. # Apps Type
  30. apptype=$( echo "$appconf" | jq '.type' | tr -d '"' )
  31. # Get App Webpage from app info
  32. oweb=$(echo "$appconf" | jq ".webpage" | tr -d '"' )
  33. if [ "$oweb" != "null" ]; then
  34. oweb="[$App]($oweb)"
  35. else
  36. oweb="$App"
  37. fi
  38. # Get App Official Doc from app info
  39. odoc=$(echo "$appconf" | jq ".officialDoc" | tr -d '"' )
  40. if [ "$odoc" != "null" ]; then
  41. odoc="[$docIconBlue]($odoc)"
  42. else
  43. unset odoc
  44. fi
  45. # Get Doc from app info
  46. doc=$(echo "$appconf" | jq ".piHostedDoc" | tr -d '"' )
  47. if [ "$doc" != "null" ]; then
  48. doc="[$docIconRed]($Docs$doc)"
  49. else
  50. unset doc
  51. fi
  52. # Get Install Script from app info
  53. script=$(echo "$appconf" | jq ".preInstallScript" | tr -d '"' )
  54. if [ "$script" != "null" ]; then
  55. script="[$scriptIcon]($Scripts$script)"
  56. else
  57. unset script
  58. fi
  59. # Get Extra Script from app info
  60. if ExtraScript=$( echo "$appconf" | jq -e '.extraScript' ) ; then
  61. # If only one entry
  62. if [ "$(echo "$ExtraScript" | wc -l )" == "1" ]; then
  63. extra="[${ExtraScript:1:-1}]($Extras${ExtraScript:1:-1})"
  64. # If multiples entries
  65. else
  66. n_ext=$(echo "$ExtraScript" | jq '. | length')
  67. for n in $(seq 0 $(( n_ext - 1 ))); do
  68. ext=$(echo "$ExtraScript" | jq ".[$n]" | tr -d '"')
  69. if [ "$n" == "0" ]; then
  70. extra="[$ext]($Extras$ext)"
  71. else
  72. extra="$extra<br>[$ext]($Extras$ext)"
  73. fi
  74. done
  75. fi
  76. else
  77. unset extra n_ext ExtraScript
  78. fi
  79. # Get Video from app info
  80. vid=$(echo "$appconf" | jq ".videoID")
  81. if [ "$vid" != "null" ] ; then
  82. vidURL=$(jq ".youtube[] | select(.ID==$vid) | .URL" "$appinfo" | tr -d '"')
  83. vid="[![YouTube](https://img.shields.io/badge/YouTube-FF0000?style=plastic&logo=youtube&logoColor=white)]($vidURL)"
  84. else
  85. unset vid
  86. fi
  87. # Building App Line
  88. line="|$oweb|$Arch|$apptype| $odoc | $doc | $script | $extra | $vid |"
  89. # Change container type to string (Default to Container when not set)
  90. line="${line//|1|/|Container|}"
  91. line="${line//|null|/|Container|}"
  92. line="${line//|3|/|Stack|}"
  93. # Add line to List
  94. echo "$line" >> "$AppList"
  95. done 9< <( LC_COLLATE=en_US.utf8 ls $appsfolder/*.json )