Hostname support

This commit is contained in:
Ward from fusion-voyager-3 2024-02-20 22:54:30 +03:00
parent 8a105779dc
commit 45bae23246
8 changed files with 57 additions and 12 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
pika-first-setup (1.0.1-100pika1) pikauwu; urgency=low
pika-first-setup (1.0.1-100pika2) pikauwu; urgency=low
* First release

View File

@ -31,7 +31,8 @@
"user_info_password_verify_title": "Напишете Потребителска парола отново:",
"error_label_is_root_label": "Потребителското име не може да е root.",
"error_label_is_pikaos_label": "Потребителското име не може да е pikaos.",
"error_label_is_special_label": "Потребителското име не може да съдържа специални символи.",
"error_label_username_is_special_label": "Потребителското име не може да съдържа специални символи.",
"error_label_hostname_is_special_label": "",
"error_label_password_mismatch_label": "Паролите не съвпадат!",
"first_setup_gameutils_box_text_title": "PikaOS Геймърски МЕТА Пакет",
"first_setup_gameutils_box_text_description": "Бихте ли желали PikaOS Геймърския МЕТА Пакет?\n(от съществено значение, затова е и силно препоръчителен)",

View File

@ -31,7 +31,8 @@
"user_info_password_verify_title": "Gib das Benutzerpasswort erneut ein:",
"error_label_is_root_label": "Der Benutzername darf nicht root sein.",
"error_label_is_pikaos_label": "Der Benutzername darf nicht pikaos sein.",
"error_label_is_special_label": "Der Benutzername darf keine Sonderzeichen enthalten.",
"error_label_username_is_special_label": "Username can not contain special characters or spaces.",
"error_label_hostname_is_special_label": "Hostname can not contain special characters or spaces.",
"error_label_password_mismatch_label": "Passwörter stimmen nicht überein!",
"first_setup_gameutils_box_text_title": "PikaOS Gaming Meta-Paket",
"first_setup_gameutils_box_text_description": "Möchtest du das PikaOS Gaming Meta-Paket?\n(unverzichtbar für Spiele, daher dringend empfohlen)",

View File

@ -27,11 +27,13 @@
"first_setup_user_box_text_description": "Create a user account.",
"user_info_username_title": "Username:",
"user_info_full_name_title": "Full name:",
"user_info_hostname_title": "Hostname:",
"user_info_password_title": "User password:",
"user_info_password_verify_title": "Enter User password again:",
"error_label_is_root_label": "Username can not be root.",
"error_label_is_pikaos_label": "Username can not be pikaos.",
"error_label_is_special_label": "Username can not contain special characters.",
"error_label_username_is_special_label": "Username can not contain special characters or spaces.",
"error_label_hostname_is_special_label": "Hostname can not contain special characters or spaces.",
"error_label_password_mismatch_label": "Passwords do not match!",
"first_setup_gameutils_box_text_title": "PikaOS Gaming Meta Package",
"first_setup_gameutils_box_text_description": "Would you like the PikaOS Gaming Meta Package?\n(essential for gaming thus strongly recommended)",

View File

@ -31,7 +31,8 @@
"user_info_password_verify_title": "",
"error_label_is_root_label": "Le nom d'utilisateur ne peut pas être \"root\".",
"error_label_is_pikaos_label": "Le nom d'utilisateur ne peut pas être \"pikaos\".",
"error_label_is_special_label": "Le nom d'utilisateur ne peut pas contenir de caractères spéciaux.",
"error_label_username_is_special_label": "Username can not contain special characters or spaces.",
"error_label_hostname_is_special_label": "Hostname can not contain special characters or spaces.",
"error_label_password_mismatch_label": "Les mots de passe ne correspondent pas!",
"first_setup_gameutils_box_text_title": "",
"first_setup_gameutils_box_text_description": "",

View File

@ -31,7 +31,8 @@
"user_info_password_verify_title": "Inserisci la password dell'utente un altra volta:",
"error_label_is_root_label": "L'username non può essere root.",
"error_label_is_pikaos_label": "L'username non può essere pikaos.",
"error_label_is_special_label": "L'username non può contenere caratteri speciali.",
"error_label_username_is_special_label": "Username can not contain special characters or spaces.",
"error_label_hostname_is_special_label": "Hostname can not contain special characters or spaces.",
"error_label_password_mismatch_label": "Le password non corrispondono!",
"first_setup_gameutils_box_text_title": "PikaOS Pacchetto per il Gaming",
"first_setup_gameutils_box_text_description": "Vorresti installare il pacchetto per il gaming di Pika OS?\\n(poichè è essenziale per il gaming esso è estremamente raccomandato)",

View File

@ -31,7 +31,8 @@
"user_info_password_verify_title": "Ange Användarlösenord igen:",
"error_label_is_root_label": "Användarnamn kan inte vara root.",
"error_label_is_pikaos_label": "Användarnamn kan inte vara pikaos.",
"error_label_is_special_label": "Användarnamn kan inte innehålla specialtecken.",
"error_label_username_is_special_label": "Username can not contain special characters or spaces.",
"error_label_hostname_is_special_label": "Hostname can not contain special characters or spaces.",
"error_label_password_mismatch_label": "Lösenorden matchar inte varandra!",
"first_setup_gameutils_box_text_title": "PikaOS Gaming Meta Package",
"first_setup_gameutils_box_text_description": "Vill du ha PikaOS Gaming Meta Package?\n(essentiell för spel och därmed en stark rekommendation)",

View File

