2022-04-01 09:59:38 +00:00
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
2022-11-30 21:52:06 +00:00
include_questions( ) {
2022-04-01 09:59:38 +00:00
local chart = " $1 "
local chartname = " $2 "
local train = " $3 "
local chartversion = " $4 "
2022-09-26 08:11:11 +00:00
local source = " charts/ ${ train } / ${ chartname } /questions.yaml "
local target = " catalog/ ${ train } / ${ chartname } / ${ chartversion } /questions.yaml "
2022-04-01 09:59:38 +00:00
2022-09-26 08:11:11 +00:00
echo " Making copy of $source to $target "
cp ${ source } ${ target }
2022-09-25 09:14:39 +00:00
2022-09-26 08:11:11 +00:00
echo " Including standardised questions.yaml includes for: ${ chartname } "
sed -i -E 's:^.*# Include\{(.*)\}.*$:cat templates/questions/**/\1.yaml:e' ${ target }
2022-11-30 21:52:06 +00:00
}
2022-04-01 09:59:38 +00:00
export -f include_questions
clean_catalog( ) {
local chart = " $1 "
local chartname = " $2 "
local train = " $3 "
local chartversion = " $4 "
cd catalog/${ train } /${ chartname }
local majorversions = $( ( find . -mindepth 1 -maxdepth 1 -type d \( ! -iname ".*" \) | sed 's|^\./||g' ) | sort -Vr | cut -c1 | uniq)
echo " Removing old versions for: ${ chartname } "
for majorversion in ${ majorversions } ; do
2022-11-30 21:52:06 +00:00
local maxofmajor = $( ( find . -mindepth 1 -maxdepth 1 -type d \( -iname " ${ majorversion } .* " \) | sed 's|^\./||g' ) | sort -Vr | head -n1 )
local rmversions = $( ( find . -mindepth 1 -maxdepth 1 -type d \( -iname " ${ majorversion } .* " \) \( ! -iname " ${ maxofmajor } " \) | sed 's|^\./||g' ) | sort -Vr )
rm -Rf ${ rmversions }
2022-04-01 09:59:38 +00:00
done
cd -
2022-11-30 21:52:06 +00:00
}
2022-04-01 09:59:38 +00:00
export -f clean_catalog
clean_apps( ) {
local chart = " $1 "
local chartname = " $2 "
local train = " $3 "
local chartversion = " $4 "
2022-08-08 21:57:58 +00:00
echo " Cleaning SCALE catalog for Chart: ${ chartname } "
2022-04-01 09:59:38 +00:00
rm -Rf catalog/${ train } /${ chartname } /${ chartversion } 2>/dev/null || :
rm -Rf catalog/${ train } /${ chartname } /item.yaml 2>/dev/null || :
}
export -f clean_apps
patch_apps( ) {
local chart = " $1 "
local chartname = " $2 "
local train = " $3 "
local chartversion = " $4 "
local target = " catalog/ ${ train } / ${ chartname } / ${ chartversion } "
2022-08-08 21:57:58 +00:00
echo " Applying SCALE patches for Chart: ${ chartname } "
2022-04-01 09:59:38 +00:00
# Temporary fix to prevent the UI from bugging out on 21.08
mv ${ target } /values.yaml ${ target } /ix_values.yaml 2>/dev/null || :
touch ${ target } /values.yaml
# mv ${target}/SCALE/ix_values.yaml ${target}/ 2>/dev/null || :
cp -rf ${ target } /SCALE/templates/* ${ target } /templates 2>/dev/null || :
2022-06-07 17:41:19 +00:00
cp -rf ${ target } /SCALE/migrations/* ${ target } /migrations 2>/dev/null || :
2022-04-01 09:59:38 +00:00
rm -rf ${ target } /SCALE 2>/dev/null || :
touch ${ target } /values.yaml
2022-11-09 21:56:37 +00:00
# Remove content that is not required for the App to install
2022-07-06 20:38:12 +00:00
rm -rf ${ target } /security.md
rm -rf ${ target } /helm-values.md
rm -rf ${ target } /CONFIG.md
2022-07-14 20:20:09 +00:00
rm -rf ${ target } /docs
rm -rf ${ target } /icon.png
2022-11-09 21:56:37 +00:00
rm -rf ${ target } /ci
2022-04-01 09:59:38 +00:00
# Generate item.yaml
cat ${ target } /Chart.yaml | grep "icon" >> catalog/${ train } /${ chartname } /item.yaml
sed -i "s|^icon:|icon_url:|g" catalog/${ train } /${ chartname } /item.yaml
echo "categories:" >> catalog/${ train } /${ chartname } /item.yaml
2023-10-28 17:12:33 +00:00
category = $( cat ${ target } /Chart.yaml | yq '.annotations."truecharts.org/category"' -r)
echo " - $category " >> catalog/${ train } /${ chartname } /item.yaml
2023-06-13 07:56:52 +00:00
# Generate screenshots
2023-06-16 09:24:44 +00:00
screenshots = ""
2023-06-16 06:03:45 +00:00
if [ [ -d " ${ target } /screenshots " ] ] ; then
screenshots = $( ls ${ target } /screenshots)
fi
2023-06-13 07:56:52 +00:00
if [ [ -n $screenshots ] ] ; then
echo "screenshots:" >> catalog/${ train } /${ chartname } /item.yaml
for screenshot in $screenshots ; do
echo " - https://truecharts.org/img/hotlink-ok/chart-screenshots/ ${ chartname } / ${ screenshot } " >> catalog/${ train } /${ chartname } /item.yaml
done
else
echo "screenshots: []" >> catalog/${ train } /${ chartname } /item.yaml
fi
rm -rf ${ target } /screenshots
2022-11-10 19:39:03 +00:00
# Copy changelog from website
2022-12-01 10:56:21 +00:00
if [ [ ! -f " website/docs/charts/ ${ train } / ${ chartname } /CHANGELOG.md " ] ] ; then
touch " website/docs/charts/ ${ train } / ${ chartname } /CHANGELOG.md "
2022-11-30 21:52:06 +00:00
fi
2022-12-01 10:56:21 +00:00
cp -rf " website/docs/charts/ ${ train } / ${ chartname } /CHANGELOG.md " " ${ target } /CHANGELOG.md " 2>/dev/null || :
2022-11-10 19:39:03 +00:00
sed -i '1d' " ${ target } /CHANGELOG.md "
2022-11-10 19:59:21 +00:00
sed -i '1s/^/*for the complete changelog, please refer to the website*\n\n/' " ${ target } /CHANGELOG.md "
sed -i '1s/^/**Important:**\n/' " ${ target } /CHANGELOG.md "
2022-11-10 19:39:03 +00:00
sed -i '100,$ d' " ${ target } /CHANGELOG.md " || :
2022-04-01 09:59:38 +00:00
# Generate SCALE App description file
cat ${ target } /Chart.yaml | yq .description -r >> ${ target } /app-readme.md
echo "" >> ${ target } /app-readme.md
2022-12-25 08:49:27 +00:00
echo " This App is supplied by TrueCharts, for more information visit the manual: [https://truecharts.org/charts/ ${ train } / ${ chartname } ](https://truecharts.org/charts/ ${ train } / ${ chartname } ) " >> ${ target } /app-readme.md
2022-07-19 11:53:25 +00:00
echo "" >> ${ target } /app-readme.md
echo "---" >> ${ target } /app-readme.md
echo "" >> ${ target } /app-readme.md
echo "TrueCharts can only exist due to the incredible effort of our staff." >> ${ target } /app-readme.md
2023-01-15 09:35:02 +00:00
echo "Please consider making a [donation](https://truecharts.org/sponsor) or contributing back to the project any way you can!" >> ${ target } /app-readme.md
2022-04-01 09:59:38 +00:00
}
export -f patch_apps
copy_apps( ) {
local chart = " $1 "
local chartname = " $2 "
local train = " $3 "
local chartversion = " $4 "
echo " Copying App to Catalog: ${ 2 } "
mkdir -p catalog/${ train } /${ chartname } /${ chartversion }
cp -Rf ${ chart } /* catalog/${ train } /${ chartname } /${ chartversion } /
}
export -f copy_apps
2022-04-03 08:55:01 +00:00
if [ [ -d " charts/ ${ 1 } " ] ] ; then
echo " Start processing charts/ ${ 1 } ... "
chartversion = $( cat charts/${ 1 } /Chart.yaml | grep "^version: " | awk -F" " '{ print $2 }' )
chartname = $( basename charts/${ 1 } )
train = $( basename $( dirname " charts/ ${ 1 } " ) )
SCALESUPPORT = $( cat charts/${ 1 } /Chart.yaml | yq '.annotations."truecharts.org/SCALE-support"' -r)
if [ [ " ${ SCALESUPPORT } " = = "true" ] ] ; then
2022-11-30 21:52:06 +00:00
clean_apps " charts/ ${ 1 } " " ${ chartname } " " $train " " ${ chartversion } "
copy_apps " charts/ ${ 1 } " " ${ chartname } " " $train " " ${ chartversion } "
patch_apps " charts/ ${ 1 } " " ${ chartname } " " $train " " ${ chartversion } "
include_questions " charts/ ${ 1 } " " ${ chartname } " " $train " " ${ chartversion } "
clean_catalog " charts/ ${ 1 } " " ${ chartname } " " $train " " ${ chartversion } "
2022-04-03 08:55:01 +00:00
else
2022-11-30 21:52:06 +00:00
echo " Skipping chart charts/ ${ 1 } , no correct SCALE compatibility layer detected "
2022-04-03 08:55:01 +00:00
fi
else
echo " Chart 'charts/ ${ 1 } ' no longer exists in repo. Skipping it... "
fi
echo " Done processing charts/ ${ 1 } ... "