2020-01-20 14:19:12 +00:00
|
|
|
#!/usr/bin/env bash
|
2018-05-25 17:46:53 +00:00
|
|
|
# Setup development environment on BSD-like platforms.
|
|
|
|
#
|
|
|
|
# Tested on: FreeBSD, OpenBSD, NetBSD.
|
|
|
|
#
|
|
|
|
# Wireshark - Network traffic analyzer
|
|
|
|
# By Gerald Combs <gerald@wireshark.org>
|
|
|
|
# Copyright 1998 Gerald Combs
|
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#
|
|
|
|
# We drag in tools that might not be needed by all users; it's easier
|
|
|
|
# that way.
|
|
|
|
#
|
|
|
|
|
Fix tools/*-setup.sh to work with no arguments
They were checking for --help in an unusual manner that failed when
run with no arguments.
I've checked that --help works for each script, and that debian-setup.sh
actually works.
NOTE: bsd-setup.sh and rpm-setup.sh seem to have sometimes-broken
formatting, because they try to pass escape sequences to echo, which
POSIX says is implementation-defined (except on XSI-conformant systems).
These changes were mostly made using the following script, with a
manual fix in bsd-setup.sh because it isn't using "switch case".
```python
#!/bin/env python3
import sys
import re
usage_p = re.compile(r'^if \[ "\$1" = "--help" \]\nthen\n((?:\t(?:printf|echo) .*\n)*)\texit 1\nfi$',
re.MULTILINE)
case_p = re.compile(r'(^\tcase \$arg in$)',
re.MULTILINE)
root_check_p = re.compile(r'(\n# Check if the user is root(?:\n|.)*?fi\n)',
re.MULTILINE)
done_p = re.compile(r'(^done\n)',
re.MULTILINE)
def fix_setup(name: str):
assert name.endswith('-setup.sh')
with open(name, 'r') as fin:
s = fin.read()
s = usage_p.sub(r'function print_usage() {\n\1}', s)
s = case_p.sub(r'''\1
\t\t--help)
\t\t\tprint_usage
\t\t\texit 0
\t\t\t;;''', s)
m1 = root_check_p.search(s)
if m1:
root_check = m1[0]
s = root_check_p.sub('', s)
pos = done_p.search(s).end() # type: ignore[union-attr]
s = s[:pos] + root_check + s[pos:]
with open(name, 'w') as fout:
fout.write(s)
if __name__ == '__main__':
for name in sys.argv[1:]:
fix_setup(name)
```
2022-04-17 22:25:57 +00:00
|
|
|
function print_usage() {
|
2022-10-18 02:40:32 +00:00
|
|
|
printf "\\nUtility to setup a bsd-based system for Wireshark Development.\\n"
|
|
|
|
printf "The basic usage installs the needed software\\n\\n"
|
|
|
|
printf "Usage: $0 [--install-optional] [...other options...]\\n"
|
|
|
|
printf "\\t--install-optional: install optional software as well\\n"
|
|
|
|
printf "\\t[other]: other options are passed as-is to pkg manager.\\n"
|
Fix tools/*-setup.sh to work with no arguments
They were checking for --help in an unusual manner that failed when
run with no arguments.
I've checked that --help works for each script, and that debian-setup.sh
actually works.
NOTE: bsd-setup.sh and rpm-setup.sh seem to have sometimes-broken
formatting, because they try to pass escape sequences to echo, which
POSIX says is implementation-defined (except on XSI-conformant systems).
These changes were mostly made using the following script, with a
manual fix in bsd-setup.sh because it isn't using "switch case".
```python
#!/bin/env python3
import sys
import re
usage_p = re.compile(r'^if \[ "\$1" = "--help" \]\nthen\n((?:\t(?:printf|echo) .*\n)*)\texit 1\nfi$',
re.MULTILINE)
case_p = re.compile(r'(^\tcase \$arg in$)',
re.MULTILINE)
root_check_p = re.compile(r'(\n# Check if the user is root(?:\n|.)*?fi\n)',
re.MULTILINE)
done_p = re.compile(r'(^done\n)',
re.MULTILINE)
def fix_setup(name: str):
assert name.endswith('-setup.sh')
with open(name, 'r') as fin:
s = fin.read()
s = usage_p.sub(r'function print_usage() {\n\1}', s)
s = case_p.sub(r'''\1
\t\t--help)
\t\t\tprint_usage
\t\t\texit 0
\t\t\t;;''', s)
m1 = root_check_p.search(s)
if m1:
root_check = m1[0]
s = root_check_p.sub('', s)
pos = done_p.search(s).end() # type: ignore[union-attr]
s = s[:pos] + root_check + s[pos:]
with open(name, 'w') as fout:
fout.write(s)
if __name__ == '__main__':
for name in sys.argv[1:]:
fix_setup(name)
```
2022-04-17 22:25:57 +00:00
|
|
|
}
|
2018-05-25 17:46:53 +00:00
|
|
|
|
2022-10-18 02:40:32 +00:00
|
|
|
ADDITIONAL=0
|
2022-04-10 22:40:36 +00:00
|
|
|
OPTIONS=
|
2022-10-18 02:40:32 +00:00
|
|
|
for arg; do
|
|
|
|
case $arg in
|
|
|
|
--help)
|
|
|
|
print_usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
--install-optional)
|
|
|
|
ADDITIONAL=1
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
OPTIONS="$OPTIONS $arg"
|
|
|
|
;;
|
|
|
|
esac
|
2018-05-25 17:46:53 +00:00
|
|
|
done
|
|
|
|
|
Fix tools/*-setup.sh to work with no arguments
They were checking for --help in an unusual manner that failed when
run with no arguments.
I've checked that --help works for each script, and that debian-setup.sh
actually works.
NOTE: bsd-setup.sh and rpm-setup.sh seem to have sometimes-broken
formatting, because they try to pass escape sequences to echo, which
POSIX says is implementation-defined (except on XSI-conformant systems).
These changes were mostly made using the following script, with a
manual fix in bsd-setup.sh because it isn't using "switch case".
```python
#!/bin/env python3
import sys
import re
usage_p = re.compile(r'^if \[ "\$1" = "--help" \]\nthen\n((?:\t(?:printf|echo) .*\n)*)\texit 1\nfi$',
re.MULTILINE)
case_p = re.compile(r'(^\tcase \$arg in$)',
re.MULTILINE)
root_check_p = re.compile(r'(\n# Check if the user is root(?:\n|.)*?fi\n)',
re.MULTILINE)
done_p = re.compile(r'(^done\n)',
re.MULTILINE)
def fix_setup(name: str):
assert name.endswith('-setup.sh')
with open(name, 'r') as fin:
s = fin.read()
s = usage_p.sub(r'function print_usage() {\n\1}', s)
s = case_p.sub(r'''\1
\t\t--help)
\t\t\tprint_usage
\t\t\texit 0
\t\t\t;;''', s)
m1 = root_check_p.search(s)
if m1:
root_check = m1[0]
s = root_check_p.sub('', s)
pos = done_p.search(s).end() # type: ignore[union-attr]
s = s[:pos] + root_check + s[pos:]
with open(name, 'w') as fout:
fout.write(s)
if __name__ == '__main__':
for name in sys.argv[1:]:
fix_setup(name)
```
2022-04-17 22:25:57 +00:00
|
|
|
# Check if the user is root
|
|
|
|
if [ $(id -u) -ne 0 ]
|
|
|
|
then
|
|
|
|
echo "You must be root."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2018-05-25 17:46:53 +00:00
|
|
|
BASIC_LIST="\
|
|
|
|
cmake \
|
2022-08-23 18:01:06 +00:00
|
|
|
qt6 \
|
2021-11-12 20:23:16 +00:00
|
|
|
git \
|
2022-12-20 12:27:41 +00:00
|
|
|
pcre2 \
|
|
|
|
speexdsp"
|
2018-05-25 17:46:53 +00:00
|
|
|
|
|
|
|
ADDITIONAL_LIST="\
|
|
|
|
gettext-tools \
|
|
|
|
snappy \
|
|
|
|
bcg729 \
|
|
|
|
libssh \
|
|
|
|
libmaxminddb \
|
2019-07-29 21:06:20 +00:00
|
|
|
libsmi \
|
|
|
|
brotli \
|
2020-01-26 14:51:44 +00:00
|
|
|
zstd \
|
2020-01-30 13:12:20 +00:00
|
|
|
lua52 \
|
2019-07-29 21:06:20 +00:00
|
|
|
"
|
2018-05-25 17:46:53 +00:00
|
|
|
|
2021-09-12 20:45:54 +00:00
|
|
|
# Uncomment to add PNG compression utilities used by compress-pngs:
|
|
|
|
# ADDITIONAL_LIST="$ADDITIONAL_LIST \
|
|
|
|
# advancecomp \
|
|
|
|
# optipng \
|
|
|
|
# pngcrush"
|
|
|
|
|
2018-05-25 17:46:53 +00:00
|
|
|
# Guess which package manager we will use
|
|
|
|
PM=`which pkgin 2> /dev/null || which pkg 2> /dev/null || which pkg_add 2> /dev/null`
|
|
|
|
|
|
|
|
case $PM in
|
|
|
|
*/pkgin)
|
|
|
|
PM_OPTIONS="install"
|
|
|
|
PM_SEARCH="pkgin search"
|
2018-08-21 06:37:54 +00:00
|
|
|
PM_MUST_GLOB=no
|
2018-05-25 17:46:53 +00:00
|
|
|
;;
|
|
|
|
*/pkg)
|
|
|
|
PM_OPTIONS="install"
|
|
|
|
PM_SEARCH="pkg search"
|
2018-08-21 06:37:54 +00:00
|
|
|
PM_MUST_GLOB=yes
|
2018-05-25 17:46:53 +00:00
|
|
|
;;
|
|
|
|
*/pkg_add)
|
|
|
|
PM_OPTIONS=""
|
|
|
|
PM_SEARCH="pkg_info"
|
2018-08-21 06:37:54 +00:00
|
|
|
PM_MUST_GLOB=no
|
2018-05-25 17:46:53 +00:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
|
|
|
|
echo "Using $PM ($PM_SEARCH)"
|
|
|
|
|
|
|
|
# Adds package $2 to list variable $1 if the package is found
|
|
|
|
add_package() {
|
|
|
|
local list="$1" pkgname="$2"
|
|
|
|
|
|
|
|
# fail if the package is not known
|
2018-08-21 19:20:58 +00:00
|
|
|
if [ "$PM_MUST_GLOB" = yes ]
|
2018-08-21 06:37:54 +00:00
|
|
|
then
|
|
|
|
#
|
|
|
|
# We need to do a glob search, with a "*" at the
|
|
|
|
# end, so we only find packages that *begin* with
|
|
|
|
# the name; otherwise, searching for pkg-config
|
|
|
|
# could find packages that *don't* begin with
|
|
|
|
# pkg-config, but have it later in the name
|
|
|
|
# (FreeBSD 11 has one such package), so when
|
|
|
|
# we then try to install it, that fails. Doing
|
|
|
|
# an *exact* search fails, as that requires that
|
|
|
|
# the package name include the version number.
|
|
|
|
#
|
2018-08-21 09:37:40 +00:00
|
|
|
$PM_SEARCH -g "$pkgname*" > /dev/null 2>&1 || return 1
|
2018-08-21 06:37:54 +00:00
|
|
|
else
|
2018-08-21 09:37:40 +00:00
|
|
|
$PM_SEARCH "$pkgname" > /dev/null 2>&1 || return 1
|
2018-08-21 06:37:54 +00:00
|
|
|
fi
|
2018-05-25 17:46:53 +00:00
|
|
|
|
|
|
|
# package is found, append it to list
|
|
|
|
eval "${list}=\"\${${list}} \${pkgname}\""
|
|
|
|
}
|
|
|
|
|
|
|
|
# pkg-config: NetBSD
|
2018-08-21 06:37:54 +00:00
|
|
|
# pkgconf: FreeBSD
|
2018-05-25 17:46:53 +00:00
|
|
|
add_package BASIC_LIST pkg-config ||
|
2018-08-21 06:37:54 +00:00
|
|
|
add_package BASIC_LIST pkgconf ||
|
2018-05-25 17:46:53 +00:00
|
|
|
echo "pkg-config is unavailable"
|
|
|
|
|
|
|
|
# c-ares: FreeBSD
|
|
|
|
# libcares: OpenBSD
|
2019-11-22 19:16:36 +00:00
|
|
|
add_package BASIC_LIST c-ares ||
|
|
|
|
add_package BASIC_LIST libcares ||
|
2018-05-25 17:46:53 +00:00
|
|
|
echo "c-ares is unavailable"
|
|
|
|
|
|
|
|
# rubygem-asciidoctor: FreeBSD
|
|
|
|
add_package ADDITIONAL_LIST rubygem-asciidoctor ||
|
|
|
|
echo "asciidoctor is unavailable"
|
|
|
|
|
2020-01-26 14:51:44 +00:00
|
|
|
# liblz4: FreeBSD
|
2018-05-25 17:46:53 +00:00
|
|
|
# lz4: NetBSD
|
2020-01-26 14:51:44 +00:00
|
|
|
add_package ADDITIONAL_LIST liblz4 ||
|
2018-05-25 17:46:53 +00:00
|
|
|
add_package ADDITIONAL_LIST lz4 ||
|
|
|
|
echo "lz4 is unavailable"
|
|
|
|
|
|
|
|
# nghttp2: NetBSD
|
|
|
|
add_package ADDITIONAL_LIST nghttp2 ||
|
|
|
|
echo "nghttp2 is unavailable"
|
|
|
|
|
|
|
|
# spandsp: NetBSD
|
|
|
|
add_package ADDITIONAL_LIST spandsp ||
|
|
|
|
echo "spandsp is unavailable"
|
|
|
|
|
|
|
|
# ninja: FreeBSD, OpenBSD
|
|
|
|
# ninja-build: NetBSD
|
|
|
|
add_package ADDITIONAL_LIST ninja-build ||
|
|
|
|
add_package ADDITIONAL_LIST ninja ||
|
|
|
|
echo "ninja is unavailable"
|
|
|
|
|
2020-01-20 14:22:05 +00:00
|
|
|
# libilbc: FreeBSD
|
|
|
|
add_package ADDITIONAL_LIST libilbc ||
|
|
|
|
echo "libilbc is unavailable"
|
|
|
|
|
2018-05-25 17:46:53 +00:00
|
|
|
# Add OS-specific required/optional packages
|
|
|
|
# Those not listed don't require additions.
|
|
|
|
case `uname` in
|
2022-10-18 02:40:32 +00:00
|
|
|
FreeBSD | NetBSD)
|
2018-05-25 17:46:53 +00:00
|
|
|
add_package ADDITIONAL_LIST libgcrypt || echo "libgcrypt is unavailable"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
ACTUAL_LIST=$BASIC_LIST
|
|
|
|
|
|
|
|
# Now arrange for optional support libraries
|
2022-10-18 02:40:32 +00:00
|
|
|
if [ $ADDITIONAL -ne 0 ]
|
2018-05-25 17:46:53 +00:00
|
|
|
then
|
|
|
|
ACTUAL_LIST="$ACTUAL_LIST $ADDITIONAL_LIST"
|
|
|
|
fi
|
|
|
|
|
|
|
|
$PM $PM_OPTIONS $ACTUAL_LIST $OPTIONS
|
2020-01-23 15:09:26 +00:00
|
|
|
if [ ! $? ]
|
2018-05-25 17:46:53 +00:00
|
|
|
then
|
|
|
|
exit 2
|
|
|
|
fi
|
|
|
|
|
2022-10-18 02:40:32 +00:00
|
|
|
if [ $ADDITIONAL -eq 0 ]
|
2018-05-25 17:46:53 +00:00
|
|
|
then
|
2019-11-15 22:21:12 +00:00
|
|
|
echo -e "\n*** Optional packages not installed. Rerun with --install-optional to have them.\n"
|
2018-05-25 17:46:53 +00:00
|
|
|
fi
|