File: ssh-add-key.sh

package info (click to toggle)
cockpit 356-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 317,176 kB
  • sloc: javascript: 775,374; python: 41,133; ansic: 33,875; cpp: 11,141; sh: 3,534; makefile: 581; xml: 262
file content (26 lines) | stat: -rwxr-xr-x 480 bytes parent folder | download | duplicates (8)
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
#! /bin/sh
# SPDX-License-Identifier: LGPL-2.1-or-later

set -euf

d=$HOME/.ssh
p=${2:-authorized_keys}
f=$d/$p

if ! test -f "$f"; then
    # shellcheck disable=SC2174 # yes, we know that -m only applies to the deepest directory
    mkdir -m 700 -p "$d"
    touch "$f"
    chmod 600 "$f"
fi

while read l; do
    if [ "$l" = "$1" ]; then
        exit 0
    fi
done <"$f"

# Add newline if necessary
! test -s "$f" || tail -c1 < "$f" | read -r _ || echo >> "$f"

echo "$1" >>"$f"