obosdi-pkg/config/accounts/sudoers/menu
2022-11-10 22:27:23 +01:00

71 lines
1.9 KiB
Bash

#!/bin/bash
. ./lib
options=()
options+=("Add sudoer" "")
options+=("Edit sudoer" "")
options+=("Delete sudoer" "")
options+=("" "")
options+=("Edit /etc/sudoers" "")
defaultitem="Add sudoer"
sel=$(dialog --backtitle "$apptitle" --title "Sudoers Menu :" --default-item "$defaultitem" --cancel-button "Back" --menu "" 0 0 0 \
"${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)
userlist=()
for itm in $users; do
userlist+=("$itm" "")
done
sel=$(dialog --backtitle "$apptitle" --title "Add sudoer :" --cancel-button "Cancel" --menu "" 0 0 0 \
"${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
done
sel=$(dialog --backtitle "$apptitle" --title "Edit sudoer :" --cancel-button "Cancel" --menu "" 0 0 0 \
"${sudoerlist[@]}" \
3>&1 1>&2 2>&3)
if [ "$?" = "0" ]; then
editfile /etc/sudoers.d/$sel
fi
;;
'Delete sudoer')
sudoers=$(ls /etc/sudoers.d)
sudoerlist=()
for itm in $sudoers; do
if [ ! "$itm" = "aurbuilder" ]; then
sudoerlist+=("$itm" "")
fi
done
sel=$(dialog --backtitle "$apptitle" --title "Delete sudoer :" --cancel-button "Cancel" --menu "" 0 0 0 \
"${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')
editfile /etc/sudoers
;;
esac
exit 0