@ -18,6 +18,7 @@ const USER_CREATE_PROG: &str = r###"
USERNAME="$0"
PASSWORD="$1"
FULLNAME="$2"
HOSTNAME="$3"
adduser --quiet --disabled-password --shell /bin/bash --gecos "${FULLNAME}" "${USERNAME}"
echo "${USERNAME}":"${PASSWORD}" | chpasswd
usermod -a -G sudo "${USERNAME}"
@ -26,6 +27,8 @@ cp -rvf /etc/skel/.* /home/"${USERNAME}"/ || true
chown -R "${USERNAME}":"${USERNAME}" /home/"${USERNAME}"
usermod -a -G adm,cdrom,sudo,render,dip,video,plugdev,input,render,lpadmin "${USERNAME}"
rm -rf /etc/sddm.conf.d/zautologin.conf || true
hostnamectl set-hostname "${HOSTNAME}"
echo "127.0.0.1 ${HOSTNAME}" >> /etc/hosts
"###;
fn only_alphanumeric(input: &str) -> bool {
@ -43,6 +46,7 @@ fn uppercase_first_letter(s: &str) -> String {
pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
let user_info_username_valid = Rc::new(RefCell::new(false));
let user_info_full_name_valid = Rc::new(RefCell::new(false));
let user_info_hostname_valid = Rc::new(RefCell::new(false));
let user_info_passwords_valid = Rc::new(RefCell::new(false));
let (user_loop_sender, user_loop_receiver) = async_channel::unbounded();
@ -104,6 +108,11 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
.title(t!("user_info_password_title"))
.build();
let user_info_hostname = adw::EntryRow::builder()
.hexpand(true)
.title(t!("user_info_hostname_title"))
.build();
let user_info_password_verify = adw::PasswordEntryRow::builder()
.hexpand(true)
.title(t!("user_info_password_verify_title"))
@ -163,6 +172,7 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
user_info_listbox.append(&user_info_username);
user_info_listbox.append(&user_info_full_name);
user_info_listbox.append(&user_info_hostname);
user_info_listbox.append(&user_info_password);
user_info_listbox.append(&user_info_password_verify_revealer);
@ -176,9 +186,9 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
// The main loop executes the asynchronous block
let user_loop_context = MainContext::default();
user_loop_context.spawn_local(clone!(@strong user_info_username_valid, @strong user_info_full_name_valid, @strong user_info_passwords_valid, @weak user_next_button => async move {
user_loop_context.spawn_local(clone!(@strong user_info_username_valid, @strong user_info_full_name_valid,@strong user_info_hostname_valid, @strong user_info_passwords_valid, @weak user_next_button => async move {
while let Ok(_state) = user_loop_receiver.recv().await {
if *user_info_username_valid.borrow_mut() == true && *user_info_full_name_valid.borrow_mut() == true && *user_info_passwords_valid.borrow_mut() == true {
if *user_info_username_valid.borrow_mut() == true && *user_info_full_name_valid.borrow_mut() == true && *user_info_hostname_valid.borrow_mut() && *user_info_passwords_valid.borrow_mut() == true {
user_next_button.set_sensitive(true);
} else {
user_next_button.set_sensitive(false);
@ -222,7 +232,7 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
if only_alphanumeric(&user_info_username_string) {
_username_is_special=false;
} else {
error_label.set_label(&t!("error_label_is_special_label"));
error_label.set_label(&t!("error_label_username_is_special_label"));
_username_is_special=true;
}
@ -252,6 +262,34 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
}
}));
user_info_hostname.connect_changed(clone!(@strong user_info_hostname_valid, @weak user_info_hostname, @weak user_info_full_name, @weak error_label => move |_| {
let user_info_hostname_string = user_info_hostname.text().to_string();
if user_info_hostname_string.len() > 32 {
user_info_hostname.set_text(&user_info_hostname_string[..32]);
user_info_hostname.set_position(-1);
}
let mut _hostname_is_special = false;
if Regex::new(r"^[A-Za-z0-9\.]*$").unwrap().is_match(&user_info_hostname_string) {
_hostname_is_special=false;
} else {
error_label.set_label(&t!("error_label_hostname_is_special_label"));
_hostname_is_special=true;
}
if _hostname_is_special == false {
error_label.set_visible(false);
if !user_info_hostname.text().is_empty() {
*user_info_hostname_valid.borrow_mut()=true;
}
} else {
*user_info_hostname_valid.borrow_mut()=false;
error_label.set_visible(true);
}
}));
user_info_password.connect_changed(clone!(@strong user_info_passwords_valid,@weak user_info_password_verify_revealer, @weak user_info_password, @weak user_info_password_verify, @weak error_label => move |_| {
if user_info_password.text().is_empty() {
user_info_password_verify_revealer.set_reveal_child(false)
@ -278,8 +316,8 @@ pub fn user_carousel(first_setup_carousel: &adw::Carousel) {
}
}));
user_next_button.connect_clicked(clone!(@weak first_setup_carousel, @weak user_info_username, @weak user_info_password, @weak user_info_full_name => move |_| {
let result = cmd!("/usr/lib/pika/pika-first-setup-gtk4/scripts/pika-sudo.sh", "bash", "-c", USER_CREATE_PROG, &user_info_username.text(), &user_info_password.text(), &user_info_full_name.text()).read();
user_next_button.connect_clicked(clone!(@weak first_setup_carousel, @weak user_info_username, @weak user_info_hostname, @weak user_info_password, @weak user_info_full_name, @weak user_info_hostname_valid => move |_| {
let result = cmd!("/usr/lib/pika/pika-first-setup-gtk4/scripts/pika-sudo.sh", "bash", "-c", USER_CREATE_PROG, &user_info_username.text(), &user_info_password.text(), &user_info_full_name.text(), &user_info_hostname.text()).read();
assert!(result.is_ok());
first_setup_carousel.scroll_to(&first_setup_carousel.nth_page(3), true);
}));