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