Automatic install script fails when /etc/apt/sources-list.d is empty
Summary
When using the install.sh script on a completely vanilla Debian Bookworm system, where /etc/apt/source.list.d is empty, the script fails saying:
sed: can't read /etc/apt/sources.list.d/*: No such file or directory
Steps to reproduce
Run install.sh on a system with an empty /etc/apt/sources.list.d
What is the current bug behavior?
The relevant code starts at line 146 in install.sh, the code is
if [ "$(find /etc/apt/sources.list.d/ -mindepth 1 -maxdepth 1 -type f -name 'sympl_*.list' | wc -l )" != "0" ] \
|| [ "$( grep -c '^deb http://packages.mythic-beasts.com/mythic/' /etc/apt/sources.list.d/* )" != "0" ]; then
echo -n "Removing previous Sympl repo..."
find /etc/apt/sources.list.d/ -mindepth 1 -maxdepth 1 -type f -name 'sympl_*.list' -delete
sed -i 's|^deb http://packages.mythic-beasts.com/mythic/.*|#&|' /etc/apt/sources.list.d/*
echo " OK"
fi
placing this code in a file and running it with bash -x says:
~# bash -x ax
++ find /etc/apt/sources.list.d/ -mindepth 1 -maxdepth 1 -type f -name 'sympl_*.list'
++ wc -l
+ '[' 0 '!=' 0 ']'
++ grep -c '^deb http://packages.mythic-beasts.com/mythic/' '/etc/apt/sources.list.d/*'
grep: /etc/apt/sources.list.d/*: No such file or directory
+ '[' '' '!=' 0 ']'
+ echo -n 'Removing previous Sympl repo...'
Removing previous Sympl repo...+ find /etc/apt/sources.list.d/ -mindepth 1 -maxdepth 1 -type f -name 'sympl_*.list' -delete
+ sed -i 's|^deb http://packages.mythic-beasts.com/mythic/.*|#&|' '/etc/apt/sources.list.d/*'
sed: can't read /etc/apt/sources.list.d/*: No such file or directory
+ echo ' OK'
OK
What is the expected correct behavior?
I think this code should be skipped if the directory is empty.
Relevant logs and/or screenshots
(Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's very hard to read otherwise.)
Possible fixes
I worked around by adding touching a README file in /etc/apt/sources.list.d. However the code may need to be
if [ "$(find /etc/apt/sources.list.d/ -mindepth 1 -maxdepth 1 -type f -name 'sympl_*.list' | wc -l )" != "0" ]; then
if [ "$( grep -c '^deb http://packages.mythic-beasts.com/mythic/' /etc/apt/sources.list.d/* )" != "0" ]; then
echo -n "Removing previous Sympl repo..."
find /etc/apt/sources.list.d/ -mindepth 1 -maxdepth 1 -type f -name 'sympl_*.list' -delete
sed -i 's|^deb http://packages.mythic-beasts.com/mythic/.*|#&|' /etc/apt/sou rces.list.d/*
echo " OK"
fi
fi
Caveat: edited but not tested.
/cc @kelduum