I am creating an AWS distributor package to modify the syslog configuration on different flavors of Linux servers. I wrote a few simple bash scripts to handle the install, uninstall, and update. I thought this would be universal. However, today I found out that AWS uses sh
to execute the script (i.e. sh install.sh
) and on Ubuntu/Debian this defaults to DASH and not BASH. For that reason my scripts fail with:
update errors: update.sh: 3: update.sh: function: not found
update.sh: 9: update.sh: Syntax error: "}" unexpected
failed to run commands: exit status 2
Failed to install package; install status Failed
I can't change the AWS behavior. And I don't want to modify any configurations on the server. So, it would appear my only options are that which modify the script file itself?
The first preference would be to make the script universal so it can run on any flavor of Linux. The second preference would be to create a different script for Debian that is DASH compatible.
Unfortunately, I don't find much information about dash programming. Any suggestions?
The 3 scripts in question are....
install.sh
#!/bin/bash
function isInstalled {
if sudo ls /etc/rsyslog.d/xdr.conf >/dev/null 2>&1; then
true
else
false
fi
}
if isInstalled; then
exit 0
else
sudo cp xdr.conf /etc/rsyslog.d/xdr.conf
sudo service rsyslog restart
fi
uninstall.sh
#!/bin/bash
function isInstalled {
if sudo ls /etc/rsyslog.d/xdr.conf >/dev/null 2>&1; then
true
else
false
fi
}
if isInstalled; then
sudo rm /etc/rsyslog.d/xdr.conf
sudo service rsyslog restart
else
exit 0
fi
update.sh
#!/bin/bash
function isDiff {
if sudo diff xdr.conf /etc/rsyslog.d/xdr.conf >/dev/null 2>&1; then
false
else
true
fi
}
if isDiff; then
sudo cp xdr.conf /etc/rsyslog.d/xdr.conf
sudo service rsyslog restart
else
exit 0
fi