Koozali.org formerly Contribs.org
Contribs.org Forums => Development => Topic started by: DanB35 on February 24, 2016, 01:19:29 PM
-
I'm having trouble getting a template fragment to work. It's throwing errors which I expect relate to my not having escaped everything I need to escape. Here's what I need to appear in the output:
if [ $1 = "deploy_cert" ] && [ $2 = "pbx.mydomain.tld" ]; then
KEY=$3
CERT=$4
CHAIN=${5/fullchain.pem/chain.pem}
scp $CERT root@pbx:/etc/pki/tls/certs/pbx.mydomain.tld.crt
scp $KEY root@pbx:/etc/pki/tls/private/pbx.mydomain.tld.key
scp $CHAIN root@pbx:/etc/pki/tls/certs/server-chain.crt
ssh root@pbx "/sbin/service httpd reload"
exit 0
fi
Here's what I have in the fragment:
{
use strict;
use warnings;
use esmith::ConfigDB;
my $configDB = esmith::ConfigDB->open_ro or die("can't open Config DB");
my $letsencryptStatus = $configDB->get_prop( 'letsencrypt', 'status' ) || 'disabled';
if ( $letsencryptStatus ne 'disabled' ) {
$OUT .= "if [ \$1 = \"deploy_cert\" ] && [ \$2 = \"pbx.mydomain.tld\" ]; then\n"
$OUT .= " KEY=\$3\n"
$OUT .= " CERT=\$4\n"
$OUT .= " CHAIN=\${5/fullchain.pem/chain.pem}\n"
$OUT .= " scp \$CERT root@pbx:/etc/pki/tls/certs/pbx.mydomain.tld.crt\n"
$OUT .= " scp \$KEY root@pbx:/etc/pki/tls/private/pbx.mydomain.tld.key\n"
$OUT .= " scp \$CHAIN root@pbx:/etc/pki/tls/certs/server-chain.crt\n"
$OUT .= " ssh root@pbx \"/sbin/service httpd reload\"\n"
$OUT .= " exit 0\n"
$OUT .= "fi\n"
}
}
...but when I try to expand the template, I get these errors:
[root@e-smith hook-script.sh]# expand-template /usr/local/bin/hook-script.sh
WARNING in /etc/e-smith/templates-custom//usr/local/bin/hook-script.sh/05deploy_cert_PBX: Scalar found where operator expected at /etc/e-smith/templates-custom//usr/local/bin/hook-script.sh/05deploy_cert_PBX line 13, near ""if [ \$1 = \"deploy_cert\" ] && [ \$2 = \"pbx.familybrown.org\" ]; then\n"
$OUT"
WARNING in /etc/e-smith/templates-custom//usr/local/bin/hook-script.sh/05deploy_cert_PBX: (Missing operator before
$OUT?)
ERROR in /etc/e-smith/templates-custom//usr/local/bin/hook-script.sh/05deploy_cert_PBX: Program fragment delivered error <<syntax error at /etc/e-smith/templates-custom//usr/local/bin/hook-script.sh/05deploy_cert_PBX line 13, near ""if [ \$1 = \"deploy_cert\" ] && [ \$2 = \"pbx.familybrown.org\" ]; then\n"
$OUT ">> at template line 1
ERROR: Template processing failed for //usr/local/bin/hook-script.sh: 2 fragments generated warnings, 1 fragment generated errors
at /sbin/e-smith/expand-template line 45
I'm assuming that I missed escaping something, but it isn't obvious to me at first glance what it is. Any suggestions?
-
You forgot the semi-colon at the end of your $OUT = XXX lines
But anyway, you'd better have something like
$OUT .=<<"_EOF";
if [ \$1 = "deploy_cert" ] && [ \$2 = "pbx.mydomain.tld" ]; then
KEY=\$3
CERT=\$4
CHAIN=\${5/fullchain.pem/chain.pem}
scp $CERT root\@pbx:/etc/pki/tls/certs/pbx.mydomain.tld.crt
scp $KEY root\@pbx:/etc/pki/tls/private/pbx.mydomain.tld.key
scp $CHAIN root\@pbx:/etc/pki/tls/certs/server-chain.crt
ssh root\@pbx "/sbin/service httpd reload"
exit 0
fi
_EOF
(In this case, as your not using any perl variable, you could even use <<'_EOF' in which case there's no need to escape $ and @)
-
You forgot the semi-colon at the end of your $OUT = XXX lines
Well, I figured I'd feel dumb when I learned the answer, and I do--but now I know. Thanks!
$OUT .=<<"_EOF";
So much the better. For the sake of posterity, I note that I also had to escape the $ in $CERT, etc. It seems to be working now. Thanks!
-
Please add [Solved] in front of the subject.
-
It won't let me edit the first post to change the subject.
-
Bummer, thanks for trying.
-
It won't let me edit the first post to change the subject.
I think editing is allowed only for 7 days from the original post date.
-
Well, I figured I'd feel dumb when I learned the answer, and I do--but now I know. Thanks!
So much the better. For the sake of posterity, I note that I also had to escape the $ in $CERT, etc. It seems to be working now. Thanks!
I also tried it and yeah it works! you just forgot the semi-colon at the end of your $OUT = XXX lines.. It's a good thing to know then!
-
Dan,
If you have a mod to the contrib then let me know and I can update it. I'm not on here so often so miss stuff. Just mail me.
B. Rgds
John