Put repo make in single action

This commit is contained in:
Ward from fusion-voyager-3 2024-09-24 20:00:27 +03:00
parent e45147dbcd
commit c0a8767821
7 changed files with 446 additions and 36 deletions

View File

@ -31,7 +31,6 @@ install_no_build_debug:
cp -vf target/debug/pikman-update-manager $(DESTDIR)/usr/bin/
cp -vf target/debug/apt_update $(DESTDIR)/usr/lib/pika/pikman-update-manager/scripts/
cp -vf target/debug/apt_full_upgrade $(DESTDIR)/usr/lib/pika/pikman-update-manager/scripts/
cp -vf data/wget.sh $(DESTDIR)/usr/lib/pika/pikman-update-manager/scripts/
cp -vf data/modify_repo.sh $(DESTDIR)/usr/lib/pika/pikman-update-manager/scripts/
cp -vf data/*.gschema.xml $(DESTDIR)/usr/share/glib-2.0/schemas/
#cp -vf data/com.github.pikaos-linux.pikagnomelayouts.desktop $(DESTDIR)/usr/share/applications/

View File

@ -1,10 +1,21 @@
#! /bin/bash
set -e
if [[ "$1" == "deb822_move" ]]
then
mv -vf "/tmp/"$2".sources" "/etc/apt/sources.list.d/"$2".sources"
elif [[ "$1" == "legacy_move" ]]
then
mv -vf "/tmp/"$2".list" "/etc/apt/sources.list.d/"$2".list"
elif [[ "$1" == "deb822_move_with_wget" ]]
then
wget -O $4 $3
mv -vf "/tmp/"$2".sources" "/etc/apt/sources.list.d/"$2".sources"
elif [[ "$1" == "legacy_move_with_wget" ]]
then
wget -O $4 $3
mv -vf "/tmp/"$2".list" "/etc/apt/sources.list.d/"$2".list"
elif [[ "$1" == "delete_deb822" ]]
then
rm -rvf $2

View File

@ -1,2 +0,0 @@
#! /bin/bash
wget -O $2 $1

View File

@ -117,5 +117,8 @@
"apt_src_remove_warning_dialog_heading": "Are You Sure?",
"apt_src_remove_warning_dialog_body": "The Repositoy Will Be Deleted, And Any Packages Downloaded From It Might Get Overwritten",
"apt_src_remove_warning_dialog_cancel_label": "Cancel",
"apt_src_remove_warning_dialog_ok_label": "OK"
"apt_src_remove_warning_dialog_ok_label": "OK",
"unofficial_source_add_is_enabled_label_label": "Enabled",
"unofficial_source_edit_dialog_add_edit": "Save Changes",
"unofficial_source_edit_dialog_heading": "Editing"
}

View File

@ -156,13 +156,13 @@ pub fn add_dialog_fn(window: adw::ApplicationWindow) {
unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false);
unofficial_source_add_dialog.set_response_appearance(
"unofficial_source_add_dialog_add",
adw::ResponseAppearance::Suggested,
"unofficial_source_add_dialog_cancel",
adw::ResponseAppearance::Destructive,
);
unofficial_source_add_dialog.set_response_appearance(
"unofficial_source_add_dialog_cancel",
adw::ResponseAppearance::Destructive,
"unofficial_source_add_dialog_add",
adw::ResponseAppearance::Suggested,
);
//
@ -282,7 +282,6 @@ pub fn add_dialog_fn(window: adw::ApplicationWindow) {
.choose(None::<&gio::Cancellable>, move |choice| {
match choice.as_str() {
"unofficial_source_add_dialog_add" => {
println!("add");
let non_alphanum_regex = Regex::new(r"[^a-zA-Z0-9]").unwrap();
let sign_method = if unofficial_source_signed_file_checkbutton.is_active() {
1
@ -316,11 +315,9 @@ pub fn add_dialog_fn(window: adw::ApplicationWindow) {
..Default::default()
};
if sign_method == 2 {
match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/wget.sh", &unofficial_source_add_signed_entry.text().to_string(), &format!("/etc/apt/keyrings/{}.gpg.key", repo_file_name)).run() {
Ok(_) => {
match Deb822Repository::write_to_file(new_repo.clone(), format!("/tmp/{}.sources", repo_file_name).into()) {
Ok(_) => {
match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "deb822_move", repo_file_name).run() {
match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "deb822_move_with_wget", &repo_file_name, &unofficial_source_add_signed_entry.text().to_string(), &format!("/etc/apt/keyrings/{}.gpg.key", &repo_file_name)).run() {
Ok(_) => {}
Err(e) => {
let apt_src_create_error_dialog = adw::MessageDialog::builder()
@ -347,19 +344,6 @@ pub fn add_dialog_fn(window: adw::ApplicationWindow) {
apt_src_create_error_dialog.present();
}
}
}
Err(e) => {
let key_download_error_dialog = adw::MessageDialog::builder()
.heading(t!("key_download_error_dialog_heading"))
.body(e.to_string())
.build();
key_download_error_dialog.add_response(
"key_download_error_dialog_ok",
&t!("key_download_error_dialog_ok_label").to_string(),
);
key_download_error_dialog.present();
}
}
} else {
match Deb822Repository::write_to_file(new_repo.clone(), format!("/tmp/{}.sources", repo_file_name).into()) {
Ok(_) => {
@ -392,9 +376,6 @@ pub fn add_dialog_fn(window: adw::ApplicationWindow) {
}
}
}
"apt_update_dialog_ignore" => {
unofficial_source_add_dialog.close();
}
_ => {}
}
});

View File

@ -0,0 +1,399 @@
use crate::apt_package_row::AptPackageRow;
use adw::gio::SimpleAction;
use adw::prelude::*;
use apt_deb822_tools::Deb822Repository;
use regex::Regex;
use gtk::glib::{property::PropertyGet, clone, BoxedAnyObject};
use gtk::*;
use std::cell::Ref;
use std::ops::Deref;
use pika_unixsocket_tools::pika_unixsocket_tools::*;
use rust_apt::cache::*;
use rust_apt::new_cache;
use rust_apt::records::RecordField;
use std::cell::RefCell;
use std::process::Command;
use std::rc::Rc;
use std::thread;
use tokio::runtime::Runtime;
use std::path::Path;
pub fn deb822_edit_dialog_fn(
window: adw::ApplicationWindow,
deb822_repo: &Deb822Repository,
) {
let repofile_path = Path::new(&deb822_repo.filepath);
let repo_file_name = repofile_path
.file_name()
.unwrap()
.to_str()
.unwrap()
.to_owned();
let unofficial_source_add_dialog_child_box = Box::builder()
.hexpand(true)
.orientation(Orientation::Vertical)
.build();
let unofficial_source_add_name_entry = gtk::Entry::builder()
.build();
let unofficial_source_add_name_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("unofficial_source_add_name_prefrencesgroup_title"))
.build();
unofficial_source_add_name_prefrencesgroup.add(&unofficial_source_add_name_entry);
let unofficial_source_add_uri_entry = gtk::Entry::builder()
.build();
let unofficial_source_add_uri_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("unofficial_source_add_uri_prefrencesgroup_title"))
.build();
unofficial_source_add_uri_prefrencesgroup.add(&unofficial_source_add_uri_entry);
let unofficial_source_add_suites_entry = gtk::Entry::builder()
.build();
let unofficial_source_add_suites_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("unofficial_source_add_suites_prefrencesgroup_title"))
.build();
unofficial_source_add_suites_prefrencesgroup.add(&unofficial_source_add_suites_entry);
let unofficial_source_add_components_entry = gtk::Entry::builder()
.build();
let unofficial_source_add_components_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("unofficial_source_add_components_prefrencesgroup_title"))
.build();
unofficial_source_add_components_prefrencesgroup.add(&unofficial_source_add_components_entry);
let unofficial_source_add_signed_entry = gtk::Entry::builder()
.sensitive(false)
.build();
let unofficial_source_add_signed_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("unofficial_source_add_signed_prefrencesgroup_title"))
.build();
unofficial_source_add_signed_prefrencesgroup.add(&unofficial_source_add_signed_entry);
let unofficial_source_add_archs_entry = gtk::Entry::builder()
.build();
let unofficial_source_add_archs_prefrencesgroup = adw::PreferencesGroup::builder()
.title(t!("unofficial_source_add_archs_prefrencesgroup_title"))
.build();
unofficial_source_add_archs_prefrencesgroup.add(&unofficial_source_add_archs_entry);
let unofficial_source_add_box2 = gtk::Box::builder()
.margin_top(10)
.orientation(Orientation::Horizontal)
.hexpand(true)
.spacing(5)
.build();
let unofficial_source_add_is_source_label = gtk::Label::builder()
.label(t!("unofficial_source_add_is_source_label_label"))
.halign(Align::Start)
.valign(Align::Center)
.build();
let unofficial_source_add_is_enabled_label = gtk::Label::builder()
.label(t!("unofficial_source_add_is_enabled_label_label"))
.halign(Align::Start)
.valign(Align::Center)
.build();
let unofficial_source_add_is_source_switch = gtk::Switch::builder()
.halign(Align::Start)
.valign(Align::Center)
.build();
let unofficial_source_add_is_enabled_switch = gtk::Switch::builder()
.halign(Align::Start)
.valign(Align::Center)
.build();
let unofficial_source_signed_keyring_checkbutton = gtk::CheckButton::builder()
.halign(Align::Start)
.valign(Align::Center)
.label(t!("unofficial_source_signed_keyring_checkbutton_label"))
.active(true)
.build();
let unofficial_source_signed_file_checkbutton = gtk::CheckButton::builder()
.halign(Align::Start)
.valign(Align::Center)
.label(t!("unofficial_source_signed_file_checkbutton_label"))
.group(&unofficial_source_signed_keyring_checkbutton)
.build();
//
let unofficial_source_add_dialog_child_clamp = adw::Clamp::builder()
.child(&unofficial_source_add_dialog_child_box)
.maximum_size(500)
.build();
let unofficial_source_add_viewport = gtk::ScrolledWindow::builder()
.hexpand(true)
.vexpand(true)
.child(&unofficial_source_add_dialog_child_clamp)
.hscrollbar_policy(PolicyType::Never)
.build();
let unofficial_source_add_dialog = adw::MessageDialog::builder()
.transient_for(&window)
.extra_child(&unofficial_source_add_viewport)
.heading(t!("unofficial_source_edit_dialog_heading").to_string() + " " + &repo_file_name)
.width_request(700)
.height_request(500)
.build();
unofficial_source_add_dialog.add_response(
"unofficial_source_edit_dialog_edit",
&t!("unofficial_source_edit_dialog_add_edit").to_string(),
);
unofficial_source_add_dialog.add_response(
"unofficial_source_add_dialog_cancel",
&t!("unofficial_source_add_dialog_cancel_label").to_string(),
);
unofficial_source_add_dialog.set_response_enabled("unofficial_source_add_dialog_add", false);
unofficial_source_add_dialog.set_response_appearance(
"unofficial_source_add_dialog_cancel",
adw::ResponseAppearance::Destructive,
);
unofficial_source_add_dialog.set_response_appearance(
"unofficial_source_edit_dialog_edit",
adw::ResponseAppearance::Suggested,
);
//
let unofficial_source_add_dialog_clone0 = unofficial_source_add_dialog.clone();
let unofficial_source_add_name_entry_clone0 = unofficial_source_add_name_entry.clone();
let unofficial_source_add_uri_entry_clone0 = unofficial_source_add_uri_entry.clone();
let unofficial_source_add_suites_entry_clone0 = unofficial_source_add_suites_entry.clone();
let unofficial_source_add_components_entry_clone0 = unofficial_source_add_components_entry.clone();
let unofficial_source_add_signed_entry_clone0 = unofficial_source_add_signed_entry.clone();
let unofficial_source_signed_keyring_checkbutton_clone0 = unofficial_source_signed_keyring_checkbutton.clone();
let add_button_update_state = move || {
if
!unofficial_source_add_name_entry_clone0.text().is_empty() &&
!unofficial_source_add_uri_entry_clone0.text().is_empty() &&
!unofficial_source_add_suites_entry_clone0.text().is_empty() &&
!unofficial_source_add_components_entry_clone0.text().is_empty()
{
if unofficial_source_signed_keyring_checkbutton_clone0.is_active() {
unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true);
} else if !unofficial_source_add_signed_entry_clone0.text().is_empty() {
unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", true);
} else {
unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false);
}
} else {
unofficial_source_add_dialog_clone0.set_response_enabled("unofficial_source_add_dialog_add", false);
}
};
//
for entry in [
&unofficial_source_add_name_entry,
&unofficial_source_add_uri_entry,
&unofficial_source_add_suites_entry,
&unofficial_source_add_components_entry,
&unofficial_source_add_signed_entry,
] {
entry.connect_text_notify(clone!(
#[strong]
add_button_update_state,
move |_|
{
add_button_update_state();
}
)
);
}
//
unofficial_source_signed_keyring_checkbutton.connect_toggled(clone!(
#[weak]
unofficial_source_add_signed_entry,
#[strong]
add_button_update_state,
move |checkbutton|
{
if checkbutton.is_active() {
unofficial_source_add_signed_entry.set_sensitive(false);
add_button_update_state();
}
}
)
);
unofficial_source_signed_file_checkbutton.connect_toggled(clone!(
#[weak]
unofficial_source_add_signed_entry,
#[strong]
add_button_update_state,
move |checkbutton|
{
if checkbutton.is_active() {
unofficial_source_add_signed_entry.set_sensitive(true);
add_button_update_state();
}
}
)
);
unofficial_source_add_box2.append(&unofficial_source_add_is_source_label);
unofficial_source_add_box2.append(&unofficial_source_add_is_source_switch);
unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_label);
unofficial_source_add_box2.append(&unofficial_source_add_is_enabled_switch);
unofficial_source_add_box2.append(&unofficial_source_signed_keyring_checkbutton);
unofficial_source_add_box2.append(&unofficial_source_signed_file_checkbutton);
unofficial_source_add_dialog_child_box.append(&unofficial_source_add_name_prefrencesgroup);
unofficial_source_add_dialog_child_box.append(&unofficial_source_add_uri_prefrencesgroup);
unofficial_source_add_dialog_child_box.append(&unofficial_source_add_suites_prefrencesgroup);
unofficial_source_add_dialog_child_box.append(&unofficial_source_add_components_prefrencesgroup);
unofficial_source_add_dialog_child_box.append(&unofficial_source_add_archs_prefrencesgroup);
unofficial_source_add_dialog_child_box.append(&unofficial_source_add_box2);
unofficial_source_add_dialog_child_box.append(&unofficial_source_add_signed_prefrencesgroup);
//
match &deb822_repo.repolib_name {
Some(t) => {
unofficial_source_add_name_entry.set_text(&t);
}
None => {}
}
match &deb822_repo.uris {
Some(t) => {
unofficial_source_add_uri_entry.set_text(&t);
}
None => {}
}
match &deb822_repo.suites {
Some(t) => {
unofficial_source_add_suites_entry.set_text(&t);
}
None => {}
}
match &deb822_repo.components {
Some(t) => {
unofficial_source_add_components_entry.set_text(&t);
}
None => {}
}
match &deb822_repo.signed_by {
Some(t) => {
unofficial_source_signed_file_checkbutton.set_active(true);
unofficial_source_add_signed_entry.set_text(&t);
}
None => {
unofficial_source_signed_keyring_checkbutton.set_active(true)
}
}
match &deb822_repo.architectures {
Some(t) => {
unofficial_source_add_archs_entry.set_text(&t);
}
None => {}
}
match &deb822_repo.enabled {
Some(t) => {
unofficial_source_add_is_enabled_switch.set_active(match t.to_lowercase().as_str() {
"yes" => true,
"true" => true,
"no" => false,
"false" => false,
_ => true,
});
}
None => {
unofficial_source_add_is_enabled_switch.set_active(true);
}
}
//
let deb822_repo_clone0 = deb822_repo.clone();
unofficial_source_add_dialog.clone()
.choose(None::<&gio::Cancellable>, move |choice| {
match choice.as_str() {
"unofficial_source_edit_dialog_edit" => {
let sign_method = if unofficial_source_signed_file_checkbutton.is_active() {
1
} else {
0
};
let new_repo = Deb822Repository {
repolib_name: Some(unofficial_source_add_name_entry.text().to_string()),
filepath: format!("/etc/apt/sources.list.d/{}.source", repo_file_name),
uris: Some(unofficial_source_add_uri_entry.text().to_string()),
types: if unofficial_source_add_is_source_switch.is_active() {
Some("deb deb-src".to_string())
} else {
Some("deb".to_string())
},
suites: Some(unofficial_source_add_suites_entry.text().to_string()),
components: Some(unofficial_source_add_components_entry.text().to_string()),
architectures: if unofficial_source_add_archs_entry.text().is_empty() {
None
} else {
Some(unofficial_source_add_archs_entry.text().to_string())
},
signed_by: match sign_method {
1 => Some(unofficial_source_add_signed_entry.text().to_string()),
_ => None
},
..deb822_repo_clone0
};
match Deb822Repository::write_to_file(new_repo.clone(), format!("/tmp/{}.sources", repo_file_name).into()) {
Ok(_) => {
match duct::cmd!("pkexec", "/usr/lib/pika/pikman-update-manager/scripts/modify_repo.sh", "deb822_move", repo_file_name).run() {
Ok(_) => {}
Err(e) => {
let apt_src_create_error_dialog = adw::MessageDialog::builder()
.heading(t!("apt_src_create_error_dialog_heading"))
.body(e.to_string())
.build();
apt_src_create_error_dialog.add_response(
"apt_src_create_error_dialog_ok",
&t!("apt_src_create_error_dialog_ok_label").to_string(),
);
apt_src_create_error_dialog.present();
}
}
}
Err(e) => {
let apt_src_create_error_dialog = adw::MessageDialog::builder()
.heading(t!("apt_src_create_error_dialog_heading"))
.body(e.to_string())
.build();
apt_src_create_error_dialog.add_response(
"apt_src_create_error_dialog_ok",
&t!("apt_src_create_error_dialog_ok_label").to_string(),
);
apt_src_create_error_dialog.present();
}
}
}
_ => {}
}
});
}

View File

@ -19,6 +19,7 @@ use std::thread;
use tokio::runtime::Runtime;
mod add_dialog;
mod deb822_edit_dialog;
enum AptSourceConfig {
Legacy(apt_legacy_tools::LegacyAptSource),
@ -103,13 +104,6 @@ pub fn apt_manage_page(
.margin_end(15)
.build();
/*unofficial_sources_selection_model.connect_selected_item_notify(|selection| {
let selection = selection.selected_item().unwrap();
let entry = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let r: Ref<AptSourceConfig> = entry.borrow();
println!("{}", r.col2.to_string())
});*/
let unofficial_sources_selection_model_rc: Rc<RefCell<gtk::SingleSelection>> = Rc::new(RefCell::default());
let unofficial_sources_selection_model_rc_clone0 = Rc::clone(&unofficial_sources_selection_model_rc);
@ -322,7 +316,32 @@ pub fn apt_manage_page(
move
|_|
{
add_dialog_fn(window.clone());
add_dialog::add_dialog_fn(window.clone());
}
)
);
unofficial_source_edit_button.connect_clicked(clone!(
#[strong]
window,
#[strong]
unofficial_sources_selection_model_rc,
#[strong]
reload_unofficial_source_closure,
move
|_|
{
let unofficial_sources_selection_model = unofficial_sources_selection_model_rc.borrow();
let selection = unofficial_sources_selection_model.selected_item().unwrap();
let item = selection.downcast_ref::<BoxedAnyObject>().unwrap();
let apt_src: Ref<AptSourceConfig> = item.borrow();
match apt_src.deref() {
AptSourceConfig::DEB822(src) => {
deb822_edit_dialog::deb822_edit_dialog_fn(window.clone(), src);
}
AptSourceConfig::Legacy(list) => {}
};
}
)
);