Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some functionality and fixes from CDI's repository #3

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
16 changes: 8 additions & 8 deletions bin/admin.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,41 +48,41 @@ EOF
admin-add() {
local new_admin="$1"
dgl-user-exists "$new_admin" || \
abort-saying "Cannot find user $new_admin in dgl login db"
abort-saying "Cannot find user $new_admin in dgl login db."
if dgl-user-is-admin "$new_admin"; then
echo -e "User $new_admin is already an admin"
echo "User $new_admin is already an admin."
exit 0
fi

assert-running-as-root
dgl-user-make-admin "$new_admin"

if dgl-user-is-admin "$new_admin"; then
printf "%s" "\nDone, $new_admin is now a DGL admin.\n"
printf 'Done, %s is now a DGL admin.\n' "$new_admin"
exit 0
else
echo -e "Oops, couldn't make $new_admin a DGL admin.\n"
echo "Oops, couldn't make $new_admin a DGL admin."
exit 1
fi
}

admin-rm() {
local ex_admin="$1"
dgl-user-exists "$ex_admin" || \
abort-saying "Cannot find user $ex_admin in dgl login db"
abort-saying "Cannot find user $ex_admin in dgl login db."
if ! dgl-user-is-admin "$ex_admin"; then
echo -e "User $ex_admin is not an admin, nothing to do"
echo "User $ex_admin is not an admin, nothing to do."
exit 0
fi

assert-running-as-root
dgl-user-unmake-admin "$ex_admin"

if ! dgl-user-is-admin "$ex_admin"; then
printf "%s" "\nDone, $ex_admin is now a regular DGL non-admin user.\n"
printf 'Done, %s is now a regular DGL non-admin user.\n' "$ex_admin"
exit 0
else
echo -e "Oops, couldn't make $ex_admin a regular DGL non-admin user."
echo "Oops, couldn't make $ex_admin a regular DGL non-admin user."
exit 1
fi
}
Expand Down
95 changes: 95 additions & 0 deletions bin/bot.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#! /bin/bash

help <<EOF

$SCRIPT_NAME: Manages dgamelaunch bot users.

Usage: $SCRIPT_NAME ls List bot users
$SCRIPT_NAME add <user> Make <user> a bot
$SCRIPT_NAME rm <user> Make <user> a non-bot user.

EOF

assert-login-db-exists

SUBCOMMAND=$1
shift
[[ -z "$SUBCOMMAND" ]] && SUBCOMMAND="ls"

bot-ls() {
echo "Existing bot users:"
login-query <<EOF
SELECT username, email FROM dglusers
WHERE (flags & 64) = 64
ORDER BY username;
EOF
}


dgl-user-make-bot() {
local user="$1"
login-query <<EOF
UPDATE dglusers
SET flags = flags | 64
WHERE username='$user';
EOF
}

dgl-user-unmake-bot() {
local user="$1"
login-query <<EOF
UPDATE dglusers
SET flags = flags & ~64
WHERE username='$user';
EOF
}


bot-add() {
local new_bot="$1"
dgl-user-exists "$new_bot" || \
abort-saying "Cannot find user $new_bot in dgl login db."
if dgl-user-is-bot "$new_bot"; then
echo "User $new_bot is already an bot."
exit 0
fi

assert-running-as-root
dgl-user-make-bot "$new_bot"

if dgl-user-is-bot "$new_bot"; then
printf 'Done, %s is now a DGL bot.\n' "$new_bot"
exit 0
else
echo "Oops, couldn't make $new_bot a DGL bot."
exit 1
fi
}

bot-rm() {
local ex_bot="$1"
dgl-user-exists "$ex_bot" || \
abort-saying "Cannot find user $ex_bot in dgl login db."
if ! dgl-user-is-bot "$ex_bot"; then
echo "User $ex_bot is not an bot, nothing to do."
exit 0
fi

assert-running-as-root
dgl-user-unmake-bot "$ex_bot"

if ! dgl-user-is-bot "$ex_bot"; then
printf 'Done, %s is now a regular DGL non-bot user.\n' "$ex_bot"
exit 0
else
echo -e "Oops, couldn't make $ex_bot a regular DGL non-bot user."
exit 1
fi
}

case $SUBCOMMAND in
ls) bot-ls "$@" ;;
add) each-do bot-add "$@" ;;
rm) each-do bot-rm "$@" ;;
*) abort-saying "Unknown usage: $SCRIPT_NAME $SUBCOMMAND"
esac
4 changes: 2 additions & 2 deletions bin/passwd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ echo "Password hint for $USER: '$(password-hint "$USER")'"

