#!/usr/bin/env bash
# ==========================================================================
#         ____            _                     _____           _
#        / ___| _   _ ___| |_ ___ _ __ ___     |_   _|__   ___ | |___
#        \___ \| | | / __| __/ _ \ '_ ` _ \ _____| |/ _ \ / _ \| / __|
#         ___) | |_| \__ \ ||  __/ | | | | |_____| | (_) | (_) | \__ \
#        |____/ \__, |___/\__\___|_| |_| |_|     |_|\___/ \___/|_|___/
#               |___/
#                             --- System-Tools ---
#                  https://www.nntb.no/~dreibh/system-tools/
# ==========================================================================
#
# Helper script for showing System-Info banner examples
# Copyright (C) 2025 by Thomas Dreibholz
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Contact: thomas.dreibholz@gmail.com

# Bash options:
set -eu


NUMBER=""
if [ $# -gt 0 ] ; then
   NUMBER="$1"
fi


readarray -t banners < <(find system-info.d -mindepth 1 -maxdepth 1 -name "[0-9][0-9]-*" | sort)
hostnames=( ""
            "kringsjaa.domain.example"
            "sognsvann.lab.smil"
            "svartkulp.lab.smil"
            "maridalsvannet.simula.nornet"
            "blanksjoe.testbed.neat"
            "altenessen.ude.nornet"
            "tryvann.testbed.neat"
            "altenessen.simula.nornet"
            "aaklungen.simula.nornet"
          )

n=0
for banner in "${banners[@]}" ; do
   echo "Processing ${banner} ..."
   n=$((n+1))
   rm -rf "example-${n}"
   mkdir -p "example-${n}"
   cp "${banner}"                 "example-${n}/"
   cp system-info.d/banner-helper "example-${n}/"
done

if [ -d "example-${NUMBER}" ] ; then
   echo "Trying example ${NUMBER}, hostname is ${hostnames[$NUMBER]}"
   sudo hostname "${hostnames[$NUMBER]}"
   sudo find /etc/system-info.d/ -mindepth 1 -maxdepth 1 -exec rm {} \;
   sudo cp "example-${NUMBER}/"* /etc/system-info.d/
   ls -l /etc/system-info.d/
   System-Info
fi
