Vous pouvez détecter la distribution sur l'hôte distant et la déployer en conséquence. en deploy.sh:
DISTRO=`ssh -o 'StrictHostKeyChecking no' ${host} 'bash -s' < bootstrap.sh`
La variable distro est peuplée par tout ce qui est repris par le script bootstrap.sh, qui est exécuté sur la machine hôte. Donc, nous pouvons maintenant utiliser bootstrap.sh pour détecter la distro ou tout autre paramètre de serveur dont nous avons besoin et echo, qui sera envoyé au script local et vous pourrez répondre en conséquence.
exemple deploy.sh:
#!/bin/bash
# Usage: ./deploy.sh [host]
host="${1}"
if [ -z "$host" ]; then
echo "Please provide a host - eg: ./deploy [email protected]"
exit 1
fi
echo "deploying to ${host}"
# The host key might change when we instantiate a new VM, so
# we remove (-R) the old host key from known_hosts
ssh-keygen -R "${host#*@}" 2> /dev/null
# rough test for what distro the server is on
DISTRO=`ssh -o 'StrictHostKeyChecking no' ${host} 'bash -s' < bootstrap.sh`
if [ "$DISTRO" == "FED" ]; then
echo "Detected a Fedora, RHEL, CentOS distro on host"
tar cjh . | ssh -o 'StrictHostKeyChecking no' "$host" '
rm -rf /tmp/chef &&
mkdir /tmp/chef &&
cd /tmp/chef &&
tar xj &&
bash install.sh'
elif [ "$DISTRO" == "DEB" ]; then
echo "Detected a Debian, Ubuntu distro on host"
tar cj . | ssh -o 'StrictHostKeyChecking no' "$host" '
sudo rm -rf ~/chef &&
mkdir ~/chef &&
cd ~/chef &&
tar xj &&
sudo bash install.sh'
fi
exemple bootstrap.sh:
#!/bin/bash
# Fedora/RHEL/CentOS distro
if [ -f /etc/redhat-release ]; then
echo "FED"
# Debian/Ubuntu
elif [ -r /lib/lsb/init-functions ]; then
echo "DEB"
fi
Cela vous permettra de détecter la plate-forme très tôt dans le processus de déploiement.
Avez-vous une question? – Cairnarvon
J'ai une solution à ce que je pensais être utile aux autres, je pensais que je posais la question et que je répondais - mais je dois attendre 8 heures. – offwhite