in libazureinit/src/provision/user.rs [135:170]
fn useradd(user: &User) -> Result<(), Error> {
if user_exists(&user.name)? {
tracing::info!(
target: "libazureinit::user::add",
"User '{}' already exists. Skipping user creation.",
user.name
);
let group_list = user.groups.join(",");
tracing::info!(
target: "libazureinit:user::add",
"User '{}' is being added to the following groups: {}",
user.name,
group_list
);
let mut command = Command::new("usermod");
command.arg("-aG").arg(&group_list).arg(&user.name);
return crate::run(command);
}
let path_useradd = env!("PATH_USERADD");
let mut command = Command::new(path_useradd);
command
.arg(&user.name)
.arg("--comment")
.arg("azure-init created this user based on username provided in IMDS")
.arg("--groups")
.arg(user.groups.join(","))
.arg("-d")
.arg(format!("/home/{}", user.name))
.arg("-m");
crate::run(command)
}