#===============================================================================
#
# FILE: genSSLcsr.sh
#
# USAGE: ./genSSLcsr.sh [options]
#
# DESCRIPTION: ++++model 1.zero.2
# Fixed few bugs from earlier script
# +Removing passphrase after CSR era
# Extended use of features
# Checks for legitimate frequent title
# ++++1.zero.three
# Fixed line breaks
# Work listing to be created in the beginning
# Used getopts for higher code preparations
# ++++1.zero.four
# Added mail characteristic (experimental right now and wishes
# a mail server working domestically.)
# Added area enter and certificates topic inputs
#
# OPTIONS: —
# REQUIREMENTS: openssl, mailx
# BUGS: —
# NOTES: —
# AUTHOR: Abhishek Tamrakar (), [email protected]
# ORGANIZATION: Self
# CREATED: 6/24/2016
# REVISION: four
# COPYRIGHT AND
# LICENSE: Copyright (C) 2016 Abhishek Tamrakar
#
# Licensed underneath the Apache License, Version 2.zero (the “License”);
# you could not use this file besides in compliance with the License.
# You could receive a replica of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by relevant regulation or agreed to in writing, software program
# distributed underneath the License is distributed on an “AS IS” BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, both specific or implied.
# See the License for the precise language governing permissions and
# limitations underneath the License.
#===============================================================================
#variables ges right here
#set basename to scriptname
SCRIPT=$zero##*/
#set flags
TFOUND=zero
CFOUND=zero
MFOUND=zero
XFOUND=zero
SFOUND=zero
logdir=/var/log
# edit these under values to switch with yours
homedir=”
yourdomain=”
nation=IN
state=Maharashtra
locality=Pune
group=”your_organization”
organizationalunit=”your_organizational_unit”
e mail=your_email@your_domain
password=your_ssl_password
# OS is asserted and shall be utilized in its subsequent model
OS=$(egrep -io ‘Redhat|centos|fedora|ubuntu’ /and so forth/subject)
### perform declarations ###
data()
printf ‘npercentstpercentst’ “INFO” “$@”
#exit on error with a customized error message
#the additional perform was eliminated and changed withonly one.
#utilizing FAILEDne<message> is a approach however not essentially required.
#
deadly()
printf ‘npercentstpercentsn’ “ERROR” “$@”
exit 1
checkperms()
if [[ -z $homedir ]]; then
homedir=$(pwd)
fi
if [[ -w $homedir ]]; then
data “Permissions acquired for $ on $homedir.”
else
deadly “InSufficient permissions to run the $.”
fi
examineDomain()
grep -E -i -q “$yourdomain$” && echo -n “[OK]” # finish perform examineDomain
utilization()
Sets the worth of take away passphrase.
true:[default] passphrase shall be faraway from key.
false: passphrase won’t be eliminated and key wont get printed.
-m # finish utilization
confirmUserAction()
whereas true; do
learn -p “Do you wish to continue? ans: ” yn
case $yn in
[Yy]* ) data “Initiating the process”;
break;;
[Nn]* ) exit 1;;
* ) data “Please answer yes or no.”;;
esac
completed
# finish perform confirmUserAction
parseSubject()
sed ‘s/// /g;s/^ //g’)
for i in $; do
case $i%=* in
‘C’ )
nation=$i##*=
;;
‘ST’ )
state=$i##*=
;;
‘L’ )
locality=$i##*=
;;
‘O’ )
group=$i##*=
;;
‘OU’ )
organizationalunit=$i##*=
;;
’emailAddress’ )
e mail=$i##*=
;;
esac
completed
sendMail()
deadly “error in sending mail.”
fi
genCSRfile()
deadly “unable to perfom move”
data “Swapping insecure key to $cn.key”
mv $/$cn.insecure $/$cn.key
&& echo -n “[DONE]”
printCSR()
### END Functions ###
#Check the variety of arguments. If none are handed, print assist and exit.
NUMARGS=$#
if [ $NUMARGS -eq 0 ]; then
deadly “$NUMARGS Arguments provided !!!! See usage with ‘-h'”
fi
#Organisational particulars
whereas getopts “:c:d:s:m:p:rhx” atype
do
case $atype in
c )
CFOUND=1
cn=”$OPTARG”
;;
d )
yourdomain=”$OPTARG”
;;
s )
SFOUND=1
subj=”$OPTARG”
;;
p )
password=”$OPTARG”
;;
r )
REMOVEPASSPHRASE=’false’
;;
m )
MFOUND=1
ccemail=”$OPTARG”
;;
x )
XFOUND=1
;;
h )
utilization
;;
? )
utilization
;;
: )
deadly “Argument required !!! see ‘-h’ for help”
;;
esac
completed
shift $(($OPTIND – 1))
#### END CASE #### START MAIN ####
if [ $CFOUND -eq 1 ]
then
# take present dir as homedir by default.
checkperms $homedir
examineDomain
if [[ ! -d $ ]]
then
mkdir $workdir:-$ 2>/dev/null && data “$ created.”
else
data “$ exists.”
fi # finish workdir examine
parseSubject “$subj”
genCSRfile
if [ $XFOUND -eq 0 ]
then
sleep 2
printCSR
fi # finish x examine
if [[ $MFOUND -eq 1 ]]; then
sendMail
fi
else
deadly “Nothing to do!”
fi # finish frequent title examine
##### END MAIN #####