#!/bin/bash

##########################################################
# Copyright (c) 2001-2026 Alexey Kuryakin daqgroup@mail.ru
##########################################################

###########################################################
## Utility to check sudoit password.
###########################################################

###########################################################
source $(crwkit which crwlib_base.sh); # Use base library #
source $(crwkit which crwlib_file.sh); # Use file library #
###########################################################

function do_version(){
 echo "$scriptname version 1.0"; return 0;
};

function do_help(){
 do_version;
 echo "Copyright (c) 2026 Alexey Kuryakin daqgroup@mail.ru";
 echo "Utility to check (verify) sudoit password status.";
 echo "Usage: $scriptname [--version|--help|--gui]";
};

function main(){
 local -i ecode=0;
 local -i optgui=0;
 case $1 in
  --version)     do_version; return 0; ;;
  --help)        do_help; return 0; ;;
  -g|-gui|--gui) let optgui=1; ;;
  *)             ;;
 esac;
 sudo --reset-timestamp;
 if [[ "x$(unix sudoit id -u)" = "x0" ]]; then
  local tit="$(langstr ru "Результат проверки …" en "Checking result …")";
  local msg="$(langstr ru "<b>ПАРОЛЬ</b> <b><span color=\"blue\">sudoit</span></b> <b><span color=\"green\">РАБОТАЕТ</span></b>!" en "sudoit <b>PASSWORD</b> is <b><span color=\"green\">WORKING</span></b>!")";
  echo "sudoit: succeed";
 else
  local tit="$(langstr ru "Результат проверки …" en "Checking result …")";
  local msg="$(langstr ru "<b>ПАРОЛЬ</b> <b><span color=\"blue\">sudoit</span></b> <b><span color=\"red\">НЕ РАБОТАЕТ</span></b>!" en "<b><span color=\"blue\">sudoit</span></b> <b>PASSWORD</b> is <b><span color=\"red\">NOT WORKING</span></b>!")";
  echo "sudoit: refused";
  let ecode=1;
 fi;
 if [[ $optgui -ne 0 ]]; then
  unix grun zenity --info --title "$tit" --text "$msg" --modal --timeout 300 > /dev/null;
 fi;
 return $ecode;
};

main "$@";

##############
## END OF FILE
##############
