use USER instead of whoami (#1134)
* use USER instead of whoami make gcloud_FigureRemoteUsername robust against unsolicited output (that I get on login ;) ) validate --prefix argument * Update gcloud.sh
This commit is contained in:
parent
6560b0e2cc
commit
fdc48d521c
|
@ -6,7 +6,7 @@ source "$here"/../scripts/gcloud.sh
|
|||
# shellcheck source=net/common.sh
|
||||
source "$here"/common.sh
|
||||
|
||||
prefix=testnet-dev-$(id -un | sed -e s/[^a-z0-9].*//)
|
||||
prefix=testnet-dev-${USER//[^A-Za-z0-9]/}
|
||||
validatorNodeCount=5
|
||||
clientNodeCount=1
|
||||
leaderMachineType=n1-standard-16
|
||||
|
@ -37,8 +37,8 @@ Configure a GCE-based testnet
|
|||
delete - delete the testnet
|
||||
|
||||
common options:
|
||||
-p prefix - Optional common prefix for instance names to avoid collisions
|
||||
(default: $prefix)
|
||||
-p prefix - Optional common prefix for instance names to avoid
|
||||
collisions (default: $prefix)
|
||||
|
||||
create-specific options:
|
||||
-n [number] - Number of validator nodes (default: $validatorNodeCount)
|
||||
|
@ -71,6 +71,7 @@ while getopts "h?p:Pi:n:c:z:ga:" opt; do
|
|||
usage
|
||||
;;
|
||||
p)
|
||||
[[ ${OPTARG//[^A-Za-z0-9]/} == "$OPTARG" ]] || usage "Invalid prefix: \"$OPTARG\", alphanumeric only"
|
||||
prefix=$OPTARG
|
||||
;;
|
||||
P)
|
||||
|
|
|
@ -196,7 +196,6 @@ gcloud_FigureRemoteUsername() {
|
|||
|
||||
echo "Detecting remote username using $zone in $zone:"
|
||||
|
||||
|
||||
# Figure the gcp ssh username
|
||||
(
|
||||
set -x
|
||||
|
@ -205,14 +204,18 @@ gcloud_FigureRemoteUsername() {
|
|||
# instance is reported as RUNNING and when it's reachable over the network
|
||||
timeout 30s bash -c "set -o pipefail; until ping -c 3 $publicIp | tr - _; do echo .; done"
|
||||
|
||||
gcloud compute ssh "$name" --zone "$zone" -- "echo whoami \$(id -un)" | tee whoami
|
||||
gcloud compute ssh "$name" --zone "$zone" -- "echo whoami:\$USER:iamwho" | tr -d $'\r '| tee /tmp/whoami-$$
|
||||
)
|
||||
while IFS=: read -r whoami gcloud_username iamwho ; do
|
||||
[[ $whoami == "whoami" && $iamwho == "iamwho" ]] && break;
|
||||
done < /tmp/whoami-$$
|
||||
rm -f /tmp/whoami-$$
|
||||
|
||||
if [[ -z $gcloud_username ]]; then
|
||||
echo Unable to figure remote user name
|
||||
exit 1
|
||||
fi
|
||||
|
||||
[[ "$(tr -dc '[:print:]' < whoami; rm -f whoami)" =~ ^whoami\ (.*)$ ]] || {
|
||||
echo Unable to figure remote user name;
|
||||
exit 1
|
||||
}
|
||||
gcloud_username="${BASH_REMATCH[1]}"
|
||||
echo "Remote username: $gcloud_username"
|
||||
}
|
||||
|
||||
|
@ -303,4 +306,3 @@ gcloud_PrepInstancesForSsh() {
|
|||
fi
|
||||
done
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue