enable_service() {
# Enable services for Ubuntu instances
+ # We purposely want to allow globbing to build the package array
+ # shellcheck disable=SC2206
services=($@)
for service in "${services[@]}"; do
# On Ubuntu sometimes the mirrors fail to install a package. This wrapper
# checks that a package is successfully installed before moving on.
+ # We purposely want to allow globbing to build the package array
+ # shellcheck disable=SC2206
packages=($@)
for pkg in "${packages[@]}"
# Retry installing package 5 times if necessary
for i in {0..5}
do
+
+ # Wait for any background apt processes to finish before running apt
+ while pgrep apt > /dev/null; do sleep 1; done
+
echo "$i: Installing $pkg"
if [ "$(dpkg-query -W -f='${Status}' "$pkg" 2>/dev/null | grep -c "ok installed")" -eq 0 ]; then
apt-cache policy "$pkg"
EOF
- # Add hostname to /etc/hosts to fix 'unable to resolve host' issue with sudo
- sed -i "/127.0.0.1/s/$/ $(hostname)/" /etc/hosts
-
echo "---> Updating operating system"
# add additional repositories
echo "No extra steps for $FACTER_OS"
;;
esac
+
+ # Update /etc/nss-switch.conf to map hostname with IP instead of using `localhost`
+ # from /etc/hosts which is required by some of the Java API's to avoid
+ # Java UnknownHostException: "Name or service not known" error.
+ sed -i "/^hosts:/s/$/ myhostname/" /etc/nsswitch.conf
}
echo "---> Attempting to detect OS"