obosdi-pkg/config/accounts/sudoers/menu

72 lines
1.9 KiB
Text
Raw Permalink Normal View History

2015-08-20 14:37:06 -06:00
#!/bin/bash
. ./lib
options=()
options+=("Add sudoer" "")
options+=("Edit sudoer" "")
options+=("Delete sudoer" "")
options+=("" "")
options+=("Edit /etc/sudoers" "")
defaultitem="Add sudoer"
2022-11-10 14:27:23 -07:00
sel=$(dialog --backtitle "$apptitle" --title "Sudoers Menu :" --default-item "$defaultitem" --cancel-button "Back" --menu "" 0 0 0 \
2015-08-20 14:37:06 -06:00
"${options[@]}" \
3>&1 1>&2 2>&3)
if [ ! "$?" = "0" ]; then
exit 1
fi
sed -i "/^defaultitem=/c\defaultitem=\"$sel\"" $0
case $sel in
'Add sudoer')
users=$(awk -F: '{if ($3 >= 1000 && $3 <= 5000) { print $1 } }' /etc/passwd)
2015-08-20 14:37:06 -06:00
userlist=()
for itm in $users; do
userlist+=("$itm" "")
done
2022-11-10 14:27:23 -07:00
sel=$(dialog --backtitle "$apptitle" --title "Add sudoer :" --cancel-button "Cancel" --menu "" 0 0 0 \
2015-08-20 14:37:06 -06:00
"${userlist[@]}" \
3>&1 1>&2 2>&3)
if [ "$?" = "0" ]; then
echo "$sel ALL=(ALL) ALL" > /etc/sudoers.d/$sel
fi
;;
'Edit sudoer')
sudoers=$(ls /etc/sudoers.d)
sudoerlist=()
for itm in $sudoers; do
if [ ! "$itm" = "aurbuilder" ]; then
sudoerlist+=("$itm" "")
fi
2015-08-20 14:37:06 -06:00
done
2022-11-10 14:27:23 -07:00
sel=$(dialog --backtitle "$apptitle" --title "Edit sudoer :" --cancel-button "Cancel" --menu "" 0 0 0 \
2015-08-20 14:37:06 -06:00
"${sudoerlist[@]}" \
3>&1 1>&2 2>&3)
if [ "$?" = "0" ]; then
2018-09-15 19:36:14 -06:00
editfile /etc/sudoers.d/$sel
2015-08-20 14:37:06 -06:00
fi
;;
'Delete sudoer')
sudoers=$(ls /etc/sudoers.d)
sudoerlist=()
for itm in $sudoers; do
if [ ! "$itm" = "aurbuilder" ]; then
sudoerlist+=("$itm" "")
fi
2015-08-20 14:37:06 -06:00
done
2022-11-10 14:27:23 -07:00
sel=$(dialog --backtitle "$apptitle" --title "Delete sudoer :" --cancel-button "Cancel" --menu "" 0 0 0 \
2015-08-20 14:37:06 -06:00
"${sudoerlist[@]}" \
3>&1 1>&2 2>&3)
if [ "$?" = "0" ]; then
if (confirm "Remove $sel from sudoers"); then
rm /etc/sudoers.d/$sel
fi
fi
;;
'Edit /etc/sudoers')
2018-09-15 19:36:14 -06:00
editfile /etc/sudoers
2015-08-20 14:37:06 -06:00
;;
esac
exit 0