From 045c3198b99a34a6c48159320d9602e5c8ec0141 Mon Sep 17 00:00:00 2001 From: Julien Escario Date: Tue, 21 Jul 2020 14:05:41 +0200 Subject: [PATCH] Install script is now POSIX compliant (tested with bash, ksh, zsh and dash) --- ssh/install_altinea_pubkey.sh | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ssh/install_altinea_pubkey.sh b/ssh/install_altinea_pubkey.sh index 2ad729a..54428fb 100755 --- a/ssh/install_altinea_pubkey.sh +++ b/ssh/install_altinea_pubkey.sh @@ -6,7 +6,7 @@ ED25519_FINGERPRINT="SHA256:TagxgsBxZhHFWiThYwe/hZSYjLBOHWBY2Ss0QsipmTw noc@alti ED25519_KEYURL="https://gitlab.altinea.fr/altinea/install-scripts/raw/branch/master/ssh/altinea-ed25519.pub" if [ -x "$(which curl)" ] ; then - COMMAND="curl $" + COMMAND="curl -s " echo "Found curl, using it" elif [ -x "$(which wget)" ]; then COMMAND="wget -q -O - " @@ -16,36 +16,31 @@ else exit 3; fi -if [[ ! -d ~/.ssh ]]; -then +if [ ! -d ~/.ssh ]; then mkdir ~/.ssh chmod 700 ~/.ssh fi -if [[ -w ~/.ssh/authorized_keys2 ]] +if [ -w ~/.ssh/authorized_keys2 ] then echo "It seems you're still relying on authorized_keys2, this is (almost) deprecated." exit 1; else touch ~/.ssh/authorized_keys - if [ $(grep -c "$RSA_FINGERPRINT" <(ssh-keygen -E sha256 -lf ~/.ssh/authorized_keys 2>/dev/null)) -eq 1 ] + if [ $(ssh-keygen -E sha256 -lf ~/.ssh/authorized_keys 2>/dev/null |grep -c "$RSA_FINGERPRINT") -ne 0 ] then echo "Altinea RSA CA fingerprint found in authorized_keys file, not adding" - exit 2; else $COMMAND $RSA_KEYURL >> ~/.ssh/authorized_keys echo "Altinea RSA CA key deployed on account" `whoami` - exit 0; fi - if [ $(grep -c "$ED25519_FINGERPRINT" <(ssh-keygen -E sha256 -lf ~/.ssh/authorized_keys 2>/dev/null)) -eq 1 ] + if [ $(ssh-keygen -E sha256 -lf ~/.ssh/authorized_keys 2>/dev/null |grep -c "$ED25519_FINGERPRINT") -ne 0 ] then echo "Altinea ED25519 CA fingerprint found in authorized_keys file, not adding" - exit 2; else $COMMAND $ED25519_KEYURL >> ~/.ssh/authorized_keys echo "Altinea ED25519 CA key deployed on account" `whoami` - exit 0; fi fi -exit 99; +exit 0;