feat: run_as_root / run_as_steam

This commit is contained in:
GenZmeY 2020-08-07 13:51:21 +03:00
parent 36f1d5514d
commit efb4094d13
28 changed files with 292 additions and 16 deletions

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: ban list
{
include "$LibDir/ban.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: ban list
{
include "$LibDir/ban.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/ban.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/ban.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/game.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/game.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/game.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/game.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
true
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/instance.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: Instance[s]
{
include "$LibDir/maprotate.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main () # $*: Instance[s]
{
include "$LibDir/maprotate.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/password.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/password.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/workshop.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/workshop.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
false
}
function cmd_main ()
{
include "$LibDir/workshop.lib"

View File

@ -34,6 +34,16 @@ function cmd_help ()
echo "TODO: description"
}
function cmd_need_superuser ()
{
false
}
function cmd_need_steamuser ()
{
true
}
function cmd_main ()
{
include "$LibDir/workshop.lib"

View File

@ -37,19 +37,16 @@ function include () # $1: Lib
function is_help () # $1: Arg
{
echo "$1" | grep -Piqo '^(-h|--help|help)$'
return $?
}
function is_version () # $1: Arg
{
echo "$1" | grep -Piqo '^(-v|--version|version)$'
return $?
}
function function_exists () # $1: function name
{
type "$1" &> /dev/null
return $?
}
function indent () # $1: Level
@ -63,21 +60,21 @@ function indent () # $1: Level
function groups_list ()
{
find "$GrpDir" \
-mindepth 1 \
-maxdepth 1 \
-type d \
-printf "%f\n" | \
find "$GrpDir" \
-mindepth 1 \
-maxdepth 1 \
-type d \
-printf "%f\n" | \
sort
}
function commands_list () # $1: Command group
{
find "$GrpDir/$1" \
-mindepth 1 \
-maxdepth 1 \
-type f \
-printf "%f\n" | \
find "$GrpDir/$1" \
-mindepth 1 \
-maxdepth 1 \
-type f \
-printf "%f\n" | \
sort
}
@ -148,7 +145,13 @@ elif [[ -d "$GroupPathname" ]]; then
fi
else
if function_exists "cmd_main"; then
cmd_main "$@"
if function_exists "cmd_need_superuser" && cmd_need_superuser; then
run_as_root "$ScriptFullname" "$Group" "$Command" "$@"
elif function_exists "cmd_need_steamuser" && cmd_need_steamuser; then
run_as_steamuser "$ScriptFullname" "$Group" "$Command" "$@"
else
cmd_main "$@"
fi
else
echo "No implementation for the command $Command"
fi

View File

@ -19,6 +19,30 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
function run_as_steamuser () # $@: command
{
include /etc/steamcmd/steamcmd.conf
if [[ "$USER" == "$SteamUser" ]]; then
"$@"
elif [[ -n $(groups "$USER" | grep -Fo 'wheel') ]] || [[ "$EUID" -eq 0 ]]; then
sudo -u "$SteamUser" "$@"
else
echo "You must be a $SteamUser, root or sudo-user to run this command."
fi
}
function run_as_root () # $@: command
{
if [[ "$EUID" -eq 0 ]]; then
"$@"
elif [[ -n $(groups "$USER" | grep -Fo 'wheel') ]]; then
sudo "$@"
else
echo "You must be root or sudo-user to run this command."
fi
}
InstallDir=":DEFINE_PREFIX:/games/kf2-srv${KF2POSTFIX}"
AppBin="$InstallDir/Binaries/Win64/KFGameSteamServer.bin.x86_64"

3
TODO
View File

@ -1,9 +1,8 @@
- selinux
- sudo for steamuser
- kick by level
- split the script into separate files
- man pages
- english help
- write help pages for each command
- check ban EGS players (mb bugs)
- ban history
- temporary ban