batch add users to nextcloud on docker with csvBatch upload users to nextcloud on docker with bash csvManaging a CSV of users and permissionsCSV lookup problem solved with CoffeeScriptCSV manipulation with PythonUpdate record with CSVSearching a CSV with PHPGoodgame Empire coin collector with random offsets in (almost-POSIX) BashParse one table out of CSV with multiple titled tables with the Python CSV moduleBool function in PHP to check if you run the script inside dockerBatch upload users to nextcloud on docker with bash csvEditing system files in Linux (as root) with GUI and CLI text editors
Email Account under attack (really) - anything I can do?
"listening to me about as much as you're listening to this pole here"
How is it possible for user's password to be changed after storage was encrypted? (on OS X, Android)
Was there ever an axiom rendered a theorem?
Domain expired, GoDaddy holds it and is asking more money
A poker game description that does not feel gimmicky
Pristine Bit Checking
Is a vector space a subspace?
What does it exactly mean if a random variable follows a distribution
Why did the Germans forbid the possession of pet pigeons in Rostov-on-Don in 1941?
Lied on resume at previous job
Is domain driven design an anti-SQL pattern?
How to make particles emit from certain parts of a 3D object?
Why do UK politicians seemingly ignore opinion polls on Brexit?
Should the British be getting ready for a no-deal Brexit?
How to make payment on the internet without leaving a money trail?
If a centaur druid Wild Shapes into a Giant Elk, do their Charge features stack?
Information to fellow intern about hiring?
Manga about a female worker who got dragged into another world together with this high school girl and she was just told she's not needed anymore
Copycat chess is back
Can a planet have a different gravitational pull depending on its location in orbit around its sun?
Add an angle to a sphere
Shall I use personal or official e-mail account when registering to external websites for work purpose?
What causes the sudden spool-up sound from an F-16 when enabling afterburner?
batch add users to nextcloud on docker with csv
Batch upload users to nextcloud on docker with bash csvManaging a CSV of users and permissionsCSV lookup problem solved with CoffeeScriptCSV manipulation with PythonUpdate record with CSVSearching a CSV with PHPGoodgame Empire coin collector with random offsets in (almost-POSIX) BashParse one table out of CSV with multiple titled tables with the Python CSV moduleBool function in PHP to check if you run the script inside dockerBatch upload users to nextcloud on docker with bash csvEditing system files in Linux (as root) with GUI and CLI text editors
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
$begingroup$
I have a working script that will batch add users to an instance of nextcloud running on top of docker. This version is the result of changes made after asking this question.
I guess I'm looking for a re-review to ensure that I haven't missed anything. I'm also interested if there are areas where I could make things better in terms of readability, performance, security, etc. You're the reviewer. My code is your oyster.
#!/bin/sh
set -eu
# Handle printing errors
die ()
printf '%sn' "$1" >&2
exit 1
message ()
printf '%sn' "$1" >&2
usage ()
ENVIRONMENT VARIABLES
OC_PASS
Sets the password for users added. The OC_PASS environment variable
is required.
EXAMPLES
The command:
batch_up.sh foobar.csv
Will add the users from foobar.csv. Users will be given the password
in the OC_PASS environment variable.
The command:
batch_up.sh <<< "jack,Jack Frost,users,jack.frost@gmail.com"
Will add the user jack, set his display name to Jack Frost, add him
to the group users, and set his email to jack.frost@gmail.com.
The command:
echo "jack,Jack Frost,users,jack.frost@gmail.com"
# Set verbosity. Default is silent.
verbose=-q
# flags
while [ $# -gt 0 ]
do
case $1 in
-h|-?|--help)
usage # Display a usage synopsis.
exit
;;
-v|-vv|-vvv|--verbose)
verbose=$1
;;
-d|--delimiter)
if [ $# -gt 1 ]
then
case $2 in
,|.|;|:||)
delimiter=$2
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
else
die 'Error: "--delimiter requires a non-empty option argument.'
fi
;;
--delimiter=?*)
case $1#*= in # Delete everything up to the = and assign the remainder.
,|.|;|:||)
delimiter=$1#*=
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
;;
--delimiter=) # Handle the case of empty --delimiter=
die 'Error: "--delimiter=" requires a non-empty option argument.'
;;
--)
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %sn' "$1" >&2
;;
*) # Default case. No more options, so break out of the loop
break
esac
shift
done
# Is the file readable?
if [ $# -gt 0 ]
then
[ -r "$1" ] || die "$1: Couldn't read file."
fi
# Is the OC_PASS environment variable set?
[ $OC_PASS:- ] || die "$0: No password specified. Run with --help for more info."
status=true # until a command fails
message 'Adding users'
while IFS=$delimiter:-, read -r f1 f2 f3 f4
do
if [ "$f1" ]
then
docker-compose exec -T -e OC_PASS --user www-data app php occ
user:add --password-from-env
$verbose:+"$verbose"
$f2:+"--display-name=$f2"
$f3:+"--group=$f3"
"$f1" </dev/null
|| status=false
# If there is a fourth value in the csv, use it to set the user email.
if [ "$f4" ]
then
docker-compose exec -T
--user www-data app php occ
user:setting "$f1" settings email "$f4"
</dev/null
|| status=false
fi
else
echo "Expected at least one field, but none were supplied." >&2
status=false
continue
fi
message '...'
done <"$1:-/dev/stdin"
message 'Done'
exec $status
csv posix sh docker
$endgroup$
add a comment |
$begingroup$
I have a working script that will batch add users to an instance of nextcloud running on top of docker. This version is the result of changes made after asking this question.
I guess I'm looking for a re-review to ensure that I haven't missed anything. I'm also interested if there are areas where I could make things better in terms of readability, performance, security, etc. You're the reviewer. My code is your oyster.
#!/bin/sh
set -eu
# Handle printing errors
die ()
printf '%sn' "$1" >&2
exit 1
message ()
printf '%sn' "$1" >&2
usage ()
ENVIRONMENT VARIABLES
OC_PASS
Sets the password for users added. The OC_PASS environment variable
is required.
EXAMPLES
The command:
batch_up.sh foobar.csv
Will add the users from foobar.csv. Users will be given the password
in the OC_PASS environment variable.
The command:
batch_up.sh <<< "jack,Jack Frost,users,jack.frost@gmail.com"
Will add the user jack, set his display name to Jack Frost, add him
to the group users, and set his email to jack.frost@gmail.com.
The command:
echo "jack,Jack Frost,users,jack.frost@gmail.com"
# Set verbosity. Default is silent.
verbose=-q
# flags
while [ $# -gt 0 ]
do
case $1 in
-h|-?|--help)
usage # Display a usage synopsis.
exit
;;
-v|-vv|-vvv|--verbose)
verbose=$1
;;
-d|--delimiter)
if [ $# -gt 1 ]
then
case $2 in
,|.|;|:||)
delimiter=$2
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
else
die 'Error: "--delimiter requires a non-empty option argument.'
fi
;;
--delimiter=?*)
case $1#*= in # Delete everything up to the = and assign the remainder.
,|.|;|:||)
delimiter=$1#*=
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
;;
--delimiter=) # Handle the case of empty --delimiter=
die 'Error: "--delimiter=" requires a non-empty option argument.'
;;
--)
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %sn' "$1" >&2
;;
*) # Default case. No more options, so break out of the loop
break
esac
shift
done
# Is the file readable?
if [ $# -gt 0 ]
then
[ -r "$1" ] || die "$1: Couldn't read file."
fi
# Is the OC_PASS environment variable set?
[ $OC_PASS:- ] || die "$0: No password specified. Run with --help for more info."
status=true # until a command fails
message 'Adding users'
while IFS=$delimiter:-, read -r f1 f2 f3 f4
do
if [ "$f1" ]
then
docker-compose exec -T -e OC_PASS --user www-data app php occ
user:add --password-from-env
$verbose:+"$verbose"
$f2:+"--display-name=$f2"
$f3:+"--group=$f3"
"$f1" </dev/null
|| status=false
# If there is a fourth value in the csv, use it to set the user email.
if [ "$f4" ]
then
docker-compose exec -T
--user www-data app php occ
user:setting "$f1" settings email "$f4"
</dev/null
|| status=false
fi
else
echo "Expected at least one field, but none were supplied." >&2
status=false
continue
fi
message '...'
done <"$1:-/dev/stdin"
message 'Done'
exec $status
csv posix sh docker
$endgroup$
add a comment |
$begingroup$
I have a working script that will batch add users to an instance of nextcloud running on top of docker. This version is the result of changes made after asking this question.
I guess I'm looking for a re-review to ensure that I haven't missed anything. I'm also interested if there are areas where I could make things better in terms of readability, performance, security, etc. You're the reviewer. My code is your oyster.
#!/bin/sh
set -eu
# Handle printing errors
die ()
printf '%sn' "$1" >&2
exit 1
message ()
printf '%sn' "$1" >&2
usage ()
ENVIRONMENT VARIABLES
OC_PASS
Sets the password for users added. The OC_PASS environment variable
is required.
EXAMPLES
The command:
batch_up.sh foobar.csv
Will add the users from foobar.csv. Users will be given the password
in the OC_PASS environment variable.
The command:
batch_up.sh <<< "jack,Jack Frost,users,jack.frost@gmail.com"
Will add the user jack, set his display name to Jack Frost, add him
to the group users, and set his email to jack.frost@gmail.com.
The command:
echo "jack,Jack Frost,users,jack.frost@gmail.com"
# Set verbosity. Default is silent.
verbose=-q
# flags
while [ $# -gt 0 ]
do
case $1 in
-h|-?|--help)
usage # Display a usage synopsis.
exit
;;
-v|-vv|-vvv|--verbose)
verbose=$1
;;
-d|--delimiter)
if [ $# -gt 1 ]
then
case $2 in
,|.|;|:||)
delimiter=$2
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
else
die 'Error: "--delimiter requires a non-empty option argument.'
fi
;;
--delimiter=?*)
case $1#*= in # Delete everything up to the = and assign the remainder.
,|.|;|:||)
delimiter=$1#*=
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
;;
--delimiter=) # Handle the case of empty --delimiter=
die 'Error: "--delimiter=" requires a non-empty option argument.'
;;
--)
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %sn' "$1" >&2
;;
*) # Default case. No more options, so break out of the loop
break
esac
shift
done
# Is the file readable?
if [ $# -gt 0 ]
then
[ -r "$1" ] || die "$1: Couldn't read file."
fi
# Is the OC_PASS environment variable set?
[ $OC_PASS:- ] || die "$0: No password specified. Run with --help for more info."
status=true # until a command fails
message 'Adding users'
while IFS=$delimiter:-, read -r f1 f2 f3 f4
do
if [ "$f1" ]
then
docker-compose exec -T -e OC_PASS --user www-data app php occ
user:add --password-from-env
$verbose:+"$verbose"
$f2:+"--display-name=$f2"
$f3:+"--group=$f3"
"$f1" </dev/null
|| status=false
# If there is a fourth value in the csv, use it to set the user email.
if [ "$f4" ]
then
docker-compose exec -T
--user www-data app php occ
user:setting "$f1" settings email "$f4"
</dev/null
|| status=false
fi
else
echo "Expected at least one field, but none were supplied." >&2
status=false
continue
fi
message '...'
done <"$1:-/dev/stdin"
message 'Done'
exec $status
csv posix sh docker
$endgroup$
I have a working script that will batch add users to an instance of nextcloud running on top of docker. This version is the result of changes made after asking this question.
I guess I'm looking for a re-review to ensure that I haven't missed anything. I'm also interested if there are areas where I could make things better in terms of readability, performance, security, etc. You're the reviewer. My code is your oyster.
#!/bin/sh
set -eu
# Handle printing errors
die ()
printf '%sn' "$1" >&2
exit 1
message ()
printf '%sn' "$1" >&2
usage ()
ENVIRONMENT VARIABLES
OC_PASS
Sets the password for users added. The OC_PASS environment variable
is required.
EXAMPLES
The command:
batch_up.sh foobar.csv
Will add the users from foobar.csv. Users will be given the password
in the OC_PASS environment variable.
The command:
batch_up.sh <<< "jack,Jack Frost,users,jack.frost@gmail.com"
Will add the user jack, set his display name to Jack Frost, add him
to the group users, and set his email to jack.frost@gmail.com.
The command:
echo "jack,Jack Frost,users,jack.frost@gmail.com"
# Set verbosity. Default is silent.
verbose=-q
# flags
while [ $# -gt 0 ]
do
case $1 in
-h|-?|--help)
usage # Display a usage synopsis.
exit
;;
-v|-vv|-vvv|--verbose)
verbose=$1
;;
-d|--delimiter)
if [ $# -gt 1 ]
then
case $2 in
,|.|;|:||)
delimiter=$2
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
else
die 'Error: "--delimiter requires a non-empty option argument.'
fi
;;
--delimiter=?*)
case $1#*= in # Delete everything up to the = and assign the remainder.
,|.|;|:||)
delimiter=$1#*=
shift
;;
*)
die 'Error: delimiter should be one of ,.;:| characters.'
esac
;;
--delimiter=) # Handle the case of empty --delimiter=
die 'Error: "--delimiter=" requires a non-empty option argument.'
;;
--)
shift
break
;;
-?*)
printf 'WARN: Unknown option (ignored): %sn' "$1" >&2
;;
*) # Default case. No more options, so break out of the loop
break
esac
shift
done
# Is the file readable?
if [ $# -gt 0 ]
then
[ -r "$1" ] || die "$1: Couldn't read file."
fi
# Is the OC_PASS environment variable set?
[ $OC_PASS:- ] || die "$0: No password specified. Run with --help for more info."
status=true # until a command fails
message 'Adding users'
while IFS=$delimiter:-, read -r f1 f2 f3 f4
do
if [ "$f1" ]
then
docker-compose exec -T -e OC_PASS --user www-data app php occ
user:add --password-from-env
$verbose:+"$verbose"
$f2:+"--display-name=$f2"
$f3:+"--group=$f3"
"$f1" </dev/null
|| status=false
# If there is a fourth value in the csv, use it to set the user email.
if [ "$f4" ]
then
docker-compose exec -T
--user www-data app php occ
user:setting "$f1" settings email "$f4"
</dev/null
|| status=false
fi
else
echo "Expected at least one field, but none were supplied." >&2
status=false
continue
fi
message '...'
done <"$1:-/dev/stdin"
message 'Done'
exec $status
csv posix sh docker
csv posix sh docker
asked 4 mins ago
quarterpiquarterpi
284
284
add a comment |
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217111%2fbatch-add-users-to-nextcloud-on-docker-with-csv%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f217111%2fbatch-add-users-to-nextcloud-on-docker-with-csv%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown