iv been working on combining these two scripts:
https://gist.github.com/dmytro/0606cb32e42fc0918466
https://gist.github.com/RichardBronosky/331f975bba6697e5a15217233d280c06
into this:
#!/bin/bash
cd /etc/openvpn
read -p "please enter the user name for the new file: " USER
[ -z ${USER} ] && { echo “cannot be empty”; exit 1; }
[ -f keys/${USER}.crt ] && { echo “Certificate keys/${USER}.crt already exists”; exit 2; }
source ./vars
./build-key ${USER}
cd /etc/openvpn/keys
(
cat config.ovpn.tpl
echo ‘’
cat ${USER}.key
echo ‘’
echo ‘’
cat ${USER}.crt
echo ‘’
echo ‘’
cat ${USER}.crt
echo ‘’
) > openvpn_${USER}.ovpn
sleep 5
src = “openvpn_${USER}.ovpn”
$1 = $src
dst = “$(basename $src .ovpn)_packed.ovpn”
gawk -f - $src > $dst << ‘AWK’
BEGIN {
RS="\n|\r\n"
}
function readcert(file) {
while ((getline < file) > 0) {
contents = contents RT $0
if ($1 == “-----BEGIN”)
contents = $0
if ($1 == “-----END”)
break
}
close(file)
return contents
}
$1 ~ /^(ca|key|cert)$/ {
tag = $1
print “#” $0
print “<” tag “>”
print readcert($2)
print “</” tag “>”
next
}
{
print
}
AWK
but i cant get past this:
can someone please make me look like an idiot and point out the issue, i don’t do this as often as some of you might