| 1 | #!/bin/shscip-shell filesystem . . `/bin/sh`. |
| 2 | set -e |
| 3 | |
| 4 | # if we are not bind mounting in certs or the user has not already generated certs |
| 5 | # create self-signed certs |
| 6 | if [scip-shell system . . `[`. ! -f $RO_CERTS ] || [scip-shell system . . `[`. ! -f $RO_KEYS ]; then |
| 7 | mkdirscip-shell system . . mkdir. -p $RO_DATA |
| 8 | chmodscip-shell system . . chmod. 700 $RO_DATA |
| 9 | chownscip-shell system . . chown. -R redoctober:redoctober $RO_DATA |
| 10 | |
| 11 | # Generate private key with password "$RO_CERTPASSWD" |
| 12 | opensslscip-shell system . . openssl. genrsa -aes128 -passout pass:$RO_CERTPASSWD -out $RO_KEYS 2048 |
| 13 | # Remove password from private key |
| 14 | opensslscip-shell system . . openssl. rsa -passin pass:$RO_CERTPASSWD -in $RO_KEYS -out $RO_KEYS |
| 15 | # Generate CSR (make sure the common name CN field matches your server |
| 16 | # address. It's set to "RO_COMMONNAME" environment variable here.) |
| 17 | opensslscip-shell system . . openssl. req -new -key $RO_KEYS -out $RO_DATA/server.csr -subj "/C=US/ST=California/L=Everywhere/CN=${RO_COMMONNAME}" |
| 18 | # Sign the CSR and create certificate |
| 19 | opensslscip-shell system . . openssl. x509 -req -days 365 -in $RO_DATA/server.csr -signkey $RO_KEYS -out $RO_CERTS |
| 20 | |
| 21 | # Clean up |
| 22 | rmscip-shell system . . rm. $RO_DATA/server.csr |
| 23 | chmodscip-shell system . . chmod. 600 $RO_CERTS $RO_KEYS |
| 24 | chownscip-shell system . . chown. -R redoctober $RO_CERTS $RO_KEYS |
| 25 | |
| 26 | echoscip-shell system . . echo. |
| 27 | echoscip-shell system . . echo. "Generated default certificates for RedOctobeer at $RO_CERTS and $RO_KEYS" |
| 28 | echoscip-shell system . . echo. |
| 29 | fi |
| 30 | |
| 31 | if [scip-shell system . . `[`. "$1" = 'redoctober' ]; then |
| 32 | exec chpst -u redoctober "$@" |
| 33 | fi |
| 34 | |
| 35 | exec "$@" |