Skip to content

Commit 08eca41

Browse files
committed
ocp-mco-sshkey.sh: syntax improvements
1 parent d07cc77 commit 08eca41

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

systemd/ocp-mco-sshkey.sh

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,42 @@
11
#!/bin/bash
22

3+
set -o pipefail
4+
set -o errexit
5+
set -o nounset
6+
set -o errtrace
37
set -x
48

59
source /usr/local/bin/crc-systemd-common.sh
610
export KUBECONFIG="/opt/kubeconfig"
711

8-
pub_key_path="/opt/crc/id_rsa.pub"
12+
PUB_KEY_PATH="/opt/crc/id_rsa.pub"
913

10-
if [ ! -f "${pub_key_path}" ]; then
14+
if [ ! -f "$PUB_KEY_PATH" ]; then
1115
echo "No pubkey file found"
1216
exit 1
1317
fi
1418

19+
wait_for_resource_or_die machineconfig
20+
1521
echo "Updating the public key resource for machine config operator"
16-
pub_key=$(tr -d '\n\r' < ${pub_key_path})
17-
wait_for_resource machineconfig
18-
if ! oc patch machineconfig 99-master-ssh -p "{\"spec\": {\"config\": {\"passwd\": {\"users\": [{\"name\": \"core\", \"sshAuthorizedKeys\": [\"${pub_key}\"]}]}}}}" --type merge;
19-
then
20-
echo "failed to update public key to machine config operator"
21-
exit 1
22-
fi
22+
pub_key=$(cat "${PUB_KEY_PATH}" | tr -d '\n\r')
23+
24+
jq -n --arg key "${pub_key}" '
25+
{
26+
"spec": {
27+
"config": {
28+
"passwd": {
29+
"users": [
30+
{
31+
"name": "core",
32+
"sshAuthorizedKeys": [ $key ]
33+
}
34+
]
35+
}
36+
}
37+
}
38+
}' | oc patch machineconfig 99-master-ssh --type merge --patch-file=/dev/stdin
39+
40+
echo "All done"
41+
42+
exit 0

0 commit comments

Comments
 (0)