Skip to content

Commit

Permalink
feat: Support setting profile icon
Browse files Browse the repository at this point in the history
  • Loading branch information
mmstick committed Jun 14, 2021
1 parent 38769ab commit 28d8c28
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ fn main() {
.arg(
Arg::with_name("username")
.long("username")
.requires("profile_icon")
.help("specifies a default user account to create")
.takes_value(true),
)
Expand All @@ -47,6 +48,12 @@ fn main() {
.requires("username")
.takes_value(true),
)
.arg(
Arg::with_name("profile_icon")
.long("profile_icon")
.help("path to icon for user profile")
.takes_value(true),
)
.arg(
Arg::with_name("timezone")
.long("tz")
Expand Down Expand Up @@ -252,6 +259,10 @@ fn main() {

let user_account = matches.value_of("username").map(|username| {
let username = username.to_owned();
let profile_icon = matches.value_of("profile_icon")
.expect("requires profile icon path")
.to_owned();

let realname = matches.value_of("realname").map(String::from);
let password = matches.value_of("password").map(String::from).or_else(|| {
if unsafe { libc::isatty(0) } == 0 {
Expand All @@ -264,7 +275,7 @@ fn main() {
}
});

UserAccountCreate { realname, username, password }
UserAccountCreate { realname, username, password, profile_icon }
});

let pb_opt: Rc<RefCell<Option<ProgressBar<io::Stdout>>>> = Rc::new(RefCell::new(None));
Expand Down
1 change: 1 addition & 0 deletions ffi/distinst.vapi
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace Distinst {
string username;
string? realname;
string? password;
string profile_icon;
}

[CCode (cname = "DISTINST_PARTITION_TABLE", has_type_id = false)]
Expand Down
2 changes: 2 additions & 0 deletions ffi/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct DistinstUserAccountCreate {
pub username: *const libc::c_char,
pub realname: *const libc::c_char,
pub password: *const libc::c_char,
pub profile_icon: *const libc::c_char,
}

impl DistinstUserAccountCreate {
Expand All @@ -47,6 +48,7 @@ impl DistinstUserAccountCreate {
username: get_str(self.username)?.to_owned(),
realname: get_str(self.realname).ok().map(String::from),
password: get_str(self.password).ok().map(String::from),
profile_icon: get_str(self.profile_icon)?.to_owned(),
})
}
}
1 change: 1 addition & 0 deletions src/installer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub struct UserAccountCreate {
pub username: String,
pub realname: Option<String>,
pub password: Option<String>,
pub profile_icon: String,
}

/// Installer error
Expand Down
7 changes: 7 additions & 0 deletions src/installer/steps/configure/chroot_conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ impl<'a> ChrootConfigurator<'a> {
user: &str,
pass: Option<&str>,
fullname: Option<&str>,
profile_icon: &str,
) -> io::Result<()> {
let mut command = self.chroot.command("useradd", &["-m", "-G", "adm,sudo"]);
if let Some(name) = fullname {
Expand All @@ -182,6 +183,12 @@ impl<'a> ChrootConfigurator<'a> {
self.chroot.command("passwd", &[user]).stdin_input(&pass).run()?;
}

let dest = self.chroot.path.join(&["home/", user, "/.face"].concat());

if fs::copy(&profile_icon, &dest).is_err() {
let _ = fs::remove_file(&dest);
}

Ok(())
}

Expand Down
1 change: 1 addition & 0 deletions src/installer/steps/configure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ pub fn configure<D: InstallerDiskOps, P: AsRef<Path>, S: AsRef<str>, F: FnMut(i3
&user.username,
user.password.as_deref(),
user.realname.as_deref(),
&user.profile_icon,
)
} else {
Ok(())
Expand Down

0 comments on commit 28d8c28

Please sign in to comment.