Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
NoCloud
docker
Nextcloud
Commits
33251741
Commit
33251741
authored
4 years ago
by
Bruno BEAUFILS
Browse files
Options
Downloads
Patches
Plain Diff
Added user add helper (via API call)
parent
49bffdc9
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
nc-useradd.sh
+57
-0
57 additions, 0 deletions
nc-useradd.sh
with
57 additions
and
0 deletions
nc-useradd.sh
0 → 100755
+
57
−
0
View file @
33251741
#!/bin/bash
# Création d'utilisateur dans Nextcloud
#
# usage: nc-useradd.sh [OPTIONS] USERID DISPLAYNAME EMAIL [GROUPE...]
#
# OPTIONS
# -h, --help affiche ce message d'aide
#
# Créer un utilisateur dans l'instance Nextcloud via un appel à l'API
# par curl pour ne pas avoir à spécifier de mot de passe.
#
# Les variables d'environnement suivantes doivent être fixées :
#
# - NEXTCLOUD_HOST : le nom de l'instance Nextcloud
# - NEXTCLOUD_ADMIN_USER : l'id d'un utilisateur admin
# - NEXTCLOUD_ADMIN_PASSWORD : le mot de passe de l'utilisateur admin
#
# Penser à protéger les espaces avec des quotes si nécessaires
# (notamment pour DISPLAYNAME).
#
# Copyright (C) 2021 Bruno BEAUFILS <bruno@boulgour.com>
#
# This software comes with ABSOLUTELY NO WARRANTY.
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation in its version 2.
# See the README or COPYING file for details.
_doc
()
{
sed
-n
'2,/^$/ { s/^ *#// ; s/^ //g ; t e ; d ; :e p }'
<
$0
;
}
_die
()
{
echo
"
${
0
##*/
}
: error:
$*
"
1>&2
;
exit
1
;
}
test
"x
$1
"
=
"x-h"
-o
"x
$1
"
=
"x--help"
&&
_doc
&&
exit
test
-z
$NEXTCLOUD_HOST
&&
_die
"NEXTCLOUD_HOST est vide"
test
-z
$NEXTCLOUD_ADMIN_USER
&&
_die
"NEXTCLOUD_ADMIN_USER est vide"
test
-z
$NEXTCLOUD_ADMIN_PASSWORD
&&
_die
"NEXTCLOUD_ADMIN_PASSWORD est vide"
test
$#
-lt
3
&&
_die
"manque des paramètres. Essayer l'option -h"
which curl 1>/dev/null 2>&1
||
_die
"curl inacessible"
userid
=
"
$1
"
displayName
=
"
$2
"
email
=
"
$3
"
shift
3
for
g
in
"
$@
"
do
groups_args
=
"
$groups_args
-d groups[]=
\"
$g
\"
"
done
eval
curl
-X
POST https://
${
NEXTCLOUD_ADMIN_USER
}
:
${
NEXTCLOUD_ADMIN_PASSWORD
}
@
${
NEXTCLOUD_HOST
}
/ocs/v1.php/cloud/users
\
-d
userid
=
\"
$userid
\"
\
-d
displayName
=
\"
$displayName
\"
\
-d
email
=
\"
$email
\"
\
$groups_args
\
-d
language
=
\"
fr
\"
\
--header
\"
OCS-APIRequest:
true
\"
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment