1#!/bin/bash
2# Setup development environment on alpine systems
3#
4# Wireshark - Network traffic analyzer
5# By Gerald Combs <gerald@wireshark.org>
6# Copyright 1998 Gerald Combs
7#
8# SPDX-License-Identifier: GPL-2.0-or-later
9#
10# We drag in tools that might not be needed by all users; it's easier
11# that way.
12#
13
14if [ "$1" = "--help" ]
15then
16	printf "\\nUtility to setup a alpine system for Wireshark Development.\\n"
17	printf "The basic usage installs the needed software\\n\\n"
18	printf "Usage: %s [--install-optional] [--install-deb-deps] [...other options...]\\n" "$0"
19	printf "\\t--install-optional: install optional software as well\\n"
20	printf "\\t[other]: other options are passed as-is to apt\\n"
21	exit 1
22fi
23
24# Check if the user is root
25if [ "$(id -u)" -ne 0 ]
26then
27	echo "You must be root."
28	exit 1
29fi
30
31ADDITIONAL=0
32for arg; do
33	case $arg in
34		--install-optional)
35			ADDITIONAL=1
36			;;
37		*)
38			OPTIONS="$OPTIONS $arg"
39			;;
40	esac
41done
42
43BASIC_LIST="cmake \
44	ninja \
45	gcc \
46	g++ \
47	glib-dev \
48	libgcrypt-dev \
49	flex \
50	perl \
51	tiff-dev \
52	c-ares-dev \
53	qt5-qtbase-dev \
54	qt5-qttools-dev \
55	qt5-qtmultimedia-dev \
56	qt5-qtsvg-dev"
57
58ADDITIONAL_LIST="
59	git \
60	asciidoctor \
61	libssh-dev \
62	spandsp-dev \
63	libcap-dev \
64	libpcap-dev \
65	libxml2-dev \
66	libmaxminddb-dev \
67	krb5-dev \
68	lz4-dev \
69	gnutls-dev \
70	snappy-dev \
71	nghttp2-dev \
72	lua5.2-dev \
73	libnl3-dev \
74	sbc-dev \
75	minizip-dev \
76	speexdsp-dev \
77	brotli-dev \
78	"
79
80# Uncomment to add PNG compression utilities used by compress-pngs:
81# ADDITIONAL_LIST="$ADDITIONAL_LIST \
82#	advancecomp \
83#	optipng \
84#	oxipng \
85#	pngcrush"
86
87# Adds package $2 to list variable $1 if the package is found.
88# If $3 is given, then this version requirement must be satisfied.
89add_package() {
90	local list="$1" pkgname="$2"
91
92	# fail if the package is not known
93	apk list $pkgname &> /dev/null || return 1
94
95	# package is found, append it to list
96	eval "${list}=\"\${${list}} \${pkgname}\""
97}
98
99ACTUAL_LIST=$BASIC_LIST
100
101# Now arrange for optional support libraries
102if [ $ADDITIONAL -ne 0 ]
103then
104	ACTUAL_LIST="$ACTUAL_LIST $ADDITIONAL_LIST"
105fi
106
107apk update || exit 2
108apk add $ACTUAL_LIST $OPTIONS || exit 2
109
110if [ $ADDITIONAL -eq 0 ]
111then
112	printf "\n*** Optional packages not installed. Rerun with --install-optional to have them.\n"
113fi
114