From 28d8c284cb0ed982835272a849f78f23d2617132 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Fri, 11 Jun 2021 03:09:06 -0600 Subject: [PATCH] feat: Support setting profile icon --- cli/src/main.rs | 13 ++++++++++++- ffi/distinst.vapi | 1 + ffi/src/config.rs | 2 ++ src/installer/mod.rs | 1 + src/installer/steps/configure/chroot_conf.rs | 7 +++++++ src/installer/steps/configure/mod.rs | 1 + 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/cli/src/main.rs b/cli/src/main.rs index db650afa..da6addcf 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -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), ) @@ -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") @@ -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 { @@ -264,7 +275,7 @@ fn main() { } }); - UserAccountCreate { realname, username, password } + UserAccountCreate { realname, username, password, profile_icon } }); let pb_opt: Rc>>> = Rc::new(RefCell::new(None)); diff --git a/ffi/distinst.vapi b/ffi/distinst.vapi index 90fbd54a..ed463cea 100644 --- a/ffi/distinst.vapi +++ b/ffi/distinst.vapi @@ -59,6 +59,7 @@ namespace Distinst { string username; string? realname; string? password; + string profile_icon; } [CCode (cname = "DISTINST_PARTITION_TABLE", has_type_id = false)] diff --git a/ffi/src/config.rs b/ffi/src/config.rs index 7fd9928e..39b60879 100644 --- a/ffi/src/config.rs +++ b/ffi/src/config.rs @@ -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 { @@ -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(), }) } } diff --git a/src/installer/mod.rs b/src/installer/mod.rs index 8f1eae66..d98f0d92 100644 --- a/src/installer/mod.rs +++ b/src/installer/mod.rs @@ -74,6 +74,7 @@ pub struct UserAccountCreate { pub username: String, pub realname: Option, pub password: Option, + pub profile_icon: String, } /// Installer error diff --git a/src/installer/steps/configure/chroot_conf.rs b/src/installer/steps/configure/chroot_conf.rs index 94a61bbf..468dc706 100644 --- a/src/installer/steps/configure/chroot_conf.rs +++ b/src/installer/steps/configure/chroot_conf.rs @@ -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 { @@ -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(()) } diff --git a/src/installer/steps/configure/mod.rs b/src/installer/steps/configure/mod.rs index 8daa3fe1..da4fa0dc 100644 --- a/src/installer/steps/configure/mod.rs +++ b/src/installer/steps/configure/mod.rs @@ -263,6 +263,7 @@ pub fn configure, S: AsRef, F: FnMut(i3 &user.username, user.password.as_deref(), user.realname.as_deref(), + &user.profile_icon, ) } else { Ok(())