#!/usr/bin/bash

GOSTPROFILE="custom/gost-yescrypt"
GOSTPROFILENAME="gost-yescrypt"

# Проверяем, что скрипт запущен с повышенными привилегиями
if [ "$EUID" -ne 0 ]; then
  echo "Please run as root"
  exit 1
fi

# Проверяем, что вывод команды не пуст
if /usr/bin/authselect list | /usr/bin/grep -q "$GOSTPROFILE"; then
  echo "$GOSTPROFILENAME already exists"
else
  /usr/bin/authselect create-profile "$GOSTPROFILENAME" --base-on=sssd
  /usr/bin/sed -i 's/\byescrypt\b/gost_yescrypt/' /etc/authselect/custom/"$GOSTPROFILENAME"/password-auth
  /usr/bin/sed -i 's/\byescrypt\b/gost_yescrypt/' /etc/authselect/custom/"$GOSTPROFILENAME"/system-auth
fi

/usr/bin/authselect "select" $GOSTPROFILE with-fingerprint with-silent-lastlog
/usr/bin/authselect apply-changes

exit 0
