1# ex:ts=8 sw=4:
2# $OpenBSD: Paths.pm,v 1.40 2023/06/13 09:07:17 espie Exp $
3#
4# Copyright (c) 2007-2014 Marc Espie <espie@openbsd.org>
5#
6# Permission to use, copy, modify, and distribute this software for any
7# purpose with or without fee is hereby granted, provided that the above
8# copyright notice and this permission notice appear in all copies.
9#
10# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17
18use v5.36;
19
20package OpenBSD::Paths;
21
22# Commands
23sub ldconfig($) { '/sbin/ldconfig' }
24sub chroot($) { '/usr/sbin/chroot' }
25sub mkfontscale($) { '/usr/X11R6/bin/mkfontscale' }
26sub mkfontdir($) { '/usr/X11R6/bin/mkfontdir' }
27sub fc_cache($) { '/usr/X11R6/bin/fc-cache' }
28sub install_info($) { '/usr/bin/install-info' }
29sub useradd($) { '/usr/sbin/useradd' }
30sub groupadd($) { '/usr/sbin/groupadd' }
31sub sysctl($) { '/sbin/sysctl' }
32sub openssl($) { '/usr/bin/openssl' }
33sub pkgca($) { '/etc/ssl/pkgca.pem' }
34sub signify($) { '/usr/bin/signify' }
35sub signifykey($,$k) { "/etc/signify/$k.pub" }
36sub pkg_add($) { '/usr/sbin/pkg_add' }
37sub chmod($) { '/bin/chmod' }	# external command is used for symbolic modes.
38sub gzip($) { '/usr/bin/gzip' }
39sub ftp($) { $ENV{'FETCH_CMD'} || '/usr/bin/ftp' }
40sub groff($) { '/usr/local/bin/groff' }
41sub sh($) { '/bin/sh' }
42sub arch($) { '/usr/bin/arch' }
43sub uname($) { '/usr/bin/uname' }
44sub userdel($) { '/usr/sbin/userdel' }
45sub groupdel($) { '/usr/sbin/groupdel' }
46sub makewhatis($) { '/usr/sbin/makewhatis' }
47sub mknod($) { '/sbin/mknod' }
48sub mount($) { '/sbin/mount' }
49sub df($) { '/bin/df' }
50sub ssh($) { '/usr/bin/ssh' }
51sub make($) { '/usr/bin/make' }
52sub mklocatedb($) { '/usr/libexec/locate.mklocatedb' }
53sub locate($) { '/usr/bin/locate' }
54sub hostname($) { '/bin/hostname' }
55sub doas($) { '/usr/bin/doas' }
56sub env($) { '/usr/bin/env' }
57sub du($) { '/usr/bin/du' }
58sub diff($) { '/usr/bin/diff' }
59sub sha256($) { '/bin/sha256' }
60
61# Various paths
62sub shells($) { '/etc/shells' }
63sub pkgdb($) { '/var/db/pkg' }
64sub localbase($) { '/usr/local' }
65sub vartmp($) { '/tmp' }
66sub portsdir($) { '/usr/ports' }
67
68sub library_dirs($) { ("/usr", "/usr/X11R6") }
69sub master_keys($) { ("/etc/master_key") }
70sub installurl($) { "/etc/installurl" }
71sub srclocatedb($) { "/usr/lib/locate/src.db" }
72sub xlocatedb($) { "/usr/X11R6/lib/locate/xorg.db" }
73sub updateinfodb($) { '/usr/local/share/update.db' }
74
75sub font_cruft($) { ("fonts.alias", "fonts.dir", "fonts.cache-1", "fonts.scale") }
76sub man_cruft($) { ("whatis.db", "mandoc.db", "mandoc.index") }
77sub info_cruft($) { ("dir") }
78
79# a bit of code, OS-dependent stuff that's run-time detected and has no
80# home yet.
81
82my ($machine_arch, $arch, $osversion, $osdirectory);
83
84sub architecture($self)
85{
86	if (!defined $arch) {
87		my $cmd = $self->uname." -m";
88		chomp($arch = `$cmd`);
89	}
90	return $arch;
91}
92
93sub machine_architecture($self)
94{
95	if (!defined $machine_arch) {
96		my $cmd = $self->arch." -s";
97		chomp($machine_arch = `$cmd`);
98	}
99	return $machine_arch;
100}
101
102sub compute_osversion($self)
103{
104	open my $cmd, '-|', $self->sysctl, '-n', 'kern.version';
105	my $line = <$cmd>;
106	close($cmd);
107	if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) {
108		$osversion = $1;
109		if ($2 eq '-current' or $2 eq '-beta') {
110			$osdirectory = 'snapshots';
111		} else {
112			$osdirectory = $osversion;
113		}
114	}
115}
116
117sub os_version($self)
118{
119	if (!defined $osversion) {
120		$self->compute_osversion;
121	}
122	return $osversion;
123}
124
125sub os_directory($self)
126{
127	if (!defined $osversion) {
128		$self->compute_osversion;
129	}
130	return $osdirectory;
131}
132
1331;
134