##################################################################################
# File...: /root/.profile
# Status : Local Slackware ARM addition - not required for x86.
# Purpose: Within the Slackware Installer, display the initial setup instructions
#          when the user activates the local consoles.  By default /etc/{issue,motd}
#          will be displayed only over the serial console, but if the user doesn't
#          have a serial adaptor (only installing via the console), they'll never
#          see these initial setup instructions.
# Author : Stuart Winter <mozes@slackware.com>
# Date...: 30-May-2021
##################################################################################
# Copyright 2021 Stuart Winter, Donostia, Spain.
# All rights reserved.
#
# Redistribution and use of this script, with or without modification, is
# permitted provided that the following conditions are met:
#
# 1. Redistributions of this script must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
#
#  THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
#  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO
#  EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
#  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
#  PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
#  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
#  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
#  OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
#  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

export PATH=/usr/sbin:$PATH

# Only clear the screen if we're on a tty where we had to press ENTER
# to activate the console.
# This clearing of the screen reduces the confusion when a bunch of typically
# superfluous info suddenly becomes larger.
# There's no need to do this over a serial console though:
tty > /dev/null && clear

# Determine the Hardware Model:
export HWM=$( strings /proc/device-tree/model 2>/dev/null )

# I experimented with changing the console screen resolution, but
# was unsuccessful.  To compensate, we'll set a larger font on both
# the RockPro64 and Pinebook Pro.
#case $HWM in
#   "Raspberry Pi 4"*|"Pine64 RockPro64"*|"Pine64 Pinebook Pro"*)
      setfont /usr/share/kbd/consolefonts/ter-732b.psf.gz > /dev/null 2>&1
#      ;;
#esac

# Display the instructions once whenever any of the local consoles are activated:
( tty | grep -Eq '^/dev/tty[0-9]' ) && {

   # Offer to load a key map once on the local console:
   # (this code was copied from /etc/rc.d/rc.S)
   [ ! -f /.keymapset ] && {
      echo
      echo
      echo "<OPTION TO LOAD SUPPORT FOR NON-US KEYBOARD>"
      echo
      echo "If you are not using a US keyboard, you may now load a different"
      echo "keyboard map. To select a different keyboard map, please enter 1"
      echo "now. To continue using the US map, just hit enter."
      echo
      echo -n "Enter 1 to select a keyboard map: "
      read ONE
      if [ "$ONE" = "1" ]; then
         /usr/lib/setup/SeTkeymap
      fi
      clear
      # Set flag to bypass on any other local activations:
      touch /.keymapset ;} ;}

# For all shells, display the getting started information.
# For virtual consoles and the serial/UART we'll get the info anyway,
# but not for SSH. This way we have the info on all channels.
clear
cat /etc/{issue,motd}
