Added shell chooser

axtloss/rework-partitioning
UsernameSwift 2 years ago
parent ae62d58efb
commit 36590317aa

@ -228,6 +228,10 @@ pub struct NewUserArgs {
/// When not providing a password openssl jumps into an interactive masked input mode allowing you to hide your password /// When not providing a password openssl jumps into an interactive masked input mode allowing you to hide your password
/// from the terminal history. /// from the terminal history.
pub password: String, pub password: String,
/// The shell to use for the user. The current options are bash, csh, fish, tcsh, and zsh.
/// If a shell is not specified or unknown, it defaults to fish.
pub shell: String,
} }
#[derive(Debug, ArgEnum, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Serialize, Deserialize)] #[derive(Debug, ArgEnum, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Serialize, Deserialize)]

@ -127,6 +127,7 @@ pub fn setup_unakite(root: &str, oldroot: &str, efi: bool, efidir: &str, bootdev
true, true,
"Cp7oN04ZY0PsA", // unakite "Cp7oN04ZY0PsA", // unakite
false, false,
"/bin/bash",
); );
exec_eval( exec_eval(
exec( exec(

@ -2,7 +2,8 @@ use crate::internal::exec::*;
use crate::internal::*; use crate::internal::*;
use std::process::Command; use std::process::Command;
pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool) { pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: bool, shell: &str) {
let mut shell: &str = shell;
if do_hash_pass { if do_hash_pass {
let hashed_pass = &*hash_pass(password).stdout; let hashed_pass = &*hash_pass(password).stdout;
let _password = match std::str::from_utf8(hashed_pass) { let _password = match std::str::from_utf8(hashed_pass) {
@ -10,13 +11,66 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo
Err(e) => panic!("Failed to hash password, invalid UTF-8 sequence {}", e), Err(e) => panic!("Failed to hash password, invalid UTF-8 sequence {}", e),
}; };
} }
if shell == "fish" {
exec_eval(
exec_chroot(
"bash",
vec![
String::from("pacman -S fish --noconfirm"),
],
),
"installed fish",
);
}
if shell == "zsh" {
exec_eval(
exec_chroot(
"bash",
vec![
String::from("pacman -S zsh --noconfirm"),
],
),
"installed zsh",
);
}
else if shell == "tcsh" || shell == "csh" {
exec_eval(
exec_chroot(
"bash",
vec![
String::from("pacman -S tcsh --noconfirm"),
],
),
"installed tcsh and csh",
);
}
else {
exec_eval(
exec_chroot(
"bash",
vec![
String::from("pacman -S fish --noconfirm"),
],
),
"no shell or unknown shell specified, installed fish",
);
shell = "fish";
}
let shell_path = match shell {
"bash" => "/bin/bash",
"csh" => "/bin/csh",
"fish" => "/bin/fish",
"tcsh" => "/bin/tcsh",
"zsh" => "/bin/zsh",
&_ => "/bin/fish",
};
exec_eval( exec_eval(
exec_chroot( exec_chroot(
"useradd", "useradd",
vec![ vec![
String::from("-m"), String::from("-m"),
String::from("-s"), String::from("-s"),
String::from("/bin/bash"), String::from(shell_path),
String::from("-p"), String::from("-p"),
String::from(password).replace('\n', ""), String::from(password).replace('\n', ""),
String::from(username), String::from(username),
@ -49,7 +103,7 @@ pub fn new_user(username: &str, hasroot: bool, password: &str, do_hash_pass: boo
pub fn hash_pass(password: &str) -> std::process::Output { pub fn hash_pass(password: &str) -> std::process::Output {
let output = Command::new("openssl") let output = Command::new("openssl")
.args(["passwd", "-1", password]) .args(["passwd", "-6", password])
.output() .output()
.expect("Failed to hash password"); .expect("Failed to hash password");
output output
@ -67,3 +121,4 @@ pub fn root_pass(root_pass: &str) {
"set root password", "set root password",
); );
} }

@ -53,6 +53,7 @@ struct Users {
name: String, name: String,
password: String, password: String,
hasroot: bool, hasroot: bool,
shell: String,
} }
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
@ -138,11 +139,13 @@ pub fn read_config(configpath: PathBuf) {
log::info!("Creating user : {}", config.users[i].name); log::info!("Creating user : {}", config.users[i].name);
log::info!("Setting use password : {}", config.users[i].password); log::info!("Setting use password : {}", config.users[i].password);
log::info!("Enabling root for user : {}", config.users[i].hasroot); log::info!("Enabling root for user : {}", config.users[i].hasroot);
log::info!("Setting user shell : {}", config.users[i].shell);
users::new_user( users::new_user(
config.users[i].name.as_str(), config.users[i].name.as_str(),
config.users[i].hasroot, config.users[i].hasroot,
config.users[i].password.as_str(), config.users[i].password.as_str(),
false, false,
config.users[i].shell.as_str(),
); );
println!("---------"); println!("---------");
} }

@ -53,7 +53,7 @@ fn main() {
} }
Command::Users { subcommand } => match subcommand { Command::Users { subcommand } => match subcommand {
UsersSubcommand::NewUser(args) => { UsersSubcommand::NewUser(args) => {
users::new_user(&args.username, args.hasroot, &args.password, true); users::new_user(&args.username, args.hasroot, &args.password, true, &args.shell);
} }
UsersSubcommand::RootPass { password } => { UsersSubcommand::RootPass { password } => {
users::root_pass(&password); users::root_pass(&password);

Loading…
Cancel
Save