diff --git a/Makefile b/Makefile index d132dfb..b28a503 100644 --- a/Makefile +++ b/Makefile @@ -123,6 +123,8 @@ install: check uninstall done @install -Dm644 -t "${DESTDIR}${PREFIX}/share/applications/" "${PKGNAME}.desktop" @install -Dm755 -t "${DESTDIR}${PREFIX}/bin/" "${CMAKE_BUILD_DIR}/${PKGNAME}" + @install -Dm644 "com.ublinux.${PKGNAME}.policy" "${DESTDIR}/usr/share/polkit-1/actions/com.ublinux.${PKGNAME}${PKGIDENT}.policy" + @sed -e '\|annotate key=|s|/usr/bin|${PREFIX}/bin|' -e '/action id=/s/\.run/${PKGIDENT}\.run/' -i ${DESTDIR}/usr/share/polkit-1/actions/com.ublinux.${PKGNAME}${PKGIDENT}.policy @if [ -z ${DESTDIR} ]; then \ [ -d "${DESTDIR}/usr/share/icons/hicolor/" ] && gtk-update-icon-cache -fiq "${DESTDIR}/usr/share/icons/hicolor/" &>/dev/null || true; \ update-desktop-database --quiet &>/dev/null || true; \ diff --git a/com.ublinux.ubinstall-gtk.policy b/com.ublinux.ubinstall-gtk.policy new file mode 100644 index 0000000..6a12933 --- /dev/null +++ b/com.ublinux.ubinstall-gtk.policy @@ -0,0 +1,24 @@ + + + + + UBLinux + https://ublinux.ru + + + Run "ubinstall-gtk" as root + Запуск утилиты ubinstall-gtk с правами root + Authentication is required to run ubinstall-gtk + Требуется авторизация для запуска утилиты ubinstall-gtk с правами root + + auth_admin + auth_admin + auth_admin + + /usr/bin/ubinstall-gtk + true + + + diff --git a/source/ubinstall-gtk.c b/source/ubinstall-gtk.c index 30486e1..9c1d055 100644 --- a/source/ubinstall-gtk.c +++ b/source/ubinstall-gtk.c @@ -254,9 +254,17 @@ gboolean on_image_slide(void *data){ return 1; } -void *on_config_save(char *command); -void *on_config_save(char *command){ +void *on_config_save(void *); +void *on_config_save(void *){ + int size=0; + config_str parameters = yon_config_get_all(&size); + main_config.install_thread=(GThread*)0x1; + FILE *file = fopen(progress_path,"w"); + if (file) + fclose(file); + char *command = save_config_command(yon_char_parsed_to_string(parameters,size," ")); if (system(command)){}; + main_config.install_thread=(GThread*)0x0; main_config.config_save_thread=NULL; return NULL; } @@ -264,7 +272,7 @@ void *on_config_save(char *command){ void *yon_installation_start(main_window *widgets); void *yon_installation_start(main_window *widgets){ int code = system(start_fast_install_command); - main_config.install_thread=NULL; + // main_config.install_thread=NULL; main_config.install_complete=1; if (!code) gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_COMPLETION); @@ -275,21 +283,49 @@ void *yon_installation_start(main_window *widgets){ void *yon_installation_progress_update(void *data); void *yon_installation_progress_update(void *data){ - sleep(1); main_window *widgets = (main_window*)data; - FILE *file = fopen(progress_path,"r"); + FILE *file = NULL; char *current = g_malloc0(4096); - if (file){ - while (main_config.install_thread){ - current = fgets(current,4096,file); - if (current[0]!='#'){ - int size; - config_str parsed = yon_char_parse(current,&size,"|"); - gtk_label_set_text(GTK_LABEL(widgets->InstallationLabel),parsed[1]); - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widgets->InstallationProgress),atof(parsed[0])); + clock_t last_time = 0; + clock_t current_time; + while (main_config.install_thread){ + while (1){ + current_time = clock(); + if ((double)(current_time - last_time) / CLOCKS_PER_SEC >= 0.5){ + if (!file) + file = fopen(progress_path,"r"); + if (file){ + if (fgets(current,4096,file)){ + + } else { + if (!yon_char_is_empty(current)&¤t[0]=='('){ + char * current_copy = yon_char_new(current); + char *percentage = yon_char_divide_search(current_copy,")",-1); + free(yon_char_divide(current_copy,0)); + free(yon_char_divide(percentage,0)); + if (strcmp(percentage,"#pb")){ + double fraction = atof(percentage); + gtk_label_set_text(GTK_LABEL(widgets->InstallationLabel),current_copy); + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widgets->InstallationProgress),fraction/100); + } else { + int size; + config_str parsed = yon_char_parse(current_copy,&size," "); + double fraction = atof(parsed[3])/100; + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(widgets->PackageInstallationProgress),fraction/100); + parsed = yon_char_parsed_rip(parsed,&size,3); + gtk_label_set_text(GTK_LABEL(widgets->PackageInstallationLabel),yon_char_parsed_to_string(parsed,size," ")); + + } + last_time = current_time; + } + break; + } + } } - } + fclose(file); + file=NULL; + } return NULL; } @@ -324,8 +360,8 @@ void on_page_changed(GtkWidget *,GtkWidget *,int page, main_window *widgets){ gtk_widget_set_sensitive(widgets->BackButton,0); if (main_config.config_save_thread) g_thread_join(main_config.config_save_thread); - if (!main_config.install_thread&&!main_config.install_complete) - main_config.install_thread = g_thread_new("InstallThread",(GThreadFunc)yon_installation_start,widgets); + // if (!main_config.install_thread&&!main_config.install_complete) + // main_config.install_thread = g_thread_new("InstallThread",(GThreadFunc)yon_installation_start,widgets); if (!main_config.progress_thread) main_config.progress_thread = g_thread_new("ProgressThread",(GThreadFunc)yon_installation_progress_update,widgets); @@ -347,9 +383,8 @@ void on_page_changed(GtkWidget *,GtkWidget *,int page, main_window *widgets){ gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(GTK_BUTTON(widgets->NextButton))),"com.ublinux.libublsettingsui-gtk3.sync-symbolic",GTK_ICON_SIZE_BUTTON); gtk_image_set_from_icon_name(GTK_IMAGE(gtk_button_get_image(GTK_BUTTON(widgets->CancelInstallButton))),"com.ublinux.libublsettingsui-gtk3.reset-symbolic",GTK_ICON_SIZE_BUTTON); - int size=0; - config_str parameters = yon_config_get_all(&size); - main_config.config_save_thread = g_thread_new("savethread",(GThreadFunc)on_config_save,save_config_command(yon_char_parsed_to_string(parameters,size," "))); + pthread_t tid; + pthread_create(&tid,NULL,on_config_save,NULL); } break; case YON_PAGE_INSTALL_COMMON: @@ -481,7 +516,7 @@ void on_page_navigation_clicked(GtkWidget *self, main_window *widgets){ char *device; gtk_tree_model_get(model,&iter,0,&device,-1); yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"fast"); - yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_DEVICE_command,device); + yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,device); yon_config_register(device_label_parameter,device_label_parameter_command,device_name); yon_config_register(part_type_parameter,part_type_parameter_command,file_system_type); @@ -514,8 +549,8 @@ void on_page_navigation_clicked(GtkWidget *self, main_window *widgets){ char *part; gtk_tree_model_get(model,&iter,0,&part,-1); yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"next"); - yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_DEVICE_command,device); - yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOSTART_PARTS_command,part); + yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,device); + yon_config_register(AUTOSTART_PARTS,AUTOSTART_PARTS_command,part); yon_config_register(device_label_parameter,device_label_parameter_command,device_name); yon_config_register(part_type_parameter,part_type_parameter_command,file_system_type); if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->NextInstallationFormatCheck))) @@ -551,8 +586,8 @@ void on_page_navigation_clicked(GtkWidget *self, main_window *widgets){ char *part; gtk_tree_model_get(model,&iter,0,&part,-1); yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_TYPE_INSTALL_command,"part"); - yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOINSTALL_DEVICE_command,device); - yon_config_register(AUTOINSTALL_TYPE_INSTALL,AUTOSTART_PARTS_command,part); + yon_config_register(AUTOINSTALL_DEVICE,AUTOINSTALL_DEVICE_command,device); + yon_config_register(AUTOSTART_PARTS,AUTOSTART_PARTS_command,part); yon_config_register(device_label_parameter,device_label_parameter_command,device_name); yon_config_register(part_type_parameter,part_type_parameter_command,file_system_type); if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widgets->NextInstallationFormatCheck))) @@ -605,9 +640,8 @@ void on_page_navigation_clicked(GtkWidget *self, main_window *widgets){ gtk_widget_set_sensitive(widgets->BackButton,0); }break; case YON_PAGE_INSTALLATION_BEGIN:{ - int size=0; - config_str parameters = yon_config_get_all(&size); - main_config.config_save_thread = g_thread_new("savethread",(GThreadFunc)on_config_save,save_config_command(yon_char_parsed_to_string(parameters,size," "))); + pthread_t tid; + pthread_create(&tid,NULL,on_config_save,NULL); gtk_notebook_set_current_page(GTK_NOTEBOOK(widgets->Notebook),YON_PAGE_INSTALLATION); } break; case YON_PAGE_COMPLETION: diff --git a/source/ubinstall-gtk.h b/source/ubinstall-gtk.h index 6eba450..2c71335 100755 --- a/source/ubinstall-gtk.h +++ b/source/ubinstall-gtk.h @@ -71,7 +71,7 @@ NULL #define get_devices_command "lsblk --noheadings --nodeps -Jo PATH,SIZE,MODEL,VENDOR,SERIAL --exclude 7,253" #define get_parts_and_devices_command "lsblk --noheadings -Jo TYPE,PATH,SIZE,FSTYPE,LABEL,PARTLABEL,MOUNTPOINT,FSUSED,FSUSE% --exclude 7,253" -#define AUTOINSTALL_TYPE_INSTALL "AUTOINSTALL[type_install]" +#define AUTOINSTALL_TYPE_INSTALL "AUTOINSTALL[install_type]" #define AUTOINSTALL_DEVICE "AUTOINSTALL[device]" #define AUTOSTART_PARTS "AUTOINSTALL[part]" @@ -110,7 +110,7 @@ NULL #define part_type_parameter "AUTOINSTALL[part_type]" #define part_type_parameter_command "ubconfig --source global get [autoinstall] AUTOINSTALL[part_type]" -#define save_config_command(parameters) yon_char_append("pkexec ubconfig set [autoinstall] ",parameters) +#define save_config_command(parameters) yon_char_unite("pkexec bash -c 'ubconfig set [autoinstall] ",parameters, ";ubinstall2 --test --config /etc/ublinux/autoinstall'", NULL) #define AUTOINSTALL_TYPE_INSTALL_command "ubconfig --source global get autoinstall AUTOINSTALL[install_type]" #define AUTOINSTALL_DEVICE_command "ubconfig --source global get autoinstall AUTOINSTALL[device]" @@ -118,7 +118,7 @@ NULL #define start_fast_install_command "ubinstall2 --autoinstall" -#define progress_path "/tmp/ubinstall/ubinstall_progress.log" +#define progress_path "/var/log/ubinstall_progress.log" #define password_limits_path "/etc/security/pwquiality.conf" diff --git a/ubinstall-gtk.desktop b/ubinstall-gtk.desktop index 8b5dcb8..ed03562 100644 --- a/ubinstall-gtk.desktop +++ b/ubinstall-gtk.desktop @@ -1,12 +1,13 @@ [Desktop Entry] Version=2.35 Encoding=UTF-8 -Name=Установка UBLinux +Name=ubinstall-gtk +Name[ru]=Установка UBLinux Comment=ubinstall-gtk Comment[ru]=Установка UBLinux -Icon=ubinstall-gtk +Icon=com.ublinux.ubinstall-gtk Terminal=false Type=Application -Exec=/bin/ubinstall-gtk +Exec=pkexec /bin/ubinstall-gtk Categories=Settings;System; StartupNotify=true