File: ssh-add-key.sh

package info (click to toggle)
cockpit 355-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 311,568 kB
  • sloc: javascript: 774,787; python: 40,655; ansic: 35,157; cpp: 11,141; sh: 3,512; makefile: 580; xml: 261
file content (25 lines) | stat: -rwxr-xr-x 435 bytes parent folder | download | duplicates (13)
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
#! /bin/sh

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"