patched prcopyleft

Matteo Guglielmi Matteo.Guglielmi at dalco.ch
Tue May 5 08:39:24 CEST 2020


This patched version of prcopyleft will automatically center the header
text and make use of the full console width.


cheers.


###########################################
### /srv/fai/nfsroot/lib/fai/prcopyleft ###
###########################################

#!/bin/bash

#*********************************************************************
#
# This script is part of FAI (Fully Automatic Installation)
# (c) 2003-2018 by Thomas Lange, lange at informatik.uni-koeln.de
# Universitaet zu Koeln
#
#*********************************************************************

# variables needed: FAI_VERSION, do_init_tasks

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_repeatstring() {
  local str=$1
  local len=$2

  len=$(seq 1 $len)

  [ -z "$len" ] || printf -- "$str%.0s" $len
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
_prcopyleft() {
  local devcon=/dev/console
  local rows cols edge empty MSG
  local i j msg len diff half mod lx rx

  read rows cols < <(stty size < $devcon)

  edge="+$(_repeatstring - $[cols - 2])+"
  empty="|$(_repeatstring ' ' $[cols - 2])|"
  MSG=("Fully Automatic Installation  -  FAI"
       "$FAI_VERSION  (c) 1999-2020"
       "Thomas Lange  <lange at informatik.uni-koeln.de>")

  echo "$edge"

  for ((i=0, j=1; i<${#MSG[@]}; i++, j++)); do
    msg=${MSG[$i]}
    len=${#msg}
    diff=$[cols - len]
    half=$[diff / 2]
    mod=$[diff % 2]
    lx="|$(_repeatstring ' ' $[half - 1])"
    rx=$(_repeatstring ' ' $mod)$(echo "$lx" | rev)
    msg=$lx$msg$rx

    echo "$msg"

    [ $j -lt ${#MSG[@]} ] && echo "$empty" || echo "$edge"
  done
}
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

# color logo only if initial install
color_logo=$do_init_tasks

# set red color, but not on some archs
[ -e /.nocolorlogo ] && color_logo=0
[ -n "$console" ] && color_logo=0  # no red logo if console was defined on the command line
case $HOSTTYPE in
  sparc*|powerpc*) color_logo=0 ;;
esac

[ $color_logo -eq 1 ] && echo -ne "\ec\e[1;31m"

_prcopyleft | tee -a $LOGDIR/fai.log

if [ $color_logo -eq 1 ]; then
  echo -ne "\e[8;0r"
  echo -ne "\e[9B\e[1;m"
fi


More information about the linux-fai mailing list