vpanel-stack/bin/vpanel-verify-access.sh
Matthew Saunders Brown fd94a4e3c4 initial commit
2022-07-01 15:24:26 -07:00

59 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
#
# vpanel-stack
# https://git.stack-source.com/msb/vpanel-stack
# Copyright (c) 2022 Matthew Saunders Brown <matthewsaundersbrown@gmail.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# first switch to root
if [ "$USER" != "root" ]; then
exec sudo -u root $0 $@
fi
help()
{
thisfilename=$(basename -- "$0")
echo "Check if specified user has vpanel sudo access."
echo ""
echo "usage: $thisfilename -u <username> [-h]"
echo ""
echo " -u <username> Username to check."
echo " -h Print this help."
}
while getopts "hu:" opt ; do
case "${opt}" in
h ) # display help and exit
help
exit
;;
u ) # username
username=${OPTARG,,}
;;
\? )
echo "Invalid option: $OPTARG"
exit 1
;;
: )
echo "Invalid option: $OPTARG requires an argument"
exit 1
;;
esac
done
# check for username
if [[ -z $username ]]; then
echo "username is required"
exit 1
fi
# check sudo rights
if /usr/bin/sudo -l -U $username vpanel-verify-access.sh >/dev/null; then
echo TRUE
exit 0
else
echo FALSE
exit 1
fi