File: ssh.sh

package info (click to toggle)
golang-github-vmware-govmomi 0.24.2-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,848 kB
  • sloc: sh: 2,285; lisp: 1,560; ruby: 948; xml: 139; makefile: 54
file content (44 lines) | stat: -rw-r--r-- 868 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function public-key {
  local dir=${HOME}/.ssh

  for f in $HOME/.ssh/{id_{rsa,dsa},*}.pub; do
    if [ -r $f ]; then
      echo $f
      return
    fi
  done

  echo "Can't find public key file..."
  exit 1
}

PUBLIC_KEY_FILE=${PUBLIC_KEY_FILE-$(public-key)}
SSH_OPTS="-oStrictHostKeyChecking=no -oUserKnownHostsFile=/dev/null -oLogLevel=quiet"

function upload-public-key {
  local vm_name=$1
  local dir=$2

  if [ -z "$dir" ]
  then
    uid=$(echo $GOVC_GUEST_LOGIN | awk -F: '{print $1}')
    dir=$(govc guest.getenv -vm ${vm_name} HOME | awk -F= '{print $2}')

    if [ -z "$dir" ]
    then
      echo "Can't find ${uid}'s HOME dir..."
      exit 1
    fi
  fi

  govc guest.mkdir \
       -vm ${vm_name} \
       -p \
       ${dir}/.ssh

  govc guest.upload \
       -vm ${vm_name} \
       -f \
       ${PUBLIC_KEY_FILE} \
       ${dir}/.ssh/authorized_keys
}