I'm writing a script to customize a clean installation of Linux and there are several sections where it runs apt-get install. I've encountered some issues with my connection where it will occasionally stop working which can cause apt-get to fail and when this happens the script would continue to process the other commands.
The following script works, except now I'm hitting another issue: if the function is issued as aptinstall firefox firefox-locale-en
for example, it only installs the first package that's listed.
I modified the script so that apt-get is run within a function that will retry if it fails up to 5 times:
# Install package - will retry download if connection fails up to 5 times and abort if unsuccessful
function aptinstall (){
local __pkg=$1
set +x
n=0
until [ $n -ge 5 ]
do
apt-get install -y $__pkg && break
n=$[$n+1]
sleep 15 # Wait 15 seconds before trying to download and install packages again
done
if [ "$n" -eq 5 ]; then
echo >&2 "An error has occurred. Please check your network connection."
exit 1
fi
Can anyone help me figure out why only the first package is installed? Thanks!
for __pkg do
for __pkg do
results in install.sh: line 39: syntax error near unexpected token `}' where the end of the function is. I must be missing something but I'm not sure what it is, my bash scripting skills have gotten pretty rusty.