forked from pink-mist/sbotools
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsboconfig
More file actions
executable file
·382 lines (349 loc) · 12.9 KB
/
sboconfig
File metadata and controls
executable file
·382 lines (349 loc) · 12.9 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
#!/usr/bin/perl
#
# vim: ts=4:noet
#
# sboconfig
# script to handle sbotools configuration
#
# authors: Jacob Pipkin <j@dawnrazor.net>
# Luke Williams <xocel@iquidus.org>
# Andreas Guldstrand <andreas.guldstrand@gmail.com>
# maintainer: K. Eugene Carlson <kvngncrlsn@gmail.com>
# license: MIT License
use 5.16.0;
use strict;
use warnings FATAL => 'all';
use SBO::Lib qw/ :config :colors slurp usage_error script_error lint_sbo_config $tempdir open_fh prompt wrapsay show_version /;
use File::Basename;
use Getopt::Long qw(:config no_ignore_case_always);
use File::Copy;
use File::Path qw(make_path);
use File::Temp qw(tempfile);;
my $self = basename($0);
my $label = $is_sbotest ? "sbotest config" : $self;
sub show_usage {
if ($is_sbotest) {
show_sbotest_usage();
return 1;
}
print <<"EOF";
Usage: $label option argument ...
$label
Options:
-h|--help:
this screen.
-v|--version:
version information.
-l|--list:
show current options.
-n|--non-default:
show current non-default options.
--reset:
restore the default configuration.
Configuration options (defaults shown):
-B|--branch FALSE:
GIT_BRANCH: git branch to use, or FALSE for the OS version default.
-b|--build-ignore FALSE:
BUILD_IGNORE: if TRUE, only attempt upgrades if the version differs.
-C|--classic FALSE:
CLASSIC: if TRUE, BUILD_IGNORE and RSYNC_DEFAULT; use 2.7 output.
-c|--noclean FALSE:
NOCLEAN: if TRUE, do not clean working directories after building.
-D|--dialogrc FALSE:
DIALOGRC: if a FILE, use it as dialogrc for sbotool.
-d|--distclean FALSE:
DISTCLEAN: if TRUE, clean source and package archives after building.
-e|--etc-profile FALSE:
ETC_PROFILE: if TRUE, source executable scripts in /etc/profile.d.
-g|--gpg-verify FALSE:
GPG_VERIFY: verify the repo with gnupg.
-j|--jobs FALSE:
JOBS: numeric -j setting to feed to make for multicore systems.
-K|--color FALSE:
COLOR: if TRUE, enable sbotools color output.
-L|--log-dir FALSE:
LOG_DIR: if an absolute path, save a log file here after each build.
-P|--cpan-ignore FALSE:
CPAN_IGNORE: install scripts even if they are installed from the CPAN.
-p|--pkg-dir FALSE:
PKG_DIR: set a directory to store packages in.
-s|--sbo-home /usr/sbo:
SBO_HOME: set the SBo directory.
-O|--obsolete-check FALSE:
OBSOLETE_CHECK: -current: sbocheck gets obsolete list and perl history.
-o|--local-overrides FALSE:
LOCAL_OVERRIDES: a directory containing local overrides.
-V|--slackware-version FALSE:
SLACKWARE_VERSION: use the SBo repository for this version.
-r|--repo FALSE:
REPO: use a repository other than SBo.
-R|--rsync FALSE:
RSYNC_DEFAULT: default mirrors (other than for -current) are rsync.
-S|--strict-upgrades FALSE:
STRICT_UPGRADES: only upgrade when the version or build is higher.
-w|--nowrap FALSE:
NOWRAP: do not automatically wrap sbotools output.
-X|--so-check FALSE:
SO_CHECK: check for .so dependencies after sbocheck and sboupgrade.
Use $label without options for a dialog menu.
EOF
return 1;
}
sub show_sbotest_usage {
print <<"EOF";
Usage: $label option argument ...
$label
Options:
-h|--help:
this screen.
-v|--version:
version information.
-l|--list:
show current options.
-n|--non-default:
show current non-default options.
--reset:
restore the default configuration.
Configuration options (defaults shown):
-A|--sbo-archive /usr/sbotest/archive:
SBO_ARCHIVE: the directory for package reuse.
-B|--branch FALSE:
GIT_BRANCH: git branch to use, or FALSE for the OS version default.
-C|--classic FALSE:
CLASSIC: if TRUE, BUILD_IGNORE and RSYNC_DEFAULT; use 2.7 output.
-c|--noclean FALSE:
NOCLEAN: if TRUE, do not clean working directories after building.
-d|--distclean FALSE:
DISTCLEAN: if TRUE, clean source and package archives after building.
-e|--etc-profile TRUE:
ETC_PROFILE: if FALSE, do not source executables in /etc/profile.d.
-g|--gpg-verify FALSE:
GPG_VERIFY: verify the repo with gnupg.
-j|--jobs FALSE:
JOBS: numeric -j setting to feed to make for multicore systems.
-K|--color FALSE:
COLOR: if TRUE, enable sbotools color output.
-L|--log-dir /usr/sbotest/logs:
LOG_DIR: if an absolute path, save a log file here after each build.
-P|--cpan-ignore TRUE:
CPAN_IGNORE: install scripts even if they are installed from the CPAN.
-p|--pkg-dir /usr/sbotest/tests:
PKG_DIR: set a directory to store packages in.
-s|--sbo-home /usr/sbotest:
SBO_HOME: set the SBo directory.
-O|--obsolete-check FALSE:
OBSOLETE_CHECK: -current: sbocheck gets obsolete list and perl history.
-o|--local-overrides FALSE:
LOCAL_OVERRIDES: a directory containing local overrides.
-V|--slackware-version FALSE:
SLACKWARE_VERSION: use the SBo repository for this version.
-r|--repo FALSE:
REPO: use a repository other than SBo.
-R|--rsync FALSE:
RSYNC_DEFAULT: default mirrors (other than for -current) are rsync.
-S|--strict-upgrades FALSE:
STRICT_UPGRADES: with --archive-rebuild, only delete when version or
build is lower.
-w|--nowrap FALSE:
NOWRAP: do not automatically wrap sbotest output.
-X|--so-check FALSE:
SO_CHECK: check for missing .so dependencies when running sbocheck.
EOF
return 1;
}
my $all_clear = 1 unless @ARGV;
my %options;
unless ($is_sbotest) {
GetOptions(\%options, 'help|h', 'version|v', 'list|l', 'non-default|n', 'reset', 'classic|C=s', 'noclean|c=s',
'distclean|d=s', 'jobs|j=s', 'pkg-dir|p=s', 'sbo-home|s=s',
'local-overrides|o=s', 'slackware-version|V=s', 'repo|r=s',
'build-ignore|b=s', 'branch|B=s', 'rsync|R=s', 'gpg-verify|g=s', 'strict-upgrades|S=s',
'cpan-ignore|P=s', 'obsolete-check|O=s', 'etc-profile|e=s', 'log-dir|L=s',
'nowrap|w=s', 'color|K=s', 'so-check|X=s', 'dialogrc|D=s');
} else {
GetOptions(\%options, 'help|h', 'version|v', 'list|l', 'non-default|n', 'reset', 'classic|C=s', 'noclean|c=s',
'distclean|d=s', 'jobs|j=s', 'pkg-dir|p=s', 'sbo-home|s=s',
'local-overrides|o=s', 'slackware-version|V=s', 'repo|r=s',
'build-ignore|b=s', 'branch|B=s', 'rsync|R=s', 'gpg-verify|g=s', 'strict-upgrades|S=s',
'cpan-ignore|P=s', 'obsolete-check|O=s', 'etc-profile|e=s', 'log-dir|L=s',
'nowrap|w=s', 'color|K=s', 'so-check|X=s', 'sbo-archive|A=s', 'dialogrc|D=s');
}
$options{list} = 1 if exists $options{'non-default'};
if ($options{help}) {
show_usage();
wrapsay "\nNon-root users can call $label with -l, -n, -h and -v." unless $< == 0;
exit 0;
}
if ($options{version}) { show_version(); exit 0 }
unless ($< == 0 or $options{list} or $all_clear) {
show_usage();
usage_error "\nNon-root users can call $label with -l, -n, -h and -v.";
}
my %valid_confs = (
classic => 'CLASSIC',
noclean => 'NOCLEAN',
distclean => 'DISTCLEAN',
jobs => 'JOBS',
'pkg-dir' => 'PKG_DIR',
'sbo-home' => 'SBO_HOME',
'local-overrides' => 'LOCAL_OVERRIDES',
'slackware-version' => 'SLACKWARE_VERSION',
'repo' => 'REPO',
rsync => 'RSYNC_DEFAULT',
'branch' => 'GIT_BRANCH',
'build-ignore' => 'BUILD_IGNORE',
'gpg-verify' => 'GPG_VERIFY',
'strict-upgrades' => 'STRICT_UPGRADES',
'cpan-ignore' => 'CPAN_IGNORE',
'obsolete-check' => 'OBSOLETE_CHECK',
'etc-profile' => 'ETC_PROFILE',
'log-dir' => 'LOG_DIR',
color => 'COLOR',
nowrap => 'NOWRAP',
'so-check' => 'SO_CHECK',
'dialogrc' => 'DIALOGRC',
);
$valid_confs{"sbo-archive"} = 'SBO_ARCHIVE' if $is_sbotest;
my %params = (
CLASSIC => 'C|--classic',
NOCLEAN => 'c|--noclean',
DISTCLEAN => 'd|--distclean',
GPG_VERIFY => 'g|--gpg-verify',
JOBS => 'j|--jobs',
PKG_DIR => 'p|--pkg-dir',
SBO_HOME => 's|--sbo-home',
LOCAL_OVERRIDES => 'o|--local-overrides',
SLACKWARE_VERSION => 'V|--slackware-version',
REPO => 'r|--repo',
RSYNC_DEFAULT => 'R|--rsync',
GIT_BRANCH => 'B|--branch',
BUILD_IGNORE => 'b|--build-ignore',
STRICT_UPGRADES => 'S|--strict-upgrades',
CPAN_IGNORE => 'P|--cpan-ignore',
OBSOLETE_CHECK => 'O|--obsolete-check',
ETC_PROFILE => 'e|--etc-profile',
LOG_DIR => 'L|--log-dir',
COLOR => 'K|--color',
NOWRAP => 'w|--nowrap',
SO_CHECK => 'X|--so-check',
DIALOGRC => 'D|--dialogrc',
);
$params{SBO_ARCHIVE} = 'A|--sbo-archive' if $is_sbotest;
if (exists $options{list}) {
my @keys = sort {$a cmp $b} keys %config;
if (exists $options{'non-default'} and not $is_sbotest) {
for my $item (@keys) {
next if $config{$item} eq 'FALSE';
next if $item eq 'SBO_HOME' and $config{$item} eq '/usr/sbo';
say "$label -$params{$item}:\n $item=$config{$item}";
}
} elsif (exists $options{'non-default'} and $is_sbotest) {
for my $item (@keys) {
if ($item eq 'ETC_PROFILE' or $item eq 'CPAN_IGNORE') { next if $config{$item} eq 'TRUE'; }
if ($item eq 'SBO_HOME') { next if $config{$item} eq 'FALSE' or $config{$item} eq '/usr/sbotest'; }
if ($item eq 'SBO_ARCHIVE') { next if $config{$item} eq 'FALSE' or $config{$item} eq "$config{'SBO_HOME'}/archive"; }
if ($item eq 'PKG_DIR') { next if $config{$item} eq 'FALSE' or $config{$item} eq "$config{'SBO_HOME'}/tests"; }
if ($item eq 'LOG_DIR') { next if $config{$item} eq 'FALSE' or $config{$item} eq "$config{'SBO_HOME'}/logs"; }
next if $item ne 'ETC_PROFILE' and $item ne 'CPAN_IGNORE' and $config{$item} eq 'FALSE';
say "$label -$params{$item}:\n $item=$config{$item}";
}
} else {
say "$label -$params{$_}:\n $_=$config{$_}" for @keys;
}
wrapsay "\nWarning: Local overrides directory $config{LOCAL_OVERRIDES} does not exist." if $config{LOCAL_OVERRIDES} ne "FALSE" and not -d $config{LOCAL_OVERRIDES};
exit 0;
}
if (exists $options{reset}) {
if (prompt($color_warn, "Reset all options to the default setting?", default => 'no')) {
say "Restoring default configuration...";
} else {
say "Exiting without changes.";
exit 0;
}
}
# setup what's being changed, sanity check.
my %changes;
for my $key (keys %valid_confs) {
my $value = $valid_confs{$key};
if (exists $options{reset}) {
$changes{$value} = "FALSE";
} else {
$changes{$value} = $options{$key} if exists $options{$key};
}
}
$changes{'SBO_HOME'} = '/usr/sbo' if exists $options{reset};
if (exists $options{reset} and $is_sbotest) {
$changes{'SBO_HOME'} = '/usr/sbotest';
$changes{'PKG_DIR'} = '/usr/sbotest/tests';
$changes{'LOG_DIR'} = '/usr/sbotest/logs';
$changes{'SBO_ARCHIVE'} = '/usr/sbotest/archive';
$changes{'ETC_PROFILE'} = 'TRUE';
$changes{'CPAN_IGNORE'} = 'TRUE';
}
if ($all_clear and not $is_sbotest) {
system('/usr/sbin/sbotool --config');
exit;
} elsif (not %options or $all_clear) {
show_usage();
exit 1;
}
lint_sbo_config($self, %changes);
my $change_requested;
sub config_write {
script_error('config_write requires at least two arguments.') unless @_ >= 2;
if (! -d $conf_dir) {
mkdir $conf_dir or usage_error("Unable to create $conf_dir. Exiting.");
}
my $conf = slurp($conf_file) || '';
_fixup_conf($conf);
while (@_ >= 2) {
my $key = shift;
my $val = shift;
next if $key eq 'BUILD_IGNORE' and $is_sbotest;
next if $key eq 'COLOR' and $is_sbotest;
say "Setting $key to $val..." unless exists $options{reset};
# Comment default values when written in
my $comment = '';
unless ($is_sbotest) {
$comment = '#' if $val eq 'FALSE';
$comment = '#' if $key eq 'SBO_HOME' and $val eq '/usr/sbo';
} else {
$comment = '#' if $key ne 'ETC_PROFILE' and $key ne 'CPAN_IGNORE' and $val eq 'FALSE';
$comment = '#' if ($key eq 'ETC_PROFILE' or $key eq 'CPAN_IGNORE') and $val eq 'TRUE';
$comment = '#' if $key eq 'SBO_HOME' and $val eq '/usr/sbotest';
$comment = '#' if $key eq 'PKG_DIR' and $val eq '/usr/sbotest/tests';
$comment = '#' if $key eq 'LOG_DIR' and $val eq '/usr/sbotest/logs';
$comment = '#' if $key eq 'SBO_ARCHIVE' and $val eq '/usr/sbotest/archive';
}
if ($conf =~ /^#(\s*)\Q$key\E=/m) {
$conf =~ s/^#(\s*)\Q$key\E=.*$/$comment$key=$val/m;
} elsif ($conf =~ /^\Q$key\E=/m) {
$conf =~ s/^\Q$key\E=.*$/$comment$key=$val/m;
} else {
$conf .= "$comment$key=$val\n";
}
}
_fixup_conf($conf);
my ($conffh, $exit) = open_fh($conf_file, '>');
error_code("Failed to open $conf_file; exiting.", $exit) if $exit;
print {$conffh} $conf;
}
# make sure there are no duplicate keys in the config
sub _fixup_conf {
my @lines = split /\n/, $_[0];
my @fixed;
my %keys;
foreach my $line (@lines) {
# if it's a comment or blank line, just pass it through
if ($line =~ /^(#|\s*$)/) { push @fixed, $line; next; }
my ($key, $val) = split /=/, $line;
next if exists $keys{$key};
$keys{$key}++;
push @fixed, $line;
}
$_[0] = join "\n", @fixed, ''; # make sure we end with a newline if there are any lines
}
if (%changes) {
config_write(%changes);
}
END { say ""; }