Make usergen a bit more useful
So far, usergen printed a JSON object over standard output that had to be manually copied into db.json. Now, this step is done automatically, thanks to jq(1). OTOH, user directory is now also created by usergen.
This commit is contained in:
parent
27b8a69718
commit
f6fd20fdc4
|
@ -43,6 +43,7 @@ to `slcl`. If required, encryption should be done before uploading e.g.: using
|
|||
- [`dynstr`](https://gitea.privatedns.org/xavi92/dynstr)
|
||||
(provided as a `git` submodule).
|
||||
- `xxd` (for [`usergen`](usergen) only).
|
||||
- `jq` (for [`usergen`](usergen) only).
|
||||
- CMake (optional).
|
||||
|
||||
### Ubuntu / Debian
|
||||
|
|
46
usergen
46
usergen
|
@ -2,8 +2,29 @@
|
|||
|
||||
set -e
|
||||
|
||||
usage()
|
||||
{
|
||||
echo "$0 <dir>"
|
||||
}
|
||||
|
||||
if [ $# != 1 ]; then
|
||||
usage >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DIR=$1
|
||||
|
||||
echo Username: >&2
|
||||
read -r USER
|
||||
|
||||
DB="$DIR/db.json"
|
||||
|
||||
if jq '.users[].name' "$DB" | grep -q $USER
|
||||
then
|
||||
echo User $USER already in $DB >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo Password: >&2
|
||||
read -r PWD
|
||||
echo "Quota, in MiB (leave empty for unlimited quota):" >&2
|
||||
|
@ -23,12 +44,23 @@ do
|
|||
done
|
||||
|
||||
echo >&2
|
||||
cat <<-EOF
|
||||
TMP=$(mktemp)
|
||||
|
||||
cleanup()
|
||||
{
|
||||
"name": "$USER",
|
||||
"password": "$PWD",
|
||||
"salt": "$SALT",
|
||||
"key": "$KEY",
|
||||
"quota": "$QUOTA"
|
||||
rm -f $TMP
|
||||
}
|
||||
EOF
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
jq ".users += [
|
||||
{
|
||||
\"name\": \"$USER\",
|
||||
\"password\": \"$PWD\",
|
||||
\"salt\": \"$SALT\",
|
||||
\"key\": \"$KEY\",
|
||||
\"quota\": \"$QUOTA\"
|
||||
}]" "$DB" > $TMP
|
||||
|
||||
mv $TMP "$DB"
|
||||
mkdir "$DIR/user/$USER"
|
||||
|
|
Loading…
Reference in New Issue