#!/bin/bash
#
# Written by Michel Decima
# Copyright (C) 2020 Orange
#

(( EUID == 0 )) || { echo >&2 "Not root." ; exit 1 ; }

update-alternatives --set gdm-smartcard \
    /etc/pam.d/gdm-smartcard-pkcs11-exclusive \
    || { echo >&2 "Cannot switch to PKI login (GDM too old?)" ; exit 1 ; }

sed -Ei 's/(enable-smartcard-authentication)=.*/\1=true/' \
    /etc/dconf/db/gdm.d/03-smartcard
dconf update

cat << EOF
Please restart desktop manager with command:
  systemctl restart gdm3
EOF

