#!/bin/bash
set -e
for file in "dsaparam.pem" "dsa_priv.pem" "dsa_pub.pem"; do
  if [ -e "$file" ]; then
    echo "There's already a $file here! Move it aside or be more careful!"
    exit 1
  fi
done

openssl="/usr/bin/openssl"
$openssl gendsa <($openssl dsaparam 2047) -out dsa_priv.pem
chmod 0400 dsa_priv.pem
$openssl dsa -in dsa_priv.pem -pubout -out dsa_pub.pem

echo "
Generated two files:
dsa_priv.pem: your private key. Keep it secret and don't share it!
dsa_pub.pem: public counterpart to include in the app bundle.

BACK UP YOUR PRIVATE KEY AND KEEP IT SAFE!
If you lose it, your users will be unable to upgrade!
"

open -R dsa_priv.pem
