#!/bin/bash

. ${TOOLKIT}-functions.sh

# 2026-01-03
#  all the current managed distros now uses includedir feature
#  so we will "unpatch" the sudoers file, and install the
#  equivalend in /etc/sudoers.d directory
#
#  note: this file moved from run-pre to run-install
#
##orig=/etc/sudoers
##outfile=sudoers.tmp
##cp $orig $outfile || exit $?
##
## if needed, add 'kusa' group with admin privileges
##
#file=`filepath sudoers.addon` && {
	#patchfile "patch-ku-sudoers-20120323" $outfile $file || exit $?
#}
tag="#patch-ku-sudoers-20120323"
target="/etc/sudoers"
file="sudoers.tmp"

cp -a "$target" "$file"

grep -q "^$tag$" $file && {
	echo -n "  SUDO CHANGES: unpatch $file for addition '$tag' ... "
	sed -e "/^$tag$/,+4d" $file >$file.new
	rm $file
	mv $file.new $file
	echo "ok"
}

# also unpatch this snippet (base module is already installing proper
# file to /etc/sudoers.d, if needed)
#
tag1="added by kusa on "
tag2="safe_poweroff"

grep -q "$tag2" $file && {
	echo -n "  SUDO CHANGES: unpatch $file for addition '$tag2' ... "
	sed -e "/$tag1/,/$tag2/d" $file >$file.new
	rm $file
	mv $file.new $file
	echo "ok"
}

installfile $file $target root:root 0440


# remove old stuff
#
uninstallfiles /etc/sudoers.d/ku-kusa-group

exit 0
