xref: /freebsd/usr.sbin/fwget/fwget.sh (revision 4d846d260e2b9a3d4d0a701462568268cbfe7a5b)
1#!/bin/sh
2
3#-
4# SPDX-License-Identifier: BSD-2-Clause
5#
6# Copyright 2023 Beckhoff Automation GmbH & Co. KG
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted providing that the following conditions
10# are met:
11# 1. Redistributions of source code must retain the above copyright
12#    notice, this list of conditions and the following disclaimer.
13# 2. Redistributions in binary form must reproduce the above copyright
14#    notice, this list of conditions and the following disclaimer in the
15#    documentation and/or other materials provided with the distribution.
16#
17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
25# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
26# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27# POSSIBILITY OF SUCH DAMAGE.
28
29: ${LIBEXEC_PATH:="/usr/libexec/fwget"}
30
31usage()
32{
33	cat <<EOF
34Usage: `basename $0` [options] [subsystem]
35
36Supported subsystems
37  pci
38
39Options:
40  -n		-- Do not install package, only print the results
41  -v		-- More verbose
42EOF
43	exit 1
44}
45
46log_start()
47{
48	exec 3>&1 4>&2
49}
50
51log()
52{
53	echo $@ 1>&3
54}
55
56log_verbose()
57{
58	if [ "${VERBOSE}" = "n" ]; then
59		return
60	fi
61
62	echo $@ 1>&3
63}
64
65DRY_RUN=n
66VERBOSE=n
67
68log_start
69
70while [ $# -gt 0 ]; do
71	case $1 in
72		-n)
73			DRY_RUN=y
74			;;
75		-v)
76			VERBOSE=y
77			;;
78		*)
79			subsystems="${subsystems} $1"
80			;;
81	esac
82	shift
83done
84
85# Default searching PCI subsystem
86if [ -z "${subsystems}" ]; then
87	subsystems="pci"
88fi
89
90# Fail early on unsupported subsystem
91for subsystem in ${subsystems}; do
92	if [ ! -f ${LIBEXEC_PATH}/${subsystem} ]; then
93		usage
94	fi
95	. ${LIBEXEC_PATH}/${subsystem}
96done
97
98packages=""
99for subsystem in ${subsystems}; do
100	package=$(${subsystem}_search_packages)
101
102	packages="${packages} ${package}"
103done
104
105echo "Needed packages: ${packages}"
106if [ "${DRY_RUN}" = "y" ]; then
107	exit 0
108fi
109
110pkg install -q ${package}
111