summaryrefslogtreecommitdiffstats
path: root/deploy/adapters/cobbler/snippets/ssh.xml
blob: 96fe8bb04814d0862213e53d10c843d62c8e3450 (plain)
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
45
46
#set ssh_keys = $getVar("push_ssh_keys", "/root/.ssh/id_rsa.pub")
#if $ssh_keys != ""
    #set user_name = $getVar("username", "root")
    #if $user_name == "root"
        #set home = "/root"
    #else
        #set home = "/home/%s" % $user_name
    #end if
<file>
  <file_path>$home/.ssh/authorized_keys</file_path>
  <file_owner>${user_name}.${user_name}</file_owner>
  <file_permissions>600</file_permissions>
  <file_script>
    <interpreter>shell</interpreter>
    <source>
<![CDATA[
\#!/bin/bash
mkdir -p $home/.ssh
chmod 700 -R $home/.ssh
    #set $firstline = True
    #for $ssh_key in $ssh_keys.split(',')
        #if not $ssh_key
            #continue
        #end if
        #try
            #set f = $open($ssh_key)
            #if $firstline
cat << EOL > $home/.ssh/authorized_keys
                #echo $f.read()
EOL
            #else
cat << EOL >> $home/.ssh/authorized_keys
                #echo $f.read()
EOL
            #end if
            #set $firstline = False
            #silent $f.close()
        #except
# failed to read from $ssh_key
        #end try
    #end for
]]>
    </source>
  </file_script>
</file>
#end if