# This is a default template for a post-install scriptlet.
# Uncomment only required functions and remove any functions
# you don't need (and this header).

## arg 1:  the new package version
#pre_install() {
	# do something here
#}

## arg 1:  the new package version
post_install() {

#descobrir o nome do usuario
who=$(who | awk '{ print $1 }' | head -n 1)

#adicinar usuario ao grupo realtime e video
if [ -n "$(getent group | grep realtime)" ];then
    usermod -a -G realtime $who
else
echo '
users=$(ls /home)
for i in $users; do 
	if [ -z "$(groups $i | grep realtime)" ]; then
		usermod -a -G realtime $i
	fi
done' | tee -a /usr/bin/big-first-boot
fi
usermod -a -G video $who
usermod -a -G audio $who

#baixar a latencia das placas de audio PCI internas
for i in $(lspci | grep -i audio | awk '{print $1}'); do setpci -v -s $i latency_timer=ff; done

#PAM-enabled login
if [ -z "$(grep pam_limits.so /etc/pam.d/crond)" ]; then
    echo "session   required    pam_limits.so" | tee -a /etc/pam.d/crond
fi
if [ -z "$(grep pam_limits.so /etc/pam.d/login)" ]; then
    echo "session   required    pam_limits.so" | tee -a /etc/pam.d/login
fi
if [ -z "$(grep pam_limits.so /etc/pam.d/polkit-1)" ]; then
    echo "session   required    pam_limits.so" | tee -a /etc/pam.d/polkit-1
fi
if [ -z "$(grep pam_limits.so /etc/pam.d/system-auth)" ]; then
    echo "session   required    pam_limits.so" | tee -a /etc/pam.d/system-auth
fi
if [ -z "$(grep pam_limits.so /etc/pam.d/system-services)" ]; then
    echo "session   required    pam_limits.so" | tee -a /etc/pam.d/system-services
fi

systemctl start big-audio-config.service
udevadm control --reload-rules
udevadm trigger

}


## arg 1:  the new package version
## arg 2:  the old package version
#pre_upgrade() {
	# do something here
#}

## arg 1:  the new package version
## arg 2:  the old package version
#post_upgrade() {
	# do something here
#}

## arg 1:  the old package version
#pre_remove() {
	# do something here
#}

## arg 1:  the old package version
#post_remove() {
	# do something here
#}
