xref: /openbsd/usr.sbin/pkg_add/OpenBSD/Paths.pm (revision df5108e6)
1# ex:ts=8 sw=4:
2# $OpenBSD: Paths.pm,v 1.33 2015/07/23 19:46:52 jung 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 strict;
19use warnings;
20
21package OpenBSD::Paths;
22
23# Commands
24sub ldconfig() { '/sbin/ldconfig' }
25sub chroot() { '/usr/sbin/chroot' }
26sub mkfontscale() { '/usr/X11R6/bin/mkfontscale' }
27sub mkfontdir() { '/usr/X11R6/bin/mkfontdir' }
28sub fc_cache() { '/usr/X11R6/bin/fc-cache' }
29sub install_info() { '/usr/bin/install-info' }
30sub useradd() { '/usr/sbin/useradd' }
31sub groupadd() { '/usr/sbin/groupadd' }
32sub sysctl() { '/sbin/sysctl' }
33sub openssl() { '/usr/bin/openssl' }
34sub pkgca() { '/etc/ssl/pkgca.pem' }
35sub signify() { '/usr/bin/signify' }
36sub signifykey { my $s = $_[1]; "/etc/signify/$s.pub" }
37sub pkg_add() { '/usr/sbin/pkg_add' }
38sub chmod() { '/bin/chmod' }	# external command is used for symbolic modes.
39sub gzip() { '/usr/bin/gzip' }
40sub ftp() { $ENV{'FETCH_CMD'} || '/usr/bin/ftp' }
41sub groff() { '/usr/local/bin/groff' }
42sub sh() { '/bin/sh' }
43sub arch() { '/usr/bin/arch' }
44sub uname() { '/usr/bin/uname' }
45sub userdel() { '/usr/sbin/userdel' }
46sub groupdel() { '/usr/sbin/groupdel' }
47sub makewhatis() { '/usr/sbin/makewhatis' }
48sub mknod() { '/sbin/mknod' }
49sub mount() { '/sbin/mount' }
50sub df() { '/bin/df' }
51sub ssh() { '/usr/bin/ssh' }
52sub make() { '/usr/bin/make' }
53sub mklocatedb() { '/usr/libexec/locate.mklocatedb' }
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() { '/var/tmp' }
66sub portsdir() { '/usr/ports' }
67
68sub library_dirs() { ("/usr", "/usr/X11R6") }
69sub master_keys() { ("/etc/master_key") }
70sub pkgconf() { "/etc/pkg.conf" }
71sub srclocatedb() { "/usr/lib/locate/src.db" }
72sub xlocatedb() { "/usr/X11R6/lib/locate/xorg.db" }
73
74sub font_cruft() { ("fonts.alias", "fonts.dir", "fonts.cache-1", "fonts.scale") }
75sub man_cruft() { ("whatis.db", "mandoc.db", "mandoc.index") }
76sub info_cruft() { ("dir") }
77
78# a bit of code, OS-dependent stuff that's run-time detected and has no
79# home yet.
80
81my ($machine_arch, $arch, $osversion, $osdirectory);
82
83sub architecture
84{
85	if (!defined $arch) {
86		my $cmd = uname()." -m";
87		chomp($arch = `$cmd`);
88	}
89	return $arch;
90}
91
92sub machine_architecture
93{
94	if (!defined $machine_arch) {
95		my $cmd = arch()." -s";
96		chomp($machine_arch = `$cmd`);
97	}
98	return $machine_arch;
99}
100
101sub compute_osversion
102{
103	open my $cmd, '-|', OpenBSD::Paths->sysctl, '-n', 'kern.version';
104	my $line = <$cmd>;
105	close($cmd);
106	if ($line =~ m/^OpenBSD (\d\.\d)(\S*)\s/) {
107		$osversion = $1;
108		if ($2 eq '-current' or $2 eq '-beta') {
109			$osdirectory = 'snapshots';
110		} else {
111			$osdirectory = $osversion;
112		}
113	}
114}
115
116sub os_version
117{
118	if (!defined $osversion) {
119		compute_osversion();
120	}
121	return $osversion;
122}
123
124sub os_directory
125{
126	if (!defined $osversion) {
127		compute_osversion();
128	}
129	return $osdirectory;
130}
131
1321;
133