1 /* SPDX-License-Identifier: LGPL-2.1+ */
9 #include "alloc-util.h"
10 #include "ask-password-api.h"
16 #include "hostname-util.h"
18 #include "libcrypt-util.h"
19 #include "locale-util.h"
20 #include "main-func.h"
21 #include "memory-util.h"
24 #include "parse-util.h"
25 #include "path-util.h"
26 #include "pretty-print.h"
27 #include "proc-cmdline.h"
28 #include "random-util.h"
29 #include "string-util.h"
31 #include "terminal-util.h"
32 #include "time-util.h"
33 #include "tmpfile-util-label.h"
34 #include "umask-util.h"
35 #include "user-util.h"
37 static char *arg_root
= NULL
;
38 static char *arg_locale
= NULL
; /* $LANG */
39 static char *arg_keymap
= NULL
;
40 static char *arg_locale_messages
= NULL
; /* $LC_MESSAGES */
41 static char *arg_timezone
= NULL
;
42 static char *arg_hostname
= NULL
;
43 static sd_id128_t arg_machine_id
= {};
44 static char *arg_root_password
= NULL
;
45 static bool arg_prompt_locale
= false;
46 static bool arg_prompt_keymap
= false;
47 static bool arg_prompt_timezone
= false;
48 static bool arg_prompt_hostname
= false;
49 static bool arg_prompt_root_password
= false;
50 static bool arg_copy_locale
= false;
51 static bool arg_copy_keymap
= false;
52 static bool arg_copy_timezone
= false;
53 static bool arg_copy_root_password
= false;
54 static bool arg_force
= false;
56 STATIC_DESTRUCTOR_REGISTER(arg_root
, freep
);
57 STATIC_DESTRUCTOR_REGISTER(arg_locale
, freep
);
58 STATIC_DESTRUCTOR_REGISTER(arg_locale_messages
, freep
);
59 STATIC_DESTRUCTOR_REGISTER(arg_keymap
, freep
);
60 STATIC_DESTRUCTOR_REGISTER(arg_timezone
, freep
);
61 STATIC_DESTRUCTOR_REGISTER(arg_hostname
, freep
);
62 STATIC_DESTRUCTOR_REGISTER(arg_root_password
, erase_and_freep
);
64 static bool press_any_key(void) {
68 printf("-- Press any key to proceed --");
71 (void) read_one_char(stdin
, &k
, USEC_INFINITY
, &need_nl
);
79 static void print_welcome(void) {
80 _cleanup_free_
char *pretty_name
= NULL
, *ansi_color
= NULL
;
81 static bool done
= false;
90 "PRETTY_NAME", &pretty_name
,
91 "ANSI_COLOR", &ansi_color
,
94 log_full_errno(r
== -ENOENT
? LOG_DEBUG
: LOG_WARNING
, r
,
95 "Failed to read os-release file, ignoring: %m");
97 pn
= isempty(pretty_name
) ? "Linux" : pretty_name
;
100 printf("\nWelcome to your new installation of \x1B[%sm%s\x1B[0m!\n", ansi_color
, pn
);
102 printf("\nWelcome to your new installation of %s!\n", pn
);
104 printf("\nPlease configure your system!\n\n");
111 static int show_menu(char **x
, unsigned n_columns
, unsigned width
, unsigned percentage
) {
112 unsigned break_lines
, break_modulo
;
113 size_t n
, per_column
, i
, j
;
115 assert(n_columns
> 0);
118 per_column
= DIV_ROUND_UP(n
, n_columns
);
120 break_lines
= lines();
124 /* The first page gets two extra lines, since we want to show
126 break_modulo
= break_lines
;
127 if (break_modulo
> 3)
130 for (i
= 0; i
< per_column
; i
++) {
132 for (j
= 0; j
< n_columns
; j
++) {
133 _cleanup_free_
char *e
= NULL
;
135 if (j
* per_column
+ i
>= n
)
138 e
= ellipsize(x
[j
* per_column
+ i
], width
, percentage
);
142 printf("%4zu) %-*s", j
* per_column
+ i
+ 1, width
, e
);
147 /* on the first screen we reserve 2 extra lines for the title */
148 if (i
% break_lines
== break_modulo
) {
149 if (!press_any_key())
157 static int prompt_loop(const char *text
, char **l
, unsigned percentage
, bool (*is_valid
)(const char *name
), char **ret
) {
165 _cleanup_free_
char *p
= NULL
;
168 r
= ask_string(&p
, "%s %s (empty to skip, \"list\" to list options): ",
169 special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET
), text
);
171 return log_error_errno(r
, "Failed to query user: %m");
174 log_warning("No data entered, skipping.");
178 if (streq(p
, "list")) {
179 r
= show_menu(l
, 3, 22, percentage
);
187 r
= safe_atou(p
, &u
);
189 if (u
<= 0 || u
> strv_length(l
)) {
190 log_error("Specified entry number out of range.");
194 log_info("Selected '%s'.", l
[u
-1]);
195 if (free_and_strdup(ret
, l
[u
-1]) < 0)
202 log_error("Entered data invalid.");
206 return free_and_replace(*ret
, p
);
210 static bool locale_is_ok(const char *name
) {
213 return locale_is_valid(name
);
215 return locale_is_installed(name
) > 0;
218 static int prompt_locale(void) {
219 _cleanup_strv_free_
char **locales
= NULL
;
222 if (arg_locale
|| arg_locale_messages
)
225 if (!arg_prompt_locale
)
228 r
= get_locales(&locales
);
230 return log_error_errno(r
, "Cannot query locales list: %m");
232 if (strv_isempty(locales
))
233 log_debug("No locales found, skipping locale selection.");
234 else if (strv_length(locales
) == 1) {
236 if (streq(locales
[0], SYSTEMD_DEFAULT_LOCALE
))
237 log_debug("Only installed locale is default locale anyway, not setting locale explicitly.");
239 log_debug("Only a single locale available (%s), selecting it as default.", locales
[0]);
241 arg_locale
= strdup(locales
[0]);
245 /* Not setting arg_locale_message here, since it defaults to LANG anyway */
250 r
= prompt_loop("Please enter system locale name or number",
251 locales
, 60, locale_is_ok
, &arg_locale
);
255 if (isempty(arg_locale
))
258 r
= prompt_loop("Please enter system message locale name or number",
259 locales
, 60, locale_is_ok
, &arg_locale_messages
);
263 /* Suppress the messages setting if it's the same as the main locale anyway */
264 if (streq_ptr(arg_locale
, arg_locale_messages
))
265 arg_locale_messages
= mfree(arg_locale_messages
);
271 static int process_locale(void) {
272 const char *etc_localeconf
;
277 etc_localeconf
= prefix_roota(arg_root
, "/etc/locale.conf");
278 if (laccess(etc_localeconf
, F_OK
) >= 0 && !arg_force
)
281 if (arg_copy_locale
&& arg_root
) {
283 (void) mkdir_parents(etc_localeconf
, 0755);
284 r
= copy_file("/etc/locale.conf", etc_localeconf
, 0, 0644, 0, 0, COPY_REFLINK
);
287 return log_error_errno(r
, "Failed to copy %s: %m", etc_localeconf
);
289 log_info("%s copied.", etc_localeconf
);
298 if (!isempty(arg_locale
))
299 locales
[i
++] = strjoina("LANG=", arg_locale
);
300 if (!isempty(arg_locale_messages
) && !streq(arg_locale_messages
, arg_locale
))
301 locales
[i
++] = strjoina("LC_MESSAGES=", arg_locale_messages
);
308 (void) mkdir_parents(etc_localeconf
, 0755);
309 r
= write_env_file(etc_localeconf
, locales
);
311 return log_error_errno(r
, "Failed to write %s: %m", etc_localeconf
);
313 log_info("%s written.", etc_localeconf
);
317 static int prompt_keymap(void) {
318 _cleanup_strv_free_
char **kmaps
= NULL
;
324 if (!arg_prompt_keymap
)
327 r
= get_keymaps(&kmaps
);
328 if (r
== -ENOENT
) /* no keymaps installed */
331 return log_error_errno(r
, "Failed to read keymaps: %m");
335 return prompt_loop("Please enter system keymap name or number",
336 kmaps
, 60, keymap_is_valid
, &arg_keymap
);
339 static int process_keymap(void) {
340 const char *etc_vconsoleconf
;
344 etc_vconsoleconf
= prefix_roota(arg_root
, "/etc/vconsole.conf");
345 if (laccess(etc_vconsoleconf
, F_OK
) >= 0 && !arg_force
)
348 if (arg_copy_keymap
&& arg_root
) {
350 (void) mkdir_parents(etc_vconsoleconf
, 0755);
351 r
= copy_file("/etc/vconsole.conf", etc_vconsoleconf
, 0, 0644, 0, 0, COPY_REFLINK
);
354 return log_error_errno(r
, "Failed to copy %s: %m", etc_vconsoleconf
);
356 log_info("%s copied.", etc_vconsoleconf
);
363 return 0; /* don't fail if no keymaps are installed */
367 if (isempty(arg_keymap
))
370 keymap
= STRV_MAKE(strjoina("KEYMAP=", arg_keymap
));
372 r
= mkdir_parents(etc_vconsoleconf
, 0755);
374 return log_error_errno(r
, "Failed to create the parent directory of %s: %m", etc_vconsoleconf
);
376 r
= write_env_file(etc_vconsoleconf
, keymap
);
378 return log_error_errno(r
, "Failed to write %s: %m", etc_vconsoleconf
);
380 log_info("%s written.", etc_vconsoleconf
);
384 static bool timezone_is_valid_log_error(const char *name
) {
385 return timezone_is_valid(name
, LOG_ERR
);
388 static int prompt_timezone(void) {
389 _cleanup_strv_free_
char **zones
= NULL
;
395 if (!arg_prompt_timezone
)
398 r
= get_timezones(&zones
);
400 return log_error_errno(r
, "Cannot query timezone list: %m");
404 r
= prompt_loop("Please enter timezone name or number",
405 zones
, 30, timezone_is_valid_log_error
, &arg_timezone
);
412 static int process_timezone(void) {
413 const char *etc_localtime
, *e
;
416 etc_localtime
= prefix_roota(arg_root
, "/etc/localtime");
417 if (laccess(etc_localtime
, F_OK
) >= 0 && !arg_force
)
420 if (arg_copy_timezone
&& arg_root
) {
421 _cleanup_free_
char *p
= NULL
;
423 r
= readlink_malloc("/etc/localtime", &p
);
426 return log_error_errno(r
, "Failed to read host timezone: %m");
428 (void) mkdir_parents(etc_localtime
, 0755);
429 if (symlink(p
, etc_localtime
) < 0)
430 return log_error_errno(errno
, "Failed to create %s symlink: %m", etc_localtime
);
432 log_info("%s copied.", etc_localtime
);
437 r
= prompt_timezone();
441 if (isempty(arg_timezone
))
444 e
= strjoina("../usr/share/zoneinfo/", arg_timezone
);
446 (void) mkdir_parents(etc_localtime
, 0755);
447 if (symlink(e
, etc_localtime
) < 0)
448 return log_error_errno(errno
, "Failed to create %s symlink: %m", etc_localtime
);
450 log_info("%s written", etc_localtime
);
454 static int prompt_hostname(void) {
460 if (!arg_prompt_hostname
)
467 _cleanup_free_
char *h
= NULL
;
469 r
= ask_string(&h
, "%s Please enter hostname for new system (empty to skip): ", special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET
));
471 return log_error_errno(r
, "Failed to query hostname: %m");
474 log_warning("No hostname entered, skipping.");
478 if (!hostname_is_valid(h
, true)) {
479 log_error("Specified hostname invalid.");
483 /* Get rid of the trailing dot that we allow, but don't want to see */
484 arg_hostname
= hostname_cleanup(h
);
492 static int process_hostname(void) {
493 const char *etc_hostname
;
496 etc_hostname
= prefix_roota(arg_root
, "/etc/hostname");
497 if (laccess(etc_hostname
, F_OK
) >= 0 && !arg_force
)
500 r
= prompt_hostname();
504 if (isempty(arg_hostname
))
507 r
= write_string_file(etc_hostname
, arg_hostname
,
508 WRITE_STRING_FILE_CREATE
| WRITE_STRING_FILE_SYNC
| WRITE_STRING_FILE_MKDIR_0755
|
509 (arg_force
? WRITE_STRING_FILE_ATOMIC
: 0));
511 return log_error_errno(r
, "Failed to write %s: %m", etc_hostname
);
513 log_info("%s written.", etc_hostname
);
517 static int process_machine_id(void) {
518 const char *etc_machine_id
;
519 char id
[SD_ID128_STRING_MAX
];
522 etc_machine_id
= prefix_roota(arg_root
, "/etc/machine-id");
523 if (laccess(etc_machine_id
, F_OK
) >= 0 && !arg_force
)
526 if (sd_id128_is_null(arg_machine_id
))
529 r
= write_string_file(etc_machine_id
, sd_id128_to_string(arg_machine_id
, id
),
530 WRITE_STRING_FILE_CREATE
| WRITE_STRING_FILE_SYNC
| WRITE_STRING_FILE_MKDIR_0755
|
531 (arg_force
? WRITE_STRING_FILE_ATOMIC
: 0));
533 return log_error_errno(r
, "Failed to write machine id: %m");
535 log_info("%s written.", etc_machine_id
);
539 static int prompt_root_password(void) {
540 const char *msg1
, *msg2
;
543 if (arg_root_password
)
546 if (!arg_prompt_root_password
)
552 msg1
= strjoina(special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET
), " Please enter a new root password (empty to skip):");
553 msg2
= strjoina(special_glyph(SPECIAL_GLYPH_TRIANGULAR_BULLET
), " Please enter new root password again:");
556 _cleanup_strv_free_erase_
char **a
= NULL
, **b
= NULL
;
558 r
= ask_password_tty(-1, msg1
, NULL
, 0, 0, NULL
, &a
);
560 return log_error_errno(r
, "Failed to query root password: %m");
561 if (strv_length(a
) != 1)
562 return log_error_errno(SYNTHETIC_ERRNO(EIO
),
563 "Received multiple passwords, where we expected one.");
566 log_warning("No password entered, skipping.");
570 r
= ask_password_tty(-1, msg2
, NULL
, 0, 0, NULL
, &b
);
572 return log_error_errno(r
, "Failed to query root password: %m");
573 if (strv_length(b
) != 1)
574 return log_error_errno(SYNTHETIC_ERRNO(EIO
),
575 "Received multiple passwords, where we expected one.");
577 if (!streq(*a
, *b
)) {
578 log_error("Entered passwords did not match, please try again.");
582 arg_root_password
= TAKE_PTR(*a
);
589 static int write_root_shadow(const char *shadow_path
, const char *hashed_password
) {
590 _cleanup_fclose_
FILE *original
= NULL
, *shadow
= NULL
;
591 _cleanup_(unlink_and_freep
) char *shadow_tmp
= NULL
;
594 r
= fopen_temporary_label("/etc/shadow", shadow_path
, &shadow
, &shadow_tmp
);
598 original
= fopen(shadow_path
, "re");
602 r
= sync_rights(fileno(original
), fileno(shadow
));
606 while ((r
= fgetspent_sane(original
, &i
)) > 0) {
608 if (streq(i
->sp_namp
, "root")) {
609 i
->sp_pwdp
= (char *) hashed_password
;
610 i
->sp_lstchg
= (long) (now(CLOCK_REALTIME
) / USEC_PER_DAY
);
613 r
= putspent_sane(i
, shadow
);
622 .sp_namp
= (char*) "root",
623 .sp_pwdp
= (char *) hashed_password
,
624 .sp_lstchg
= (long) (now(CLOCK_REALTIME
) / USEC_PER_DAY
),
630 .sp_flag
= (unsigned long) -1, /* this appears to be what everybody does ... */
636 r
= fchmod(fileno(shadow
), 0000);
640 r
= putspent_sane(&root
, shadow
);
645 r
= fflush_sync_and_check(shadow
);
649 r
= rename_and_apply_smack_floor_label(shadow_tmp
, shadow_path
);
656 static int process_root_password(void) {
657 _cleanup_free_
char *salt
= NULL
;
658 _cleanup_close_
int lock
= -1;
659 struct crypt_data cd
= {};
660 const char *hashed_password
;
661 const char *etc_shadow
;
664 etc_shadow
= prefix_roota(arg_root
, "/etc/shadow");
665 if (laccess(etc_shadow
, F_OK
) >= 0 && !arg_force
)
668 (void) mkdir_parents(etc_shadow
, 0755);
670 lock
= take_etc_passwd_lock(arg_root
);
672 return log_error_errno(lock
, "Failed to take a lock: %m");
674 if (arg_copy_root_password
&& arg_root
) {
678 p
= getspnam("root");
679 if (p
|| errno
!= ENOENT
) {
684 return log_error_errno(errno
, "Failed to find shadow entry for root: %m");
687 r
= write_root_shadow(etc_shadow
, p
->sp_pwdp
);
689 return log_error_errno(r
, "Failed to write %s: %m", etc_shadow
);
691 log_info("%s copied.", etc_shadow
);
696 r
= prompt_root_password();
700 if (!arg_root_password
)
703 r
= make_salt(&salt
);
705 return log_error_errno(r
, "Failed to get salt: %m");
708 hashed_password
= crypt_r(arg_root_password
, salt
, &cd
);
709 if (!hashed_password
)
710 return log_error_errno(errno
== 0 ? SYNTHETIC_ERRNO(EINVAL
) : errno
,
711 "Failed to encrypt password: %m");
713 r
= write_root_shadow(etc_shadow
, hashed_password
);
715 return log_error_errno(r
, "Failed to write %s: %m", etc_shadow
);
717 log_info("%s written.", etc_shadow
);
721 static int help(void) {
722 _cleanup_free_
char *link
= NULL
;
725 r
= terminal_urlify_man("systemd-firstboot", "1", &link
);
729 printf("%s [OPTIONS...]\n\n"
730 "Configures basic settings of the system.\n\n"
731 " -h --help Show this help\n"
732 " --version Show package version\n"
733 " --root=PATH Operate on an alternate filesystem root\n"
734 " --locale=LOCALE Set primary locale (LANG=)\n"
735 " --locale-messages=LOCALE Set message locale (LC_MESSAGES=)\n"
736 " --keymap=KEYMAP Set keymap\n"
737 " --timezone=TIMEZONE Set timezone\n"
738 " --hostname=NAME Set hostname\n"
739 " --machine-ID=ID Set machine ID\n"
740 " --root-password=PASSWORD Set root password\n"
741 " --root-password-file=FILE Set root password from file\n"
742 " --prompt-locale Prompt the user for locale settings\n"
743 " --prompt-keymap Prompt the user for keymap settings\n"
744 " --prompt-timezone Prompt the user for timezone\n"
745 " --prompt-hostname Prompt the user for hostname\n"
746 " --prompt-root-password Prompt the user for root password\n"
747 " --prompt Prompt for all of the above\n"
748 " --copy-locale Copy locale from host\n"
749 " --copy-keymap Copy keymap from host\n"
750 " --copy-timezone Copy timezone from host\n"
751 " --copy-root-password Copy root password from host\n"
752 " --copy Copy locale, keymap, timezone, root password\n"
753 " --setup-machine-id Generate a new random machine ID\n"
754 " --force Overwrite existing files\n"
755 "\nSee the %s for details.\n"
756 , program_invocation_short_name
763 static int parse_argv(int argc
, char *argv
[]) {
775 ARG_ROOT_PASSWORD_FILE
,
781 ARG_PROMPT_ROOT_PASSWORD
,
786 ARG_COPY_ROOT_PASSWORD
,
787 ARG_SETUP_MACHINE_ID
,
791 static const struct option options
[] = {
792 { "help", no_argument
, NULL
, 'h' },
793 { "version", no_argument
, NULL
, ARG_VERSION
},
794 { "root", required_argument
, NULL
, ARG_ROOT
},
795 { "locale", required_argument
, NULL
, ARG_LOCALE
},
796 { "locale-messages", required_argument
, NULL
, ARG_LOCALE_MESSAGES
},
797 { "keymap", required_argument
, NULL
, ARG_KEYMAP
},
798 { "timezone", required_argument
, NULL
, ARG_TIMEZONE
},
799 { "hostname", required_argument
, NULL
, ARG_HOSTNAME
},
800 { "machine-id", required_argument
, NULL
, ARG_MACHINE_ID
},
801 { "root-password", required_argument
, NULL
, ARG_ROOT_PASSWORD
},
802 { "root-password-file", required_argument
, NULL
, ARG_ROOT_PASSWORD_FILE
},
803 { "prompt", no_argument
, NULL
, ARG_PROMPT
},
804 { "prompt-locale", no_argument
, NULL
, ARG_PROMPT_LOCALE
},
805 { "prompt-keymap", no_argument
, NULL
, ARG_PROMPT_KEYMAP
},
806 { "prompt-timezone", no_argument
, NULL
, ARG_PROMPT_TIMEZONE
},
807 { "prompt-hostname", no_argument
, NULL
, ARG_PROMPT_HOSTNAME
},
808 { "prompt-root-password", no_argument
, NULL
, ARG_PROMPT_ROOT_PASSWORD
},
809 { "copy", no_argument
, NULL
, ARG_COPY
},
810 { "copy-locale", no_argument
, NULL
, ARG_COPY_LOCALE
},
811 { "copy-keymap", no_argument
, NULL
, ARG_COPY_KEYMAP
},
812 { "copy-timezone", no_argument
, NULL
, ARG_COPY_TIMEZONE
},
813 { "copy-root-password", no_argument
, NULL
, ARG_COPY_ROOT_PASSWORD
},
814 { "setup-machine-id", no_argument
, NULL
, ARG_SETUP_MACHINE_ID
},
815 { "force", no_argument
, NULL
, ARG_FORCE
},
824 while ((c
= getopt_long(argc
, argv
, "h", options
, NULL
)) >= 0)
835 r
= parse_path_argument_and_warn(optarg
, true, &arg_root
);
841 r
= free_and_strdup(&arg_locale
, optarg
);
847 case ARG_LOCALE_MESSAGES
:
848 r
= free_and_strdup(&arg_locale_messages
, optarg
);
855 if (!keymap_is_valid(optarg
))
856 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
857 "Keymap %s is not valid.", optarg
);
859 r
= free_and_strdup(&arg_keymap
, optarg
);
866 if (!timezone_is_valid(optarg
, LOG_ERR
))
867 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
868 "Timezone %s is not valid.", optarg
);
870 r
= free_and_strdup(&arg_timezone
, optarg
);
876 case ARG_ROOT_PASSWORD
:
877 r
= free_and_strdup(&arg_root_password
, optarg
);
882 case ARG_ROOT_PASSWORD_FILE
:
883 arg_root_password
= mfree(arg_root_password
);
885 r
= read_one_line_file(optarg
, &arg_root_password
);
887 return log_error_errno(r
, "Failed to read %s: %m", optarg
);
892 if (!hostname_is_valid(optarg
, true))
893 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
894 "Host name %s is not valid.", optarg
);
896 hostname_cleanup(optarg
);
897 r
= free_and_strdup(&arg_hostname
, optarg
);
904 if (sd_id128_from_string(optarg
, &arg_machine_id
) < 0)
905 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
),
906 "Failed to parse machine id %s.", optarg
);
911 arg_prompt_locale
= arg_prompt_keymap
= arg_prompt_timezone
= arg_prompt_hostname
= arg_prompt_root_password
= true;
914 case ARG_PROMPT_LOCALE
:
915 arg_prompt_locale
= true;
918 case ARG_PROMPT_KEYMAP
:
919 arg_prompt_keymap
= true;
922 case ARG_PROMPT_TIMEZONE
:
923 arg_prompt_timezone
= true;
926 case ARG_PROMPT_HOSTNAME
:
927 arg_prompt_hostname
= true;
930 case ARG_PROMPT_ROOT_PASSWORD
:
931 arg_prompt_root_password
= true;
935 arg_copy_locale
= arg_copy_keymap
= arg_copy_timezone
= arg_copy_root_password
= true;
938 case ARG_COPY_LOCALE
:
939 arg_copy_locale
= true;
942 case ARG_COPY_KEYMAP
:
943 arg_copy_keymap
= true;
946 case ARG_COPY_TIMEZONE
:
947 arg_copy_timezone
= true;
950 case ARG_COPY_ROOT_PASSWORD
:
951 arg_copy_root_password
= true;
954 case ARG_SETUP_MACHINE_ID
:
956 r
= sd_id128_randomize(&arg_machine_id
);
958 return log_error_errno(r
, "Failed to generate randomized machine ID: %m");
970 assert_not_reached("Unhandled option");
973 /* We check if the specified locale strings are valid down here, so that we can take --root= into
974 * account when looking for the locale files. */
976 if (arg_locale
&& !locale_is_ok(arg_locale
))
977 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale %s is not installed.", arg_locale
);
978 if (arg_locale_messages
&& !locale_is_ok(arg_locale_messages
))
979 return log_error_errno(SYNTHETIC_ERRNO(EINVAL
), "Locale %s is not installed.", arg_locale_messages
);
984 static int run(int argc
, char *argv
[]) {
988 r
= parse_argv(argc
, argv
);
996 r
= proc_cmdline_get_bool("systemd.firstboot", &enabled
);
998 return log_error_errno(r
, "Failed to parse systemd.firstboot= kernel command line argument, ignoring: %m");
999 if (r
> 0 && !enabled
)
1000 return 0; /* disabled */
1002 r
= process_locale();
1006 r
= process_keymap();
1010 r
= process_timezone();
1014 r
= process_hostname();
1018 r
= process_machine_id();
1022 r
= process_root_password();
1029 DEFINE_MAIN_FUNCTION(run
);