File: 15-root-ssh-key

package info (click to toggle)
fai 6.5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,084 kB
  • sloc: sh: 6,774; perl: 5,665; makefile: 138
file content (35 lines) | stat: -rwxr-xr-x 794 bytes parent folder | download | duplicates (2)
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
#! /bin/bash

# (c) Thomas Lange, 2022, lange@debian.org
#
# Add public ssh key for user root to get login access

error=0; trap 'error=$(($?>$error?$?:$error))' ERR # save maximum error code

SSHDIR=$target/root/.ssh
AUKEY=$SSHDIR/authorized_keys

# reverse order of classes
for c in $classes; do
    revclasses="$c $revclasses"
done

for c in $revclasses; do
    if [ -f $FAI/files/root-ssh-key/$c ]; then
        if [ -f $AUKEY ]; then
            cmp -s $FAI/files/root-ssh-key/$c $AUKEY
            if [ $? -eq 0 ]; then
                exit
            fi
        fi
        if [ ! -d $SSHDIR ]; then
            mkdir -m 700 $SSHDIR
        fi
        cp -v $FAI/files/root-ssh-key/$c $AUKEY
        chown root:root $AUKEY
        chmod 600 $AUKEY
        break
    fi
done

exit $error