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) ```
This commit is contained in:
parent
fab32ea0cb
commit
c8d9c6fc6a
|
@ -13,27 +13,22 @@
|
|||
|
||||
set -e -u -o pipefail
|
||||
|
||||
if [ "$1" = "--help" ]
|
||||
then
|
||||
function print_usage() {
|
||||
printf "\\nUtility to setup a alpine system for Wireshark Development.\\n"
|
||||
printf "The basic usage installs the needed software\\n\\n"
|
||||
printf "Usage: %s [--install-optional] [--install-deb-deps] [...other options...]\\n" "$0"
|
||||
printf "\\t--install-optional: install optional software as well\\n"
|
||||
printf "\\t[other]: other options are passed as-is to apt\\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the user is root
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
ADDITIONAL=0
|
||||
OPTIONS=
|
||||
for arg; do
|
||||
case $arg in
|
||||
--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
--install-optional)
|
||||
ADDITIONAL=1
|
||||
;;
|
||||
|
@ -43,6 +38,13 @@ for arg; do
|
|||
esac
|
||||
done
|
||||
|
||||
# Check if the user is root
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASIC_LIST="cmake \
|
||||
ninja \
|
||||
gcc \
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
|
||||
set -e -u -o pipefail
|
||||
|
||||
if [ "$1" = "--help" ]
|
||||
then
|
||||
function print_usage() {
|
||||
printf "\\nUtility to setup a pacman-based system for Wireshark development.\\n"
|
||||
printf "The basic usage installs the needed software\\n\\n"
|
||||
printf "Usage: %s [--install-optional] [...other options...]\\n" "$0"
|
||||
|
@ -23,15 +22,7 @@ then
|
|||
printf "\\t--install-all: install everything\\n"
|
||||
printf "\\t[other]: other options are passed as-is to pacman\\n"
|
||||
printf "\\tPass --noconfirm to bypass any \"are you sure?\" messages.\\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the user is root
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
ADDITIONAL=0
|
||||
TESTDEPS=0
|
||||
|
@ -39,6 +30,10 @@ AUR=0
|
|||
OPTIONS=
|
||||
for arg; do
|
||||
case $arg in
|
||||
--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
--install-optional)
|
||||
ADDITIONAL=1
|
||||
;;
|
||||
|
@ -56,6 +51,13 @@ for arg; do
|
|||
esac
|
||||
done
|
||||
|
||||
# Check if the user is root
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASIC_LIST="base-devel \
|
||||
bcg729 \
|
||||
brotli \
|
||||
|
|
|
@ -13,22 +13,13 @@
|
|||
# that way.
|
||||
#
|
||||
|
||||
if [ "$1" = "--help" ]
|
||||
then
|
||||
function print_usage() {
|
||||
echo "\nUtility to setup a bsd-based system for Wireshark Development.\n"
|
||||
echo "The basic usage installs the needed software\n\n"
|
||||
echo "Usage: $0 [--install-optional] [...other options...]\n"
|
||||
echo "\t--install-optional: install optional software as well"
|
||||
echo "\t[other]: other options are passed as-is to pkg manager.\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the user is root
|
||||
if [ $(id -u) -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
OPTIONS=
|
||||
for op
|
||||
|
@ -36,11 +27,22 @@ do
|
|||
if [ "$op" = "--install-optional" ]
|
||||
then
|
||||
ADDITIONAL=1
|
||||
elif [ "$op" = "--help" ]
|
||||
then
|
||||
print_usage
|
||||
exit 0
|
||||
else
|
||||
OPTIONS="$OPTIONS $op"
|
||||
fi
|
||||
done
|
||||
|
||||
# Check if the user is root
|
||||
if [ $(id -u) -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASIC_LIST="\
|
||||
cmake \
|
||||
qt5 \
|
||||
|
|
|
@ -13,8 +13,7 @@
|
|||
|
||||
set -e -u -o pipefail
|
||||
|
||||
if [ "$1" = "--help" ]
|
||||
then
|
||||
function print_usage() {
|
||||
printf "\\nUtility to setup a debian-based system for Wireshark Development.\\n"
|
||||
printf "The basic usage installs the needed software\\n\\n"
|
||||
printf "Usage: %s [--install-optional] [--install-deb-deps] [...other options...]\\n" "$0"
|
||||
|
@ -22,15 +21,7 @@ then
|
|||
printf "\\t--install-deb-deps: install packages required to build the .deb file\\n"
|
||||
printf "\\t--install-test-deps: install packages required to run all tests\\n"
|
||||
printf "\\t[other]: other options are passed as-is to apt\\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the user is root
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
ADDITIONAL=0
|
||||
DEBDEPS=0
|
||||
|
@ -38,6 +29,10 @@ TESTDEPS=0
|
|||
OPTIONS=
|
||||
for arg; do
|
||||
case $arg in
|
||||
--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
--install-optional)
|
||||
ADDITIONAL=1
|
||||
;;
|
||||
|
@ -53,6 +48,13 @@ for arg; do
|
|||
esac
|
||||
done
|
||||
|
||||
# Check if the user is root
|
||||
if [ "$(id -u)" -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASIC_LIST="gcc \
|
||||
g++\
|
||||
libglib2.0-dev \
|
||||
|
|
|
@ -11,8 +11,7 @@
|
|||
# that way.
|
||||
#
|
||||
|
||||
if [ "$1" = "--help" ]
|
||||
then
|
||||
function print_usage() {
|
||||
printf "\\nUtility to setup an MSYS2 MinGW-w64 system for Wireshark development.\\n"
|
||||
printf "The basic usage installs the needed software\\n\\n"
|
||||
printf "Usage: %s [--install-optional] [...other options...]\\n" "$0"
|
||||
|
@ -21,8 +20,7 @@ then
|
|||
printf "\\t--install-all: install everything\\n"
|
||||
printf "\\t[other]: other options are passed as-is to pacman\\n"
|
||||
printf "\\tPass --noconfirm to bypass any \"are you sure?\" messages.\\n"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
ADDITIONAL=0
|
||||
TESTDEPS=0
|
||||
|
@ -30,6 +28,10 @@ LUA=0
|
|||
OPTIONS=
|
||||
for arg; do
|
||||
case $arg in
|
||||
--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
--install-optional)
|
||||
ADDITIONAL=1
|
||||
;;
|
||||
|
|
|
@ -13,29 +13,24 @@
|
|||
|
||||
set -e -u -o pipefail
|
||||
|
||||
if [ "$1" = "--help" ]
|
||||
then
|
||||
function print_usage() {
|
||||
echo "\nUtility to setup a rpm-based system for Wireshark Development.\n"
|
||||
echo "The basic usage installs the needed software\n\n"
|
||||
echo "Usage: $0 [--install-optional] [...other options...]\n"
|
||||
echo "\t--install-optional: install optional software as well"
|
||||
echo "\t--install-rpm-deps: install packages required to build the .rpm file\\n"
|
||||
echo "\t[other]: other options are passed as-is to the packet manager\n"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if the user is root
|
||||
if [ $(id -u) -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
ADDITIONAL=0
|
||||
RPMDEPS=0
|
||||
OPTIONS=
|
||||
for arg; do
|
||||
case $arg in
|
||||
--help)
|
||||
print_usage
|
||||
exit 0
|
||||
;;
|
||||
--install-optional)
|
||||
ADDITIONAL=1
|
||||
;;
|
||||
|
@ -48,6 +43,13 @@ for arg; do
|
|||
esac
|
||||
done
|
||||
|
||||
# Check if the user is root
|
||||
if [ $(id -u) -ne 0 ]
|
||||
then
|
||||
echo "You must be root."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
BASIC_LIST="cmake \
|
||||
gcc \
|
||||
gcc-c++ \
|
||||
|
|
Loading…
Reference in New Issue