27 lines
587 B
Bash
Executable File
27 lines
587 B
Bash
Executable File
#!/bin/sh
|
|
|
|
[ -z $1 ] && echo "Usage: $0 <username>" && exit 1
|
|
|
|
USERNAME=$1
|
|
|
|
if [ "$(systemctl is-active mongod)" != "active" ]; then
|
|
echo "ERROR: mongoDB service is not running"
|
|
exit 1
|
|
fi
|
|
|
|
|
|
EXISTS=$(docker-compose exec -T mongo mongo main --quiet --eval "db.users.find({ username: '$USERNAME' })")
|
|
|
|
if [ -z "$EXISTS" ]; then
|
|
echo "ERROR: user does not exists!"
|
|
exit 1
|
|
fi
|
|
|
|
REMOVED=`mongo main --quiet --eval "db.users.remove({username: '$USERNAME'}).nRemoved"`
|
|
|
|
if [ $REMOVED -gt 0 ]; then
|
|
echo "User deleted"
|
|
else
|
|
echo "ERROR: Failed to delete user"
|
|
fi
|