#!/bin/sh yourip=68.48.18.140 h=$yourip n=andy key_basename=ssh_host_rsa_key input_key=/etc/ssh/$key_basename ssh2der() { ssh-keygen -e -f "$1" -m PEM | openssl rsa -RSAPublicKey_in -outform DER } match_and_drop_first_word() { expect=$1 while read word rest do if [ "$word" = "$expect" ] then printf '%s\n' "$rest" return fi done false } keyscan() { if [ -e keyscan.cache ] then cat keyscan.cache else ssh-keyscan -t rsa "$1" fi } keycopy() { openssl rsa -in "$input_key" -outform DER > /etc/swanctl/private/"$key_basename" openssl rsa -in "$input_key" -pubout -outform DER > /etc/swanctl/pubkey/"$key_basename".pub t=$(mktemp) keyscan "$yourip" | match_and_drop_first_word "$yourip" > "$t" ssh2der "$t" > /etc/swanctl/pubkey/"$n".pub rm -f "$t" } nocomments() { sed 's/#.*//; /^ *$/d' } write_config() { conn=$1 remote_addrs=$2 id=$3 cat > /etc/swanctl/conf.d/"$conn".conf <