@@ -304,11 +304,15 @@ public function install(array $options, ?IOutput $output = null): array {
304304 $ error = [];
305305 $ dbType = $ options ['dbtype ' ];
306306
307- if (empty ($ options ['adminlogin ' ])) {
308- $ error [] = $ l ->t ('Set an admin Login. ' );
309- }
310- if (empty ($ options ['adminpass ' ])) {
311- $ error [] = $ l ->t ('Set an admin password. ' );
307+ $ disableAdminUser = (bool )($ options ['admindisable ' ] ?? false );
308+
309+ if (!$ disableAdminUser ) {
310+ if (empty ($ options ['adminlogin ' ])) {
311+ $ error [] = $ l ->t ('Set an admin Login. ' );
312+ }
313+ if (empty ($ options ['adminpass ' ])) {
314+ $ error [] = $ l ->t ('Set an admin password. ' );
315+ }
312316 }
313317 if (empty ($ options ['directory ' ])) {
314318 $ options ['directory ' ] = \OC ::$ SERVERROOT . '/data ' ;
@@ -318,8 +322,6 @@ public function install(array $options, ?IOutput $output = null): array {
318322 $ dbType = 'sqlite ' ;
319323 }
320324
321- $ username = htmlspecialchars_decode ($ options ['adminlogin ' ]);
322- $ password = htmlspecialchars_decode ($ options ['adminpass ' ]);
323325 $ dataDir = htmlspecialchars_decode ($ options ['directory ' ]);
324326
325327 $ class = self ::$ dbSetupClasses [$ dbType ];
@@ -375,7 +377,7 @@ public function install(array $options, ?IOutput $output = null): array {
375377 $ this ->outputDebug ($ output , 'Configuring database ' );
376378 $ dbSetup ->initialize ($ options );
377379 try {
378- $ dbSetup ->setupDatabase ($ username );
380+ $ dbSetup ->setupDatabase ();
379381 } catch (\OC \DatabaseSetupException $ e ) {
380382 $ error [] = [
381383 'error ' => $ e ->getMessage (),
@@ -405,19 +407,22 @@ public function install(array $options, ?IOutput $output = null): array {
405407 return $ error ;
406408 }
407409
408- $ this ->outputDebug ($ output , 'Create admin account ' );
409-
410- // create the admin account and group
411410 $ user = null ;
412- try {
413- $ user = Server::get (IUserManager::class)->createUser ($ username , $ password );
414- if (!$ user ) {
415- $ error [] = "Account < $ username> could not be created. " ;
411+ if (!$ disableAdminUser ) {
412+ $ username = htmlspecialchars_decode ($ options ['adminlogin ' ]);
413+ $ password = htmlspecialchars_decode ($ options ['adminpass ' ]);
414+ $ this ->outputDebug ($ output , 'Create admin account ' );
415+
416+ try {
417+ $ user = Server::get (IUserManager::class)->createUser ($ username , $ password );
418+ if (!$ user ) {
419+ $ error [] = "Account < $ username> could not be created. " ;
420+ return $ error ;
421+ }
422+ } catch (Exception $ exception ) {
423+ $ error [] = $ exception ->getMessage ();
416424 return $ error ;
417425 }
418- } catch (Exception $ exception ) {
419- $ error [] = $ exception ->getMessage ();
420- return $ error ;
421426 }
422427
423428 $ config = Server::get (IConfig::class);
@@ -432,7 +437,7 @@ public function install(array $options, ?IOutput $output = null): array {
432437 }
433438
434439 $ group = Server::get (IGroupManager::class)->createGroup ('admin ' );
435- if ($ group instanceof IGroup) {
440+ if ($ user !== null && $ group instanceof IGroup) {
436441 $ group ->addUser ($ user );
437442 }
438443
@@ -464,26 +469,28 @@ public function install(array $options, ?IOutput $output = null): array {
464469 $ bootstrapCoordinator = Server::get (\OC \AppFramework \Bootstrap \Coordinator::class);
465470 $ bootstrapCoordinator ->runInitialRegistration ();
466471
467- // Create a session token for the newly created user
468- // The token provider requires a working db, so it's not injected on setup
469- /** @var \OC\User\Session $userSession */
470- $ userSession = Server::get (IUserSession::class);
471- $ provider = Server::get (PublicKeyTokenProvider::class);
472- $ userSession ->setTokenProvider ($ provider );
473- $ userSession ->login ($ username , $ password );
474- $ user = $ userSession ->getUser ();
475- if (!$ user ) {
476- $ error [] = 'No account found in session. ' ;
477- return $ error ;
478- }
479- $ userSession ->createSessionToken ($ request , $ user ->getUID (), $ username , $ password );
472+ if (!$ disableAdminUser ) {
473+ // Create a session token for the newly created user
474+ // The token provider requires a working db, so it's not injected on setup
475+ /** @var \OC\User\Session $userSession */
476+ $ userSession = Server::get (IUserSession::class);
477+ $ provider = Server::get (PublicKeyTokenProvider::class);
478+ $ userSession ->setTokenProvider ($ provider );
479+ $ userSession ->login ($ username , $ password );
480+ $ user = $ userSession ->getUser ();
481+ if (!$ user ) {
482+ $ error [] = 'No account found in session. ' ;
483+ return $ error ;
484+ }
485+ $ userSession ->createSessionToken ($ request , $ user ->getUID (), $ username , $ password );
480486
481- $ session = $ userSession ->getSession ();
482- $ session ->set ('last-password-confirm ' , Server::get (ITimeFactory::class)->getTime ());
487+ $ session = $ userSession ->getSession ();
488+ $ session ->set ('last-password-confirm ' , Server::get (ITimeFactory::class)->getTime ());
483489
484- // Set email for admin
485- if (!empty ($ options ['adminemail ' ])) {
486- $ user ->setSystemEMailAddress ($ options ['adminemail ' ]);
490+ // Set email for admin
491+ if (!empty ($ options ['adminemail ' ])) {
492+ $ user ->setSystemEMailAddress ($ options ['adminemail ' ]);
493+ }
487494 }
488495
489496 return $ error ;
0 commit comments