1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
#!/usr/bin/env bash
# suppress stdout from pushd and popd commands
pushd () {
command pushd "$@" > /dev/null
}
popd () {
command popd "$@" > /dev/null
}
if [ -z "$1" ]; then
echo "You must inform a directory to store built files."
exit 1
fi
PAGES_DIR=$1
mkdir -p $PAGES_DIR
STATS_DIR=$PAGES_DIR/statistics
mkdir -p $STATS_DIR
touch $STATS_DIR/index.html
echo "<!DOCTYPE html>" > $STATS_DIR/index.html
echo '<html lang="en">' >> $STATS_DIR/index.html
echo "<head>" >> $STATS_DIR/index.html
echo '<meta charset="utf-8" />' >> $STATS_DIR/index.html
echo "<title>Statistics</title>" >> $STATS_DIR/index.html
echo "</head>" >> $STATS_DIR/index.html
echo "<body>" >> $STATS_DIR/index.html
echo "<h1>Statistics</h1>" >> $STATS_DIR/index.html
# get supported products
products=$(echo -e "import ssg.constants\nprint(ssg.constants.product_directories)" | python3 | sed -s "s/'//g; s/,//g; s/\[//g; s/\]//g")
for product in $products
do
if [ -d build/$product ]; then
echo "<h4>Product: ${product}</h4>" >> $STATS_DIR/index.html
echo "<ul>" >> $STATS_DIR/index.html
mkdir -p $STATS_DIR/$product
if [ -f build/$product/product-statistics/statistics.html ]; then
cp -rf build/$product/product-statistics $STATS_DIR/$product/product-statistics
echo "<li><a href=\"$product/product-statistics/statistics.html\">Product Statistics</a></li>" >> $STATS_DIR/index.html
fi
if [ -f build/$product/profile-statistics/statistics.html ]; then
cp -rf build/$product/profile-statistics $STATS_DIR/$product/profile-statistics
echo "<li><a href=\"$product/profile-statistics/statistics.html\">Profile statistics</a></li>" >> $STATS_DIR/index.html
fi
echo "</ul>" >> $STATS_DIR/index.html
fi
done
echo "</body>" >> $STATS_DIR/index.html
echo "</html>" >> $STATS_DIR/index.html
# Generate Guides page
mkdir -p $PAGES_DIR/guides
cp -rf build/guides $PAGES_DIR
utils/gen_html_guides_index.py . $PAGES_DIR/guides/index.html
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Something wrong happened while generating the HTML Guides Index page"
exit 1
fi
# Generate Mapping Tables page
pushd build/tables
touch index.html
echo "<!DOCTYPE html>" > index.html
echo '<html lang="en">' >> index.html
echo "<head>" >> index.html
echo '<meta charset="utf-8" />' >> index.html
echo "<title>Mapping Tables</title>" >> index.html
echo "</head>" >> index.html
echo "<body>" >> index.html
echo "<h1>Mapping Tables</h1>" >> index.html
echo "<ul>" >> index.html
for table in table-*.html
do
echo "<li><a href=\"${table}\">${table}</a></li>" >> index.html
done
echo "</ul>" >> index.html
echo "</body>" >> index.html
echo "</html>" >> index.html
popd
# Generate Rendered Policies page
POLICY_DIR="$PAGES_DIR/rendered-policies"
mkdir -p "$POLICY_DIR"
products=$(echo -e "import ssg.constants\nprint(ssg.constants.product_directories)" | python3 | sed -s "s/'//g; s/,//g; s/\[//g; s/\]//g")
for product in $products
do
if [ -d build/$product ]; then
mkdir -p "$POLICY_DIR/$product"
if [ -d "build/$product/rendered-policies/" ]; then
cp -rf "build/${product}/rendered-policies/"* "$POLICY_DIR/$product/"
fi
fi
done
utils/gen_rendered_policies_index.py . "$PAGES_DIR/rendered-policies/index.html"
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Something wrong happened while generating the HTML Rendered Policy Index page"
exit 1
fi
# Generate Components page
COMPONENTS_DIR="$PAGES_DIR/components"
mkdir -p "$COMPONENTS_DIR"
utils/render_components.py -r "$(pwd)" "$COMPONENTS_DIR"
retVal=$?
if [ $retVal -ne 0 ]; then
echo "Something wrong happened while generating components HTML pages."
exit 1
fi
# Generate Prometheus Stats
PROMETHEUS_STATS_DIR="$PAGES_DIR/prometheus_stats"
mkdir -p "$PROMETHEUS_STATS_DIR"
mv build/policies_metrics "$PROMETHEUS_STATS_DIR"
pushd $PAGES_DIR
touch index.html
echo "<!DOCTYPE html>" > index.html
echo '<html lang="en">' >> index.html
echo "<head>" >> index.html
echo '<meta charset="utf-8" />' >> index.html
echo "<title>Available Artifacts</title>" >> index.html
echo "</head>" >> index.html
echo "<body>" >> index.html
echo "<h1>Available Artifacts</h1>" >> index.html
echo "<ul>" >> index.html
echo "<li><a href=\"statistics/index.html\">Statistics</a></li>" >> index.html
echo "<li><a href=\"guides/index.html\">Guides</a></li>" >> index.html
echo "<li><a href=\"tables/index.html\">Mapping Tables</a></li>" >> index.html
echo "<li><a href=\"srg_mapping/index.html\">SRG Mapping Tables</a></li>" >> index.html
echo "<li><a href=\"rendered-policies/index.html\">Rendered Policies</a></li>" >> index.html
echo "<li><a href=\"components/index.html\">Components</a></li>" >> index.html
echo "<li><a href=\"prometheus_stats/policies_metrics\">Prometheus Policies Metrics</a></li>" >> index.html
echo "</ul>" >> index.html
echo "</body>" >> index.html
echo "</html>" >> index.html
popd
cp -rf build/tables $PAGES_DIR
exit 0
|