I agree with your point Jerry. It is certainly important to keep this in perspective. I failed to realize that the command is being executed without privileges because on my test VM I'm running the cron as root. Obviously, running it as a root cronjob is not ideal because this will make it a global setting for all admins... Furthermore, assuming that multiple admins login to the machine, they may want to have their own notification preferences and your solution, at that point, is the one that makes the most sense :) :
Code:
#! /bin/sh
# Postinst script for Lite Update Notify
set -e
IDUSER=$(grep -Po '^sudo.+:\K.*$' /etc/group)
if [ `id -u $IDUSER 2>/dev/null || echo -1` -ge 0 ]; then
echo "$IDUSER ALL=NOPASSWD: /usr/local/sbin/updatenotify" >> /etc/sudoers
else
echo "Script failed..."
fi
But I recommend we use
/etc/sudoers.d instead of modifying the default /etc/sudoers file for multiple reasons.
I think this can be done as we set the cronjob because we have admin privileges at that point. Thus, we can create or remove each sudoer under
/etc/sudoers.d using the $LUNUSER variable the same way we are using it to create the cron job.
Throw at me what you think about that.
https://unlockforus.com
Sorry for seeming stupid and preferring Linux - I just don't know any better.