#!/bin/bash
#-------------------------------------------------------------------------------
# charon_menu_aksusbd
#-------------------------------------------------------------------------------
# Copyright (C) 2013-2023 STROMASYS.
# All rights reserved.
# Products: AXP/VAX + PAR
#-------------------------------------------------------------------------------
#
VERSION=2.0

. /opt/charon/utils/charon_common
. /opt/charon/utils/charon_common_menu

while test 1
do
  display_header "License driver management (aksusbd)"
  echo
  if test $(id -u) -ne 0
  then
    echo "[31mERROR[0m: must be root !"
    Press_Enter
    echo
    break
  fi

  if test -x /usr/sbin/aksusbd
  then
    display_licfound full

    tput bold
    echo "Driver service status:"
    tput sgr0
    /usr/bin/systemctl --no-pager --lines 0 status aksusbd
    /usr/bin/systemctl -q is-enabled aksusbd
    if test $? -ne 0
    then
      tput bold
      echo "Service is not enabled. Enabling it now..."
      tput sgr0
      /usr/bin/systemctl enable aksusbd
    fi
    echo

    while test 1
    do
      echo -n "Do you want to restart the service (y/n) (q to quit) ? "
      read ANS
      case "${ANS}"
      in
        y|Y)
          /usr/bin/systemctl restart aksusbd
          break
          ;;
        n|N|q|Q)
          break 2
          ;;
        *)
          break
          ;;
      esac
    done
  else
    echo
    echo "${FGORANGE}WARNING[0m: aksusbd is not installed (HASP license) !"
    echo
    Press_Enter
    break
  fi
done

exit
