forked from pink-mist/sbotools
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsbotool
More file actions
executable file
·1963 lines (1850 loc) · 88.3 KB
/
sbotool
File metadata and controls
executable file
·1963 lines (1850 loc) · 88.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl
# vim: ts=4:noet
#
# sbotool
# a dialog-based front-end for sbotools
#
# author: K. Eugene Carlson <kvngncrlsn@gmail.com>
# license: MIT License
use strict;
use warnings;
use SBO::Lib qw/ :colors :config :const :help auto_reverse check_multilib check_x32 check_x64 clear_info_store get_all_available get_available_updates get_build_queue get_from_info get_full_reverse get_installed_packages get_optional get_orig_location get_readme_contents get_reverse_reqs get_sbo_description get_sbo_location get_slack_version get_user_group in in_regexp ineligible_compat is_local lint_sbo_config on_blacklist prompt read_config read_hints renew_sbo_locations save_options script_error show_version slurp series_check solib_check uniq update_known_solibs user_group_do_not_exist %concluded @reverse_concluded %old_libs $repo_path $slackbuilds_txt $tmpd $tempdir $descriptions_generated %warnings /;
use File::Basename;
use File::Find;
use File::Path qw/ make_path remove_tree /;
use File::Temp qw/ tempdir /;
use Getopt::Long qw/ :config no_ignore_case_always /;
use Time::HiRes qw/ time /;
my $self = basename $0;
$is_sbotool = 1;
my $exit;
usage_error("dialog is not installed.") unless -x "/usr/bin/dialog";
my ($help, $show_version, $dialogrc, $config_menu);
GetOptions( 'help|h' => \$help, 'version|v' => \$show_version, 'dialogrc|d=s' => \$dialogrc, 'config' => \$config_menu);
if ($help) { show_usage(); exit 0; }
if ($show_version) { show_version(); exit 0; }
lint_sbo_config($self, %config);
my $version = $SBO::Lib::VERSION;
my $backtitle = "sbotools-$version";
$backtitle = $< == 0 ? "$backtitle (root mode)" : "$backtitle (normal user mode)";
my $dialog_base = "/usr/bin/dialog --keep-window --cancel-label \"Back\" --exit-label \"Back\" --backtitle \"$backtitle\"";
my $dialog_prefix = $dialog_base;
if (defined $dialogrc and -s $dialogrc) {
$dialog_prefix = "DIALOGRC=\"$dialogrc\" $dialog_prefix";
} else {
$dialog_prefix = ($config{DIALOGRC} ne "FALSE" and -s $config{DIALOGRC}) ? "DIALOGRC=\"$config{DIALOGRC}\" $dialog_prefix" : $dialog_prefix;
}
my $save_dialogrc = $config{DIALOGRC};
# Account for potential dialog-related environment variables.
my $code_dialog_ok = defined $ENV{"DIALOG_OK"} ? $ENV{"DIALOG_OK"} : 0;
my $code_dialog_cancel = defined $ENV{"DIALOG_CANCEL"} ? $ENV{"DIALOG_CANCEL"} : 1;
my $code_dialog_help = defined $ENV{"DIALOG_HELP"} ? $ENV{"DIALOG_HELP"} : 2;
my $code_dialog_item_help = defined $ENV{"DIALOG_ITEM_HELP"} ? $ENV{"DIALOG_ITEM_HELP"} : $code_dialog_help;
my $code_dialog_extra = defined $ENV{"DIALOG_EXTRA"} ? $ENV{"DIALOG_EXTRA"} : 3;
my $code_dialog_error = defined $ENV{"DIALOG_ERROR"} ? $ENV{"DIALOG_ERROR"} : -1;
my $overrides_available = 1 if $config{LOCAL_OVERRIDES} ne "FALSE" and -d -w $config{LOCAL_OVERRIDES};
my ($terminal_height, $terminal_width);
my $max_width = 125;
my ($normal, $wide, $narrow); # All set in terminal_check.
terminal_check();
dialog_check();
system("$dialog_prefix --infobox \"Loading...\" 3 15");
my $editor = $ENV{EDITOR};
$editor = $ENV{VISUAL} unless $editor;
# vi is in the POSIX standard and emacs, nano, etc. are not.
# That's the only reason.
$editor = "vi" unless $editor;
my (@available, $available, $all_fulldeps, @installed, $inst_pkgs, $inst_vers, %inst_names, $inst_pkgs_std, $inst_vers_std, %inst_names_std, $fulldeps, @installed_std, $updates, @update_names, @overrides);
my (@install_list, @template_list, @upgrade_list, @remove_list);
my (@solibs_missing, @incompatible_perl, @incompatible_python, @incompatible_ruby);
# Finding as much of this stuff as possible at the start
# gets the cache going a little and makes navigation snappier
# afterwards. "Loading..." takes less time after the first run.
if (-s $slackbuilds_txt) {
@available = get_all_available();
$available = +{ map {; $_, $_ } @available };
for (@available) { push @overrides, $_ if is_local($_); }
$all_fulldeps = get_reverse_reqs($available);
@installed = @{ get_installed_packages('SBO') };
$inst_pkgs = +{ map {; $_->{name}, $_->{pkg} } @installed };
$inst_vers = +{ map {; $_->{name}, $_->{version} } @installed };
$inst_names{$_->{name}} = $_ for @installed;
$fulldeps = get_reverse_reqs($inst_pkgs);
@installed_std = @{ get_installed_packages('STD') };
$inst_pkgs_std = +{ map {; $_->{name}, $_->{pkg} } @installed_std };
$inst_names_std{$_->{name}} = $_ for @installed_std;
$inst_vers_std = +{ map {; $_->{name}, $_->{version} } @installed_std };
$updates = $config{BUILD_IGNORE} eq "TRUE" ? get_available_updates("VERS") : get_available_updates("BOTH");
if ($updates) {
for (@$updates) { push @update_names, $_->{name} unless on_blacklist $_->{name}; }
}
}
# The temporary directory from Build.pm isn't needed; use
# a different one.
if ($< == 0) {
remove_tree($tempdir) if -d $tempdir;
}
my $sbotool_tempdir = tempdir(CLEANUP => 1, DIR => "/tmp");
my $dialog_input = "$sbotool_tempdir/dialog_input";
my $dialog_output = "$sbotool_tempdir/dialog_output";
my $dialog_exit = "$sbotool_tempdir/dialog_exit";
my $command_output = "$sbotool_tempdir/command_output";
unless ($config_menu) {
display_main();
} else {
display_settings();
}
# Once a script has been selected, build a menu of available
# operations and carry out the user's choice. Accepts the name
# of a SlackBuild (mandatory) and a non-zero value to view the
# second Operations menu.
sub build_operations {
script_error("build_operations requires at least one argument.") unless @_ >= 1;
my ($height, $width, $begin_y, $begin_x, $res, $output);
my ($sbo, $display_extras) = @_;
my $base_name = $sbo;
$base_name =~ s/-compat32$//;
my $options_file = "/var/log/sbotools/$base_name";
my $is_compat_build = $sbo =~ /-compat32$/;
my $compat = $is_compat_build ? $sbo : "$sbo-compat32";
splice @reverse_concluded;
unlink $command_output;
# In-tree SlackBuilds only.
my $location = get_sbo_location($sbo);
return unless $location;
my ($unsupported, $compat_possible);
if ($arch !~ /64/) {
$unsupported = check_x64 $location;
} elsif (check_multilib()) {
$compat_possible = 1 unless ineligible_compat $location;
} else {
$unsupported = check_x32 $location;
}
my $sbo_version = get_from_info(LOCATION => $location, GET => 'VERSION')->[0];
my $description = get_sbo_description($sbo);
$description = "(No Description)" unless defined $description;
$description =~ s/"/'/g;
$description =~ s/\$/\\\$/g;
# Top matter with basic information about the SlackBuild.
my $msg = "$sbo $sbo_version\n$description";
$msg .= "\nFound in local overrides." if is_local($sbo);
$msg .= "\nBlacklisted." if on_blacklist($sbo);
if (in $sbo, @update_names) {
$msg .= "\nUpgradable. ";
$msg .= $inst_vers->{$sbo} eq $sbo_version ? "(build bump)" : "($inst_vers->{$sbo} > $sbo_version)";
} else {
$msg .= "\nInstalled. ($inst_vers->{$sbo})" if $inst_names{$sbo};
}
$msg .= "\nInstalled, non-SBo. ($inst_vers_std->{$sbo})" if $inst_names_std{$sbo};
unless ($is_compat_build) {
$msg .= "\ncompat32 installed. ($inst_vers->{$compat})" if $inst_names{$compat};
}
$msg .= "\ncompat32 builds are unsupported by anyone in principle." if $is_compat_build;
$msg .= "\nUnsupported." if $unsupported;
$msg .= "\nOn the install list." if in $sbo, @install_list;
$msg .= "\nOn the template list." if in $sbo, @template_list;
$msg .= "\nOn the upgrade list." if in $sbo, @upgrade_list;
$msg .= "\nOn the remove list." if in $sbo, @remove_list;
$msg .= "\n\nRun as root for more functions." unless $< == 0;
# Reverse dependency and queue information.
my (@installed_reverse, @available_reverse, @pre_display);
@pre_display = get_full_reverse($sbo, $inst_pkgs, $fulldeps);
for (@pre_display) { push @installed_reverse, $_ if get_sbo_location($_); }
splice @pre_display;
splice @reverse_concluded;
@pre_display = get_full_reverse($sbo, $available, $all_fulldeps);
for (@pre_display) { push @available_reverse, $_ if get_sbo_location($_); }
my $queue = get_build_queue([$sbo]);
my @disp_queue;
unless ($is_compat_build) {
for (@$queue) { push @disp_queue, $_ if get_sbo_location($_) and $_ ne $sbo; }
} else {
for (@$queue) {
next unless my $dep_loc = get_sbo_location($_);
next if $_ =~ /-compat32/ and ineligible_compat $dep_loc;
push @disp_queue, $_ if $_ ne $sbo;
}
}
# @build_operations has the main options; @more_info is for others.
# Only options with potentially useful information or actions are
# displayed.
my (@build_operations, @more_info);
my @list_menu_tag;
if ($< == 0) {
push @list_menu_tag, "remove" if in $sbo, @remove_list;
push @list_menu_tag, "template" if in $sbo, @template_list;
push @list_menu_tag, "upgrade" if in $sbo, @upgrade_list;
push @list_menu_tag, "install" if in $sbo, @install_list;
unless (on_blacklist($sbo) or $unsupported) {
if ($inst_names{$sbo}) {
push @list_menu_tag, "remove", "template";
push @list_menu_tag, "upgrade" if in $sbo, @update_names;
} elsif (not $inst_names_std{$sbo}) {
push @list_menu_tag, "install", "template";
} else {
push @list_menu_tag, "template";
}
}
if (@list_menu_tag) {
@list_menu_tag = uniq @list_menu_tag;
my $list_menu_tag = @list_menu_tag == 4 ? "For list operations." : "For " . join(", ", @list_menu_tag) . ".";
push @build_operations, "\"Lists\" \"$list_menu_tag\" \\";
}
} else {
if (in $sbo, @template_list) {
push @build_operations, "\"Template List (-)\" \"Clear from the Template List.\" \\";
} else {
push @build_operations, "\"Template List (+)\" \"Add to the Template List.\" \\" unless on_blacklist($sbo) or $unsupported;
}
}
if ($compat_possible and not $is_compat_build) {
push @build_operations, "\"compat32\" \"Select -compat32 operations.\" \\" if $inst_names{$compat};
push @more_info, "\"compat32\" \"Select -compat32 operations.\" \\" unless $inst_names{$compat};
}
push @build_operations, "\"View File\" \"View any file in the script directory.\" \\";
push @build_operations, "\"RevDep (installed)\" \"Dependent packages on the system.\" \\" if @installed_reverse;
push @more_info, "\"RevDep (all)\" \"All dependent packages in the repo.\" \\" if @available_reverse;
if (on_blacklist($sbo) or auto_reverse($sbo) or get_optional($sbo) and $< != 0) {
push @build_operations, "\"Hints\" \"View package hints.\" \\";
}
unless (on_blacklist($sbo)) {
push @more_info, "\"Queue\" \"Select from the build queue.\" \\" if @disp_queue;
push @more_info, "\"Dry Run (reverse)\" \"How reverse deps would be rebuilt.\" \\" if $inst_names{$sbo} and @installed_reverse;
unless ($inst_names_std{$sbo} or $unsupported) {
my $built_or_upgraded;
if (in $sbo, @update_names) {
$built_or_upgraded = "upgraded";
} elsif ($inst_names{$sbo}) {
$built_or_upgraded = "rebuilt";
} else {
$built_or_upgraded = "built";
}
push @build_operations, "\"Dry Run\" \"How this package would be $built_or_upgraded.\" \\";
}
}
my ($uid_gid, $missing_uid_gid);
if (-s $options_file) {
chomp(my $saved_opts = slurp $options_file);
$uid_gid = get_user_group($sbo, $location, $saved_opts);
$missing_uid_gid = user_group_do_not_exist(@$uid_gid) if @$uid_gid;
if ($< == 0) {
push @build_operations, "\"Build Options\" \"Edit saved build options.\" \\";
push @build_operations, "\"UID/GID\" \"Add missing user and/or group.\" \\" if defined $missing_uid_gid and @$missing_uid_gid;
} else {
push @build_operations, "\"Build Options\" \"View saved build options.\" \\";
push @build_operations, "\"UID/GID\" \"View missing user and/or group.\" \\" if defined $missing_uid_gid and @$missing_uid_gid;
}
} else {
$uid_gid = get_user_group($sbo, $location);
$missing_uid_gid = user_group_do_not_exist(@$uid_gid) if @$uid_gid;
if ($< == 0) {
push @build_operations, "\"Build Options\" \"Save build options.\" \\";
push @build_operations, "\"UID/GID\" \"Add missing user and/or group.\" \\" if defined $missing_uid_gid and @$missing_uid_gid;
} else {
push @build_operations, "\"UID/GID\" \"View missing user and/or group.\" \\" if defined $missing_uid_gid and @$missing_uid_gid;
}
}
push @more_info, "\"Add Override\" \"Make a local override copy for editing.\" \\" if $overrides_available and not is_local($sbo);
if (is_local($sbo) and $overrides_available) {
push @build_operations, "\"Edit Override\" \"\\\$EDITOR, \\\$VISUAL or vi, in that order.\" \\";
push @more_info, "\"Remove Override\" \"Delete the script from local overrides.\" \\";
}
push @more_info, "\"Package Tests\" \"Check solibs, perl, python and ruby.\" \\" if $inst_names{$sbo} or $inst_names_std{$sbo};
push @build_operations, "\"Edit Hints\" \"Blacklist, auto-rebuild and dependencies.\" \\" if $< == 0;
if ($inst_names{$sbo} and $< == 0 and not on_blacklist($sbo)) {
push @build_operations, "\"Remove\" \"Remove with unneeded dependencies.\" \\";
if (in $sbo, @update_names) {
push @build_operations, "\"Upgrade\" \"Upgrade the package.\" \\";
push @more_info, "\"Upgrade (reverse)\" \"Upgrade and rebuild reverse deps.\" \\" if @installed_reverse;
} else {
push @more_info, "\"Reverse Rebuild\" \"Rebuild all reverse deps.\" \\" if @installed_reverse;
if (@disp_queue) {
push @build_operations, "\"Reinstall\" \"Reinstall package and deps (optional).\" \\";
} else {
push @build_operations, "\"Reinstall\" \"Reinstall package.\" \\";
}
}
} elsif ($< == 0 and not $inst_names_std{$sbo} and not $unsupported and not on_blacklist($sbo)) {
push @build_operations, "\"Install\" \"Install the package.\" \\";
}
if ($< == 0 and $inst_names_std{$sbo} and not $unsupported and not on_blacklist($sbo)) {
push @build_operations, "\"Replace\" \"Reinstall from SBo; batch unavailable.\" \\";
}
# Don't bother hiding extras unless there are at least
# nine items total and two "less-common" items.
my $array_sum = @more_info + @build_operations;
my $extra_ops = @more_info;
if (($array_sum < 9 or @more_info < 2) and not defined $display_extras) {
push @build_operations, @more_info;
splice @more_info;
}
my $build_operations;
if (defined $display_extras and @more_info) {
@more_info = sort @more_info;
push @build_operations, @more_info;
}
@build_operations = sort @build_operations;
if (@more_info) {
if (defined $display_extras) {
push @build_operations, "\"less\" \"Show $extra_ops fewer operations.\" \\";
} else {
push @build_operations, "\"more\" \"Show $extra_ops more operations.\" \\" if @more_info;
}
}
$build_operations[-1] =~ s/\\$//;
$build_operations = join "\n", @build_operations;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $build_operations, $msg);
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --extra-button --extra-label \"Main\" --title \"$sbo Operations\" --menu \"$msg\" $height $width $height $build_operations", @help_operations);
return if $res == $code_dialog_cancel or $res == $code_dialog_error;
display_main() if $res == $code_dialog_extra;
my $option = $output;
return unless $option;
if ($option eq "more") { build_operations($sbo, 1); }
if ($option eq "less") { return; }
if ($option eq "compat32") { build_operations($compat); }
if ($option eq "Add Override") {
unless (-l "$config{LOCAL_OVERRIDES}/$sbo" or -f "$config{LOCAL_OVERRIDES}/$sbo" or is_local $sbo) {
make_path("$config{LOCAL_OVERRIDES}") unless -d $config{LOCAL_OVERRIDES};
system("cp -r $location $config{LOCAL_OVERRIDES}") unless -l "$config{LOCAL_OVERRIDES}/$sbo" or -f "$config{LOCAL_OVERRIDES}/$sbo" or is_local $sbo;
clear_info_store();
new_package_information();
}
if (-l "$config{LOCAL_OVERRIDES}/$sbo" or -f "$config{LOCAL_OVERRIDES}/$sbo") {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", "Non-directory\n\nAdd");
system("$dialog_prefix --begin $begin_y $begin_x --ok-label \"Back\" --msgbox \"A non-directory exists at $config{LOCAL_OVERRIDES}/$sbo.\n\nRemove it before adding to Local Overrides.\" $height $width");
}
}
if ($option eq "Dry Run" or $option eq "Dry Run (reverse)") {
unlink $command_output;
if ($option eq "Dry Run (reverse)") {
system("/usr/sbin/sboinstall --wrap --nocolor -D --reverse-rebuild $sbo > $command_output");
} else {
if (in $sbo, @update_names) {
system("/usr/sbin/sboupgrade --wrap --nocolor -D $sbo > $command_output");
} elsif ($inst_names{$sbo}) {
system("/usr/sbin/sboinstall --reinstall --wrap --nocolor -D $sbo > $command_output");
} else {
system("/usr/sbin/sboinstall --wrap --nocolor -D $sbo > $command_output");
}
}
my $check = slurp $command_output;
if ($check =~ /\w/) {
($height, $width, $begin_y, $begin_x) = calculate_position("wide_cond", $check);
system("$dialog_prefix --begin $begin_y $begin_x --title \"$sbo: Dry Run\" --textbox $command_output $height $width");
}
}
if ($option eq "Edit Hints") { edit_hint($sbo); }
# Root can edit build options; others can only view.
if ($option eq "Build Options" and $< != 0) {
my $build_options = slurp $options_file if -s $options_file;
if ($build_options) {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $build_options, "Run as root\n\n");
system("DIALOG_CANCEL=$code_dialog_help $dialog_prefix --begin $begin_y $begin_x --ok-label \"Back\" --title \"$sbo: Saved Build Options\" --msgbox \"Run as root to edit build options.\n\n$build_options\" $height $width", @help_options);
}
}
if ($option eq "Build Options" and $< == 0) {
my $orig_options = slurp $options_file if -s $options_file;
$orig_options =~ s/"/\\\"/g if defined $orig_options;
my $no_remove;
if ($orig_options) {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $orig_options, "Remove?\n\n");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --yes-label \"Edit\" --no-label \"Back\" --extra-button --extra-label \"Clear\" --title \"$options_file\" --yesno \"Edit or clear build options for $base_name?\n\n$orig_options\" $height $width", @help_options);
$no_remove = $res;
if ($no_remove == $code_dialog_extra) {
unlink $options_file;
($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "Options cleared");
system("$dialog_prefix --begin $begin_y $begin_x --msgbox \"Cleared options for $sbo.\" $height $width") unless -s $options_file;
build_operations($sbo, $display_extras);
return;
} elsif ($no_remove == $code_dialog_cancel) {
build_operations($sbo, $display_extras);
return;
}
}
if (defined $no_remove or not $orig_options) {
my $disp_options = $orig_options if $orig_options;
BACK: if (defined $disp_options) { # Retain the text box after viewing README.
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $orig_options, "Current\n\nInput here\n\nLeave blank");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --extra-button --extra-label \"README\" --title \"$sbo: Build Options\" --inputbox \"Enter build options for $sbo in the form VAR=VALUE.\n\n$orig_options\n\nLeave blank to retain existing options.\" $height $width \"$disp_options\"", @help_options);
} else {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", "Enter build\n\nInput here");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --extra-button --extra-label \"README\" --title \"$sbo: Build Options\" --inputbox \"Enter build options for $sbo in the form VAR=VALUE.\" $height $width", @help_options);
}
# Definitely don't want to continue in this case.
if ($res == $code_dialog_cancel or $res == $code_dialog_error) {
build_operations($sbo, $display_extras);
return;
}
my $new_options = $output;
if ($new_options =~ /\w/) {
$disp_options = $new_options;
$disp_options =~ s/"/\\\"/g;
}
if ($res == $code_dialog_extra) {
my $readme = get_readme_contents($location);
($height, $width, $begin_y, $begin_x) = calculate_position("normal", $readme);
system("$dialog_prefix --ok-label \"Back\" --begin $begin_y $begin_x --title \"$sbo: README\" --msgbox \"$readme\" $height $width");
goto BACK;
}
if ($new_options =~ /\w/ and $new_options ne $orig_options) {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", "success or fail");
unless (save_options($sbo, $new_options)) {
system("$dialog_prefix --begin $begin_y $begin_x --title \"Failure\" --msgbox \"Saving options failed for $sbo.\" $height $width");
} else {
system("$dialog_prefix --begin $begin_y $begin_x --title \"Success\" --msgbox \"Saved build options for $sbo.\" $height $width");
}
}
}
}
if ($option eq "Hints") {
unlink $command_output;
system("/usr/sbin/sbohints --wrap --nocolor -q $sbo > $command_output");
my $check = slurp $command_output;
if ($check =~ /\w/) {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $check);
do_dialog("DIALOG_CANCEL=$code_dialog_help $dialog_prefix --begin $begin_y $begin_x --title \"$sbo: Hints\" --textbox $command_output $height $width", @help_hints);
} else {
($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "No hints found");
do_dialog("DIALOG_CANCEL=$code_dialog_help $dialog_prefix --begin $begin_y $begin_x --ok-label \"Back\" --msgbox \"No hints found for $sbo.\" $height $width", @help_hints);
}
}
if ($option eq "Install" or $option eq "Reinstall" or $option eq "Remove" or $option eq "Reverse Rebuild") {
my $cmd = "/usr/sbin/sboinstall";
# The user can decide whether to reinstall dependencies or not.
if ($option eq "Reinstall") {
if (@disp_queue) {
my $disp_queue = join "\n", @disp_queue;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", "Reinstall deps?\n\n", $disp_queue);
($res, $output) = do_dialog("$dialog_prefix --title \"Reinstalling $sbo\" --yesno \"Also reinstall dependencies?\n\n$disp_queue\" $height $width");
$cmd .= " --norequirements" if $res == $code_dialog_cancel;
}
}
$cmd .= " --reinstall" if $option eq "Reinstall";
$cmd .= " --reverse-rebuild" if $option eq "Reverse Rebuild";
$cmd .= " $sbo";
$cmd = $option eq "Remove" ? "/usr/sbin/sboremove $sbo" : $cmd;
run_command($cmd);
}
# @list_menu_tag indicates whether the SlackBuild makes sense in a
# given list.
if ($option eq "Lists") {
my @lists;
if (in $sbo, @install_list) {
push @lists, "\"Install List (-)\" \"Clear from Install List.\" \"off\" \\";
} else {
push @lists, "\"Install List (+)\" \"Add to Install List.\" \"off\" \\" if in "install", @list_menu_tag;
}
if (in $sbo, @remove_list) {
push @lists, "\"Remove List (-)\" \"Clear from Remove List.\" \"off\" \\";
} else {
push @lists, "\"Remove List (+)\" \"Add to Remove List.\" \"off\" \\" if in "remove", @list_menu_tag;
}
if (in $sbo, @template_list) {
push @lists, "\"Template List (-)\" \"Clear from Template List.\" \"off\" \\";
} else {
push @lists, "\"Template List (+)\" \"Add to Template List.\" \"off\" \\" if in "template", @list_menu_tag;
}
if (in $sbo, @upgrade_list) {
push @lists, "\"Upgrade List (-)\" \"Clear from Upgrade List.\" \"off\" \\";
} else {
push @lists, "\"Upgrade List (+)\" \"Add to Upgrade List.\" \"off\" \\" if in "upgrade", @list_menu_tag;
}
$lists[-1] =~ s/\\$//;
my $lists = join "\n", @lists;
my $list_option;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $lists, "Choose one or more options.");
($res, $list_option) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"$sbo: List Management\" --checklist \"Choose one or more options.\" $height $width $height $lists", @help_list_mgmt);
if ($res == $code_dialog_cancel or $res == $code_dialog_error) {
build_operations($sbo, $display_extras);
return;
}
my @list_options = split "\n", $list_option;
if (in "Install List (+)", @list_options) { push @install_list, $sbo; }
if (in "Template List (+)", @list_options) { push @template_list, $sbo; }
if (in "Upgrade List (+)", @list_options) { push @upgrade_list, $sbo; }
if (in "Remove List (+)", @list_options) { push @remove_list, $sbo; }
if (in "Install List (-)", @list_options) { @install_list = grep { !/^\Q$sbo\E$/ } @install_list; }
if (in "Template List (-)", @list_options) { @template_list = grep { !/^\Q$sbo\E$/ } @template_list; }
if (in "Upgrade List (-)", @list_options) { @upgrade_list = grep { !/^\Q$sbo\E$/ } @upgrade_list; }
if (in "Remove List (-)", @list_options) { @remove_list = grep { !/^\Q$sbo\E$/ } @remove_list; }
}
if ($option eq "Package Tests") {
my $solib_check_pkg = $inst_names{$sbo} ? $inst_pkgs->{$sbo} : $inst_pkgs_std->{$sbo};
my $msg;
my $compatibility_ok = 1;
unless (solib_check($solib_check_pkg)) {
$msg .= "Missing shared objects found for $sbo:\n\n$old_libs{$solib_check_pkg}";
$msg .= "\nPlease note that precompiled binaries do not require rebuilds.";
push @solibs_missing, $sbo unless in $sbo, @solibs_missing;
} else {
$msg .= "No missing shared objects found.";
}
my @series_check_res = series_check($solib_check_pkg, "perl", "python", "ruby");
unless ($series_check_res[0]) {
$compatibility_ok = 0;
$msg .= "\n\nIncompatible with system perl.";
push @incompatible_perl, $sbo unless in $sbo, @incompatible_perl;
}
unless ($series_check_res[1]) {
$compatibility_ok = 0;
$msg .= "\n\nIncompatible with system python.";
push @incompatible_python, $sbo unless in $sbo, @incompatible_python;
}
unless ($series_check_res[2]) {
$compatibility_ok = 0;
$msg .= "\n\nIncompatible with system ruby.";
push @incompatible_ruby, $sbo unless in $sbo, @incompatible_ruby;
}
$msg .= "\n\nTests passed for perl, python and ruby." if $compatibility_ok;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $msg);
system("$dialog_prefix --begin $begin_y $begin_x --ok-label \"Back\" --no-collapse --title \"$sbo: Package Tests\" --msgbox \"$msg\" $height $width");
}
# The Queue option does not appear if it is a queue of one.
if ($option eq "Queue") { display_builds("$sbo: Available Queue", @disp_queue); }
if ($option eq "Remove Override") {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", "Remove?");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --yesno \"Remove $sbo from the Local Overrides directory?\" $height $width");
if ($res == $code_dialog_ok) {
remove_tree($location);
clear_info_store();
new_package_information();
$location = get_sbo_location($sbo);
unless ($location) {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", "No longer");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --msgbox \"$sbo is no longer available.\" $height $width");
}
}
}
if ($option eq "Replace") {
my $cmd = "/usr/bin/sboinstall --reinstall $sbo";
run_command($cmd, 1);
}
if ($option eq "RevDep (all)") { display_builds("$sbo: Available Reverse Dependencies", @available_reverse); }
if ($option eq "RevDep (installed)") { display_builds("$sbo: Installed Reverse Dependencies", @installed_reverse); }
if ($option eq "Template List (+)") { push @template_list, $sbo; }
if ($option eq "Template List (-)") { @template_list = grep { !/^\Q$sbo\E$/ } @template_list; }
if ($option eq "UID/GID") {
return unless defined $missing_uid_gid and @$missing_uid_gid;
my $uid_gid_msg = "This SlackBuild requires one or more missing users and groups:\n\n";
$uid_gid_msg .= " # $_\n" for (@$missing_uid_gid);
$uid_gid_msg .= "\nRun the command(s) now?" if $< == 0;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $uid_gid_msg);
if ($< == 0) {
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"Missing Users and Groups\" --yesno \"$uid_gid_msg\" $height $width");
if ($res == $code_dialog_ok) {
system("clear");
for (@$missing_uid_gid) {
print " $_\n";
system($_);
}
prompt $color_notice, "Press ENTER to continue.";
}
} else {
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"Missing Users and Groups\" --msgbox \"$uid_gid_msg\" $height $width");
}
}
if ($option =~ /^Upgrade/) {
my $cmd = "/usr/sbin/sboupgrade";
$cmd .= " --reverse-rebuild" if $option =~ /reverse/;
$cmd .= " $sbo";
run_command($cmd);
}
# Text files in the SlackBuild directory.
if ($option eq "View File" or $option eq "Edit Override") {
my (@file_list, %file_locations, @display_list);
FILES: splice @file_list;
splice @display_list;
%file_locations = ();
unlink $dialog_output;
find({ wanted => sub { push @file_list, $_ if -T $_ }, no_chdir => 1 }, $location);
my $file_list = join "\n", @file_list;
for (@file_list) {
my $base = basename $_;
$file_locations{$base} = $_;
push @display_list, "\"$base\" \"\"";
}
@display_list = sort @display_list;
my $display_list = join " ", @display_list;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $file_list, "Select a");
if ($option eq "View File") {
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"View File\" --menu \"Select a text file to read it.\" $height $width $height $display_list");
} else {
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --extra-button --extra-label \"Delete\" --title \"Edit File\" --menu \"Select a text file to edit it.\" $height $width $height $display_list");
}
my $file = $output;
if ($option eq "View File" and $file =~ /\w/) {
chomp(my $file_text = slurp $file_locations{$file});
my $wanted = $file =~ /^README/ ? "normal" : "wide";
($height, $width, $begin_y, $begin_x) = calculate_position($wanted, $file_text);
system("$dialog_prefix --begin $begin_y $begin_x --title \"$file\" --textbox $file_locations{$file} $height $width");
goto FILES;
} elsif ($option eq "Edit Override" and $file =~ /\w/) {
unless (-w $file_locations{$file}) {
($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "no write\nselect");
system("$dialog_prefix --begin $begin_y $begin_x --title \"$file\" --msgbox \"No write permissions.\n\nSelect another file.\" $height $width");
goto FILES;
}
if ($res == $code_dialog_extra) {
if ($file eq "$base_name.info") {
($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "needed\nuse");
system("$dialog_prefix --begin $begin_y $begin_x --title \"$file\" --msgbox \"$file cannot be deleted here.\n\nUse Remove Override.\" $height $width");
goto FILES;
}
($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "delete?");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"$file\" --yesno \"Really delete $file?\" $height $width");
unlink $file_locations{$file} if $res == $code_dialog_ok;
goto FILES;
}
system("$editor $file_locations{$file}");
clear_info_store();
new_package_information();
goto FILES;
}
}
build_operations($sbo, $display_extras);
return;
}
# Calculate an appropriate size and position for a dialog window based on
# the dimensions of the terminal window and the contents.
#
# In case the difference between the rows in the terminal and the height
# is odd, leave more space at the top. Horizontal space needs no adjustment
# because the difference is always even.
sub calculate_position {
script_error("calculate_position requires at least two arguments; exiting.") unless @_;
my $max_height = terminal_check();
my $wanted_width = shift;
my ($contents, $msg) = @_;
my $height = $contents =~ tr/\n//;
$height++ unless $contents =~ m/\n$/;
if (defined $msg) {
$height += $msg =~ tr/\n//;
$height++ unless $msg =~ m/\n$/;
}
$height += 5;
$height = $height > $max_height ? $max_height : $height;
my $width;
if ($wanted_width eq "wide") {
$width = $wide;
} elsif ($wanted_width eq "normal") {
$width = $normal;
} elsif ($wanted_width eq "narrow") {
$width = $narrow;
} elsif ($wanted_width eq "wide_cond") {
$width = $normal < $wide ? $wide : $normal;
} elsif ($wanted_width eq "normal_cond") {
$width = $normal < $wide ? $normal : $wide;
}
script_error("Bad value of wanted_width passed to calculate_position.") unless defined $width;
my $begin_y;
if ($height < $max_height) {
$begin_y = int(($terminal_height - $height) / 2);
} else {
$begin_y = int(0.5 + ($terminal_height - $height) / 2);
}
my $begin_x = int(($terminal_width - $width) / 2);
return ($height, $width, $begin_y, $begin_x);
}
# Ensure that a provided dialogrc file is not malformed.
sub dialog_check {
unlink $dialog_exit;
my ($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "Checking...");
system("$dialog_prefix --begin $begin_y $begin_x --infobox \"Checking dialogrc...\" $height $width > /dev/null ; echo \$? > $dialog_exit");
chomp(my $res = slurp $dialog_exit);
if ($res == $code_dialog_error) {
($height, $width, $begin_y, $begin_x) = calculate_position("normal_cond", "Checking...");
system("dialog --begin $begin_y $begin_x --msgbox \"The provided dialogrc is malformed. Using the system default.\" $height $width") unless $config{DIALOGRC} eq "FALSE";
$config{DIALOGRC} = "FALSE";
undef $dialogrc;
$dialog_prefix = $dialog_base;
}
}
# Given an array with SlackBuilds of interest, add descriptions,
# sort and get user input.
sub display_builds {
script_error("display_builds requires two arguments.") unless @_ > 1;
my ($label, @array_to_use) = @_;
my ($height, $width, $begin_y, $begin_x, $res, $output);
my @for_dialog;
for my $sbo (@array_to_use) {
next unless get_sbo_location($sbo);
my $description = get_sbo_description($sbo);
$description = "(No Description)" unless defined $description;
$description =~ s/"/'/g;
$description = is_local($sbo) ? "(LOCAL) $description" : $description unless $label =~ /Overrides/;
$description = $inst_names_std{$sbo} ? "(NON-SBO) $description" : $description;
if (in $sbo, @update_names) {
my $sbo_version = get_from_info(LOCATION => get_sbo_location($sbo), GET => 'VERSION')->[0];
my $upgrade_description = $inst_vers->{$sbo} eq $sbo_version ? "(build bump)" : "($inst_vers->{$sbo} > $sbo_version)";
$description = "$upgrade_description $description";
}
push @for_dialog, "\"$sbo\" \"$description\" \"$description\" \\";
}
@for_dialog = sort @for_dialog unless $label =~ /(Available Queue|Search Results|Filtered\))$/;
my $for_dialog = join "\n", @for_dialog;
my $fh;
open $fh, ">", $dialog_input or error_code("Failed to open $dialog_input for write.", _ERR_OPENFH);
print {$fh} $for_dialog;
close $fh;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $for_dialog, "Select a SlackBuild");
$height--;
my $do_filter;
if ($label =~ /(Missing|Perl|Python|Ruby)/ and $< == 0) {
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $for_dialog, "Select a SlackBuild\n\nuse\n\nplease");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --extra-button --extra-label \"Reinstall\" --title \"$label\" --item-help --menu \"Select a SlackBuild for more options.\n\nUse Reinstall to reinstall everything on the list.\n\nPlease note that precompiled binaries do not require rebuilds.\" $height $width $height --file $dialog_input", @help_builds_fail_menu);
if ($res == $code_dialog_extra) {
my $cmd = "/usr/sbin/sboinstall --reinstall";
my $need_dependency_prompt = 0;
for my $missing (@array_to_use) {
my $queue = get_build_queue([$missing]);
my @disp_queue;
unless ($missing =~ /compat32$/) {
for (@$queue) { push @disp_queue, $_ if get_sbo_location($_) and $_ ne $missing; }
} else {
for (@$queue) {
next unless my $dep_loc = get_sbo_location($_);
next if $_ =~ /-compat32/ and ineligible_compat $dep_loc;
push @disp_queue, $_ if $_ ne $missing;
}
}
if (@disp_queue) {
$need_dependency_prompt = 1;
last;
}
}
if ($need_dependency_prompt) {
($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "Dependencies?");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"Rebuild Dependencies?\" --yesno \"Also rebuild dependencies?\" $height $width");
$cmd .= " --norequirements" unless $res == $code_dialog_ok;
}
run_command("$cmd @array_to_use");
return;
}
} elsif (@array_to_use > 1) {
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --extra-button --extra-label \"Filter\" --title \"$label\" --item-help --menu \"Select a SlackBuild for more options.\" $height $width $height --file $dialog_input", @help_builds);
# Run a secondary search on the results if the user presses the
# "Filter" button.
$do_filter = 1 if $res == $code_dialog_extra;
} else {
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"$label\" --item-help --menu \"Select a SlackBuild for more options.\" $height $width $height --file $dialog_input", @help_builds);
}
my $option = $output;
return unless $option;
if (defined $do_filter) {
run_search($label, @array_to_use);
} else {
build_operations($option);
}
display_builds($label, @array_to_use);
return;
}
# An interface for sboclean.
sub display_clean_menu {
my (@clean_menu, $has_distfiles, $has_options, $has_working);
my ($height, $width, $begin_y, $begin_x, $res, $output);
if (-d "$config{SBO_HOME}/distfiles") {
opendir(my $handle, "$config{SBO_HOME}/distfiles");
while (my $dir = readdir $handle) {
unless (in_regexp($dir => qw/ . .. /)) { $has_distfiles = 1; last; }
}
}
if (-d "$tmpd") {
opendir(my $handle, $tmpd);
while (my $dir = readdir $handle) {
unless (in_regexp($dir => qw/ . .. /)) { $has_working = 1; last; }
}
}
if (-d "/var/log/sbotools") {
opendir(my $handle, "/var/log/sbotools");
while (my $dir = readdir $handle) {
unless (in_regexp($dir => qw/ . .. /)) { $has_options = 1; last; }
}
}
push @clean_menu, "\"Distfiles\" \"Downloaded source files.\" \"off\" \\" if $has_distfiles;
push @clean_menu, "\"Options\" \"Per-script build options.\" \"off\" \\" if $has_options;
push @clean_menu, "\"Working\" \"Working directories.\" \"off\" \\" if $has_working;
$clean_menu[-1] =~ s/\\$//;
my $clean_menu = join "\n", @clean_menu;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $clean_menu, "At least one");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"sboclean\" --checklist \"At least one option must be checked.\" $height $width $height $clean_menu", @help_clean);
return if $res == $code_dialog_cancel or $res == $code_dialog_error;
my $options = $output;
return unless $options =~ /\w/;
my @options = split "\n", $options;
my $cmd = "/usr/sbin/sboclean";
$cmd .= " -d" if in "Distfiles", @options;
$cmd .= " -w" if in "Working", @options;
if (in "Options", @options) {
my @with_options;
for (glob "/var/log/sbotools/*") {
next unless -T $_;
my $name = basename($_);
push @with_options, "\"$name\" \"\" \\";
}
unless (@with_options) {
($height, $width, $begin_y, $begin_x) = calculate_position("narrow", "one line");
system("$dialog_prefix --begin $begin_y $begin_x --title \"sboclean\" --msgbox \"No text files found in /var/log/sbotools.\" $height $width");
return;
}
@with_options = sort @with_options;
push @with_options, "\"\" \"\" \\", "\"ALL\" \"Clear all saved options.\"" if @with_options > 1;
$with_options[-1] =~ s/\\$// if @with_options;
my $with_options = join "\n", @with_options;
BACK: ($height, $width, $begin_y, $begin_x) = calculate_position("wide", $with_options, "Choose one");
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --title \"sboclean\" --menu \"Choose one script for option clearing, or ALL.\" $height $width $height $with_options");
return if $res == $code_dialog_cancel or $res == $code_dialog_error;
my $script_choice = $output;
goto BACK unless $script_choice =~ /\w/;
$cmd .= " -o $script_choice";
}
run_command($cmd);
display_main();
}
# Select and read a man page.
sub display_man_pages {
unlink $dialog_output;
my @man_pages;
push @man_pages, "\"sbotools\" \"Executive summaries of all tools.\" \\",
"\"sbotool\" \"The man page for this utility.\" \\",
"\"sbocheck\" \"Update the repo and perform checks.\" \\",
"\"sboclean\" \"Remove sbotools-related cruft.\" \\",
"\"sboconfig\" \"A command line settings manager.\" \\",
"\"sbofind\" \"Search the local repo for SlackBuilds.\" \\",
"\"sbohints\" \"Query and modify per-script hints.\" \\",
"\"sboinstall\" \"Install SlackBuilds and dependencies.\" \\",
"\"sboremove\" \"Interactively remove SlackBuilds.\" \\",
"\"sboupgrade\" \"Upgrade SBo SlackBuilds.\" \\",
"\"sbotools.colors\" \"Customize sbotools output colors.\" \\",
"\"sbotools.conf\" \"Set the configuration with this file.\" \\",
"\"sbotools.hints\" \"Set hints with this file.\"";
my $man_pages = join "\n", @man_pages;
my $msg = "Each of the scripts in sbotools can run independently from the command line.\n\nSee the man pages for further details.";
my ($height, $width, $begin_y, $begin_x) = calculate_position("wide", $man_pages, $msg);
system("$dialog_prefix --begin $begin_y $begin_x --title \"Man Pages\" --menu \"$msg\" $height $width $height $man_pages 2> $dialog_output");
chomp(my $option = slurp $dialog_output);
return unless $option =~ /\w/;
system("man $option");
display_man_pages();
return;
}
# Setting up and displaying the main menu; the setup is similar to
# build_operations() above; determine efficacious settings and push
# them to a menu array.
sub display_main {
my @main_menu;
my ($height, $width, $begin_y, $begin_x, $res, $output);
if ($< == 0) {
push @main_menu, "\"Settings\" \"View and edit sbotools settings.\" \\";
} else {
push @main_menu, "\"Settings\" \"View sbotools settings.\" \\";
}
my @list_message;
my $list_string;
push @list_message, "install" if @install_list;
push @list_message, "make template" if @template_list;
push @list_message, "upgrade" if @upgrade_list;
push @list_message, "remove" if @remove_list;
if (@list_message == 4) {
$list_string = "install, make template, upgrade or remove";
} elsif (@list_message == 3) {
$list_string = "$list_message[0], $list_message[1] or $list_message[2]";
} elsif (@list_message == 2) {
$list_string = "$list_message[0] or $list_message[1]";
} elsif (@list_message == 1) {
$list_string = $list_message[0];
}
push @main_menu, "\"List Operations\" \"Act on the $list_string list.\" \\" if $list_string;
push @main_menu, "\"Hints\" \"View per-script hints.\" \\" if $listings[0] ne "NULL";
push @main_menu, "\"Missing Solibs\" \"Packages with known-missing solibs.\" \\" if @solibs_missing;
push @main_menu, "\"Perl\" \"Incompatible perl packages.\" \\" if @incompatible_perl;
push @main_menu, "\"Python\" \"Incompatible python packages.\" \\" if @incompatible_python;
push @main_menu, "\"Ruby\" \"Incompatible ruby packages.\" \\" if @incompatible_ruby;
push @main_menu, "\"Man Pages\" \"Read sbotools-related man pages.\" \\";
push @main_menu, "\"Package Tests\" \"Solibs, perl, python and ruby checks.\" \\";
my @for_installed_list;
if (-s $slackbuilds_txt) {
push @main_menu, "\"Browse Repository\" \"View scripts by series.\" \\";
if (-s "$config{SBO_HOME}/repo/TAGS.txt") {
push @main_menu, "\"Package Search\" \"Search by name, tag and description.\" \\";
} else {
push @main_menu, "\"Package Search\" \"Search by name and description.\" \\";
}
@for_installed_list = keys %inst_names if keys %inst_names;
for (keys %inst_names_std) {
push @for_installed_list, $_ if get_sbo_location($_);
}
push @main_menu, "\"Installed\" \"List installed SBo packages.\" \\",
"\"Rebuilds\" \"Mass and per-series rebuilds.\" \\" if @for_installed_list;
push @main_menu, "\"Upgradable\" \"Upgrades are available.\" \\" if @update_names;
push @main_menu, "\"Overrides\" \"View scripts in local overrides.\" \\" if @overrides;
if (@update_names) {
push @main_menu, "\"Upgrade All (dry run)\" \"How all upgrades would be done.\" \\";
push @main_menu, "\"Upgrade All\" \"Apply all available upgrades.\" \\" if $< == 0;
}
}
if ($< == 0) {
push @main_menu, "\"Fetch Repository\" \"Get or update the repository.\" \\";
my (@clean_string, $clean_msg, $has_distfiles, $has_options, $has_working);
if (-d "$config{SBO_HOME}/distfiles") {
opendir(my $handle, "$config{SBO_HOME}/distfiles");
while (my $dir = readdir $handle) {
unless (in_regexp($dir => qw/ . .. /)) { $has_distfiles = 1; last; }
}
}
if (-d "$tmpd") {
opendir(my $handle, $tmpd);
while (my $dir = readdir $handle) {
unless (in_regexp($dir => qw/ . .. /)) { $has_working = 1; last; }
}
}
if (-d "/var/log/sbotools") {
opendir(my $handle, "/var/log/sbotools");
while (my $dir = readdir $handle) {
unless (in_regexp($dir => qw/ . .. /)) { $has_options = 1; last; }
}
}
push @clean_string, "source" if $has_distfiles;
push @clean_string, "working dirs" if $has_working;
push @clean_string, "build options" if $has_options;
if (@clean_string == 3) {
$clean_msg = "Source, working dirs, build options.";
} elsif (@clean_string == 2) {
$clean_msg = "Saved $clean_string[0] and $clean_string[1].";
} elsif (@clean_string == 1) {
$clean_msg = "Saved $clean_string[0].";
$clean_msg =~ s/working dirs/working directories/;
}
push @main_menu, "\"Clean sbotools Files\" \"$clean_msg\" \\" if $clean_msg;
}
@main_menu = sort @main_menu;
# Refresh always goes at the bottom of the screen.
push @main_menu, "\"\" \"\" \\", "\"Refresh\" \"Run in case of outside changes.\"";
my $main_menu = join "\n", @main_menu;
my $msg = "Welcome to the sbotools TUI.";
unless (-s $slackbuilds_txt) {
if ($< == 0) {
$msg .= "\n\nSelect \\\"Fetch Repository\\\" to download a copy of the repo.";
} else {
$msg .= "\n\nAs root, select \\\"Fetch Repository\\\" for a copy of the repo.";
}
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $main_menu, $msg);
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --cancel-label \"Exit\" --title \"Main Menu\" --menu \"$msg\" $height $width $height $main_menu", @help_main);
} else {
$msg .= " Navigate to scripts for actions.";
$msg .= "\n\nFetch the repository to generate descriptions." unless $descriptions_generated;
$msg .= "\n\nRun as root for more options." unless $< == 0;
($height, $width, $begin_y, $begin_x) = calculate_position("wide", $main_menu, $msg);
($res, $output) = do_dialog("$dialog_prefix --begin $begin_y $begin_x --cancel-label \"Exit\" --title \"Main Menu\" --menu \"$msg\" $height $width $height $main_menu", @help_main);
}
exit 0 if $res == $code_dialog_cancel or $res == $code_dialog_error;
my $option = $output;
display_main() unless $option;