Created
April 11, 2011 22:49
-
-
Save felixhummel/914546 to your computer and use it in GitHub Desktop.
Get a (self-signed) SSL certificate for Ubuntu 10.10
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HOSTNAME=$1 | |
TMPFILE=`mktemp` | |
FNAME=$HOSTNAME.crt | |
expect_cmd() { | |
cmd=$1 | |
package=$2 | |
which $cmd &> /dev/null | |
if [[ $? != 0 ]]; then | |
echo "ERROR: Tool needed: '$cmd'. Try" | |
echo " sudo apt-get install $package" | |
exit 1 | |
fi | |
} | |
expect_cmd unix2dos tofrodos | |
expect_cmd openssl openssl | |
# We need a "here document" [1] for input (i.e. the QUIT command) and | |
# a subshell [2] to be able to pipe the output. | |
# Then we use sed to cut irrelevant lines and convert LFs to CRLFs. | |
# [1] http://tldp.org/LDP/abs/html/here-docs.html | |
# [2] http://stackoverflow.com/questions/2128949/how-to-pipe-a-here-document-through-a-command-and-capture-the-result-into-a-varia | |
(openssl s_client -connect $HOSTNAME:443 << EOF | |
QUIT | |
EOF | |
) 2> /dev/null | sed -n '/-----BEGIN CERTIFICATE-----/,/-----END CERTIFICATE-----/p' | tee | unix2dos > $TMPFILE | |
echo "copying to /usr/local/share/ca-certificates/, ok?" | |
read || exit 1 | |
echo "verifying and installing" | |
openssl verify $TMPFILE && ( | |
sudo cp $TMPFILE /usr/local/share/ca-certificates/$FNAME | |
sudo update-ca-certificates | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment