From 460a4f5b7d58e2e0e1059d2752d9bf794cd402b3 Mon Sep 17 00:00:00 2001 From: Adar Nimrod <nimrod@shore.co.il> Date: Tue, 1 Dec 2015 13:55:55 +0200 Subject: [PATCH] Better error handling. --- ssl/dhparams | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/ssl/dhparams b/ssl/dhparams index 3a7b886..a05473f 100755 --- a/ssl/dhparams +++ b/ssl/dhparams @@ -1,23 +1,15 @@ #!/bin/sh -e . "$1" -if [ -z "$path" ] -then - echo "failed=True msg=Path not set." +fail () +{ + echo "{\"failed\": true, \"msg\": \"$1\"}" exit -fi +} -if [ ! -r $path ] -then - echo "failed=True msg=Can\'t access path." - exit -fi - -if [ ! -f $path ] -then - echo "failed=True msg=Path doesn't exist or is not a file." - exit -fi +test -z "$path" && fail "Parameter 'path' is not set." +test ! -r "$path" && fail "Can't access 'path'." +test ! -f "$path" && fail "Parameter 'path' doesn't exists or is not a file." bits="$(openssl dhparam -in $path -text -noout \ | sed -n 's/[a-zA-Z#0-9 \-]*Parameters: (\([0-9]*\) bit)/\1/p')" -- GitLab