if [[ "$UID" == "0" ]]; then
echo
read -s -p -r "Enter new password for $USER: " PASSWORD
read -s -r -p "Enter new password for $USER: " PASSWORD
echo
if [[ -z "$PASSWORD" ]]; then
abort-saying "Empty password"
fi
read -s -p -r "Retype password for $USER: " CONFIRM_PASSWORD
read -s -r -p "Retype password for $USER: " CONFIRM_PASSWORD
echo

if [[ "$PASSWORD" != "$CONFIRM_PASSWORD" ]]; then
Expand Down
1 change: 0 additions & 1 deletion bin/publish.pl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
[ 'banned_players.yml', "/crawl-master/webserver" ],
[ 'banned_players.txt', "/crawl-master/webserver" ],
[ 'chroot/data/menus/*.txt', "/dgldir/data/menus" ],
[ 'chroot/data/*.{rc,macro}', "/dgldir/data" ],
[ 'chroot/bin/*.sh', '/bin' ],
[ 'chroot/sbin/*.sh', '/sbin' ]);

Expand Down
6 changes: 6 additions & 0 deletions bin/update-bot-stable.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd "$DGL_CONF_HOME/crawl-build"

# shellcheck source=crawl-build/update-crawl-bot-stable-build.sh
source ./update-crawl-bot-stable-build.sh
6 changes: 6 additions & 0 deletions bin/update-bot-trunk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd "$DGL_CONF_HOME/crawl-build"

# shellcheck source=crawl-build/update-crawl-bot-trunk-build.sh
source ./update-crawl-bot-trunk-build.sh
6 changes: 6 additions & 0 deletions bin/update-experimental.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

cd "$DGL_CONF_HOME/crawl-build"

# shellcheck source=crawl-build/update-crawl-experimental-build.sh
source ./update-crawl-experimental-build.sh
95 changes: 95 additions & 0 deletions bin/wizard.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#! /bin/bash

help <<EOF

$SCRIPT_NAME: Manages dgamelaunch wizard users.

Usage: $SCRIPT_NAME ls List wizard users
$SCRIPT_NAME add <user> Make <user> a wizard
$SCRIPT_NAME rm <user> Make <user> a non-wizard user.

EOF

assert-login-db-exists

SUBCOMMAND=$1
shift
[[ -z "$SUBCOMMAND" ]] && SUBCOMMAND="ls"

wizard-ls() {
echo "Existing wizard users:"
login-query <<EOF
SELECT username, email FROM dglusers
WHERE (flags & 32) = 32
ORDER BY username;
EOF
}


dgl-user-make-wizard() {
local user="$1"
login-query <<EOF
UPDATE dglusers
SET flags = flags | 32
WHERE username='$user';
EOF
}

dgl-user-unmake-wizard() {
local user="$1"
login-query <<EOF
UPDATE dglusers
SET flags = flags & ~32
WHERE username='$user';
EOF
}


wizard-add() {
local new_wizard="$1"
dgl-user-exists "$new_wizard" || \
abort-saying "Cannot find user $new_wizard in dgl login db."
if dgl-user-is-wizard "$new_wizard"; then
echo "User $new_wizard is already an wizard."
exit 0
fi

assert-running-as-root
dgl-user-make-wizard "$new_wizard"

if dgl-user-is-wizard "$new_wizard"; then
printf 'Done, %s is now a DGL wizard.\n' "$new_wizard"
exit 0
else
echo "Oops, couldn't make $new_wizard a DGL wizard."
exit 1
fi
}

wizard-rm() {
local ex_wizard="$1"
dgl-user-exists "$ex_wizard" || \
abort-saying "Cannot find user $ex_wizard in dgl login db."
if ! dgl-user-is-wizard "$ex_wizard"; then
echo "User $ex_wizard is not an wizard, nothing to do."
exit 0
fi

assert-running-as-root
dgl-user-unmake-wizard "$ex_wizard"

if ! dgl-user-is-wizard "$ex_wizard"; then
printf 'Done, %s is now a regular DGL non-wizard user.\n' "$ex_wizard"
exit 0
else
echo -e "Oops, couldn't make $ex_wizard a regular DGL non-wizard user."
exit 1
fi
}

case $SUBCOMMAND in
ls) wizard-ls "$@" ;;
add) each-do wizard-add "$@" ;;
rm) each-do wizard-rm "$@" ;;
*) abort-saying "Unknown usage: $SCRIPT_NAME $SUBCOMMAND"
esac
Loading