File gnome-keyring-pam-setup of Package osc

#!/bin/bash

ACTION=

if [[ $1 != 'install' && $1 != 'uninstall' ]]; then 
  echo `basename $0`" <install|uninstall>"
  exit 1
fi

ACTION=$1
FLAVOR=
PAMLIBDIR=
if [[ `uname` = 'Linux' ]]; then
  PAMLIBDIR=/usr/lib64/security
  if grep -q SUSE /etc/issue; then
    FLAVOR=suse
  fi
  if grep -q "rhel" /etc/os-release; then
    FLAVOR=rhel
    . /etc/os-release
    case ${VERSION_ID} in
      7	) SYSTEM_AUTH='/etc/pam.d/system-auth-ac'
        ;;
      * ) SYSTEM_AUTH='/etc/pam.d/system-auth'
        ;; 
    esac
  fi
fi

if [[ $FLAVOR = "" ]]; then
  echo "OS/Platform cannot be identified, exiting"
  exit 1
fi

if [[ $ACTION = "install" ]]; then
  case $FLAVOR in
    suse)
      /usr/bin/egrep -L 'auth.*pam_gnome_keyring.so' /etc/pam.d/common-auth-pc >/dev/null 2>&1
      if [ $? != 0 ];  then
        /usr/bin/perl -i -pe '
          s!(auth\s+required\s+pam_unix2\.so.*)
           !$1\nauth\toptional\t'$PAMLIBDIR'/pam_gnome_keyring.so only_if=sshd,login,su-l,su auto_start!gx;
        ' /etc/pam.d/common-auth-pc      
      fi
      /usr/bin/egrep -L 'session.*pam_gnome_keyring.so' /etc/pam.d/common-session-pc >/dev/null 2>&1
      if [ $? != 0 ];  then
        /usr/bin/perl -i -pe '
          s!(session\s+required\s+pam_unix2\.so.*)
           !$1\nsession\toptional\t\t'$PAMLIBDIR'/pam_gnome_keyring.so only_if=sshd,login,su-l,su auto_start!gx;
        ' /etc/pam.d/common-session-pc
      fi
    ;;
    rhel)
      /usr/bin/egrep -L 'auth.*pam_gnome_keyring.so' /etc/pam.d/system-auth-ac >/dev/null 2>&1
      if [ $? != 0 ];  then
        /usr/bin/perl -i -pe '
          s!(auth\s+)\S+(\s+pam_deny\.so.*)
           !auth        optional\tpam_gnome_keyring.so only_if=login,su-l,su auto_start\n$1        required\t$2!gx;
        ' ${SYSTEM_AUTH}
      fi

      /usr/bin/egrep -L 'auth.*pam_gnome_keyring.so' /etc/pam.d/sshd >/dev/null 2>&1
      if [ $? != 0 ];  then
        /usr/bin/perl -i -pe '
          s!^(auth\s+\S+\s+password-auth.*)
           !auth        optional\tpam_gnome_keyring.so auto_start\n$1!gx;
        ' /etc/pam.d/sshd
      fi
      /usr/bin/egrep -L 'session.*pam_gnome_keyring.so' /etc/pam.d/system-auth-ac >/dev/null 2>&1
      if [ $? != 0 ];  then
          echo -e "session        optional\tpam_gnome_keyring.so only_if=login,su-l,su auto_start" >> \
         ${SYSTEM_AUTH}
      fi
      /usr/bin/egrep -L 'session.*pam_gnome_keyring.so' /etc/pam.d/sshd >/dev/null 2>&1
      if [ $? != 0 ];  then
          /usr/bin/perl -i -pe '
            s!^(session\s+include\s+password-auth.*)
             !session        optional\tpam_gnome_keyring.so auto_start\n$1!gx;
         ' /etc/pam.d/sshd
      fi
    ;;
  esac
else
  case $FLAVOR in
    suse)
      /usr/bin/perl -i -pe '
        s!^\s*(auth|session)\s+optional\s+\S*?pam_gnome_keyring.so.*\n!!sg
          ' /etc/pam.d/common-auth-pc /etc/pam.d/common-session-pc
    ;;
    rhel)
      /usr/bin/perl -i -pe '
        s!^\s*(auth|session)\s+optional\s+\S*?pam_gnome_keyring.so.*\n!!sg
          ' ${SYSTEM_AUTH} /etc/pam.d/sshd
    ;;
  esac
fi
openSUSE Build Service is sponsored by