refactor script

This commit is contained in:
deityhub
2021-02-11 22:49:05 +01:00
parent 074fa99141
commit 4df7776386
3 changed files with 60 additions and 55 deletions

View File

@@ -6,21 +6,6 @@ echo "${TIMEZONE}" >/etc/TZ
cp /usr/share/zoneinfo/${TIMEZONE} /etc/localtime
initDkim() {
usage() {
echo " usage: ${0} <example.com> [haraka username]" 2>&1
echo 2>&1
exit 1
}
if [ -z "$DOMAIN" ]; then
usage
fi
if [ -z "$SMTPD" ]; then
SMTPD="www"
fi
# Create a directory for each DKIM signing domain
mkdir -p "$DOMAIN"
cd "$DOMAIN" || exit
@@ -35,9 +20,9 @@ initDkim() {
# rotate your keys frequently, choose 2048, at the expense of more CPU.
#
# grab the generated private key and write it to private file
# PRIVATE_KEY must be in base64 for this to work
# DKIM_PRIVATE_KEY must be in base64 for this to work
# This is a workaround for issue with passing private key through env
(echo $PRIVATE_KEY | base64 -d) >private
(echo $DKIM_PRIVATE_KEY | base64 -d) >private
chmod 0400 private
openssl rsa -in private -out public -pubout
@@ -51,8 +36,11 @@ initDkim() {
#run if there is no existing haraka config
if [[ ! -d "${DATADIR}/config" ]]; then
haraka -i ${DATADIR}
echo "$DOMAIN" >${DATADIR}/config/host_list
echo "$DOMAIN" >${DATADIR}/config/me
if [[ -n "$DOMAIN" ]]; then
echo "$DOMAIN" >${DATADIR}/config/host_list
echo "$DOMAIN" >${DATADIR}/config/me
fi
#enable toobusy plugin
sed -i 's/^#toobusy$\?/toobusy/g' ${DATADIR}/config/plugins
@@ -74,6 +62,9 @@ if [[ ! -d "${DATADIR}/config" ]]; then
(echo $TLS_KEY | base64 -d) >${DATADIR}/config/tls_key.pem
(echo $TLS_CERT | base64 -d) >${DATADIR}/config/tls_cert.pem
#enable tls
sed -i "s/^#\s*tls/tls/" ${DATADIR}/config/plugins
cat <<-EOF >>${DATADIR}/config/tls.ini
[outbound]
key=tls_key.pem
@@ -83,7 +74,7 @@ if [[ ! -d "${DATADIR}/config" ]]; then
fi
if [[ -n "$PRIVATE_KEY" ]]; then
if [[ -n "$DKIM_PRIVATE_KEY" ]] && [[ -n "$DOMAIN" ]]; then
#enable dkim sign
sed -i 's/^#dkim_sign$\?/dkim_sign/g' ${DATADIR}/config/plugins
@@ -143,9 +134,6 @@ if [[ ! -d "${DATADIR}/config" ]]; then
#enable auth_flat_file
sed -i "s/^#\s*auth\/flat_file/auth\/flat_file/" ${DATADIR}/config/plugins
#enable tls
sed -i "s/^#\s*tls/tls/" ${DATADIR}/config/plugins
cat <<-EOF >>${DATADIR}/config/auth_flat_file.ini
[core]
methods=PLAIN,LOGIN,CRAM-MD5

View File

@@ -3,23 +3,6 @@
# This is used to install Fyipe on a standalone VM
# This is usally used for CI/CD testing, and to update VM's on GCP, Azure and AWS.
# create private key and public key
echo "Setup private and public key"
openssl genrsa -out private 2048
chmod 0400 private
openssl rsa -in private -out public -pubout
# value of DKIM dns record
echo "DKIM DNS TXT Record"
echo "DNS Selector: fyipe._domainkey"
echo "DNS Value: v=DKIM1;p=$(grep -v '^-' public | tr -d '\n')"
export PRIVATE_KEY=$(cat private | base64)
# generate tls_cert.pem and tls_key.pem files with there keys
echo "Setup tls_cert and tls_key"
openssl req -x509 -nodes -days 2190 -newkey rsa:2048 -keyout tls_key.pem -out tls_cert.pem -subj "/C=US/ST=Massachusetts/L=Boston/O=Hackerbay/CN=globalminimalism.com"
# Encode your tls to base64 and export it
export TLS_KEY=$(cat tls_key.pem | base64)
export TLS_CERT=$(cat tls_cert.pem | base64)
# If this is the first install, then helm wont be found.
if [[ ! $(which helm) ]]
then
@@ -55,6 +38,32 @@ then
sudo apt-get install -y python-jsonpath-rw
fi
if [[ ! -n $DOMAIN ]]; then
export DOMAIN=fyipe.com
fi
if [[ ! -n $DKIM_PRIVATE_KEY ]]; then
# create private key and public key
echo "Setup private and public key"
openssl genrsa -out private 2048
chmod 0400 private
openssl rsa -in private -out public -pubout
# value of DKIM dns record
echo "DKIM DNS TXT Record"
echo "DNS Selector: fyipe._domainkey"
echo "DNS Value: v=DKIM1;p=$(grep -v '^-' public | tr -d '\n')"
export DKIM_PRIVATE_KEY=$(cat private | base64)
fi
if [[ ! -n $TLS_KEY ]] && [[ ! -n $TLS_CERT ]]; then
# generate tls_cert.pem and tls_key.pem files with there keys
echo "Setup tls_cert and tls_key"
openssl req -x509 -nodes -days 2190 -newkey rsa:2048 -keyout tls_key.pem -out tls_cert.pem -subj "/C=US/ST=Massachusetts/L=Boston/O=Hackerbay/CN=$DOMAIN"
# Encode your tls to base64 and export it
export TLS_KEY=$(cat tls_key.pem | base64)
export TLS_CERT=$(cat tls_cert.pem | base64)
fi
#Install Docker and setup registry and insecure access to it.
if [[ ! $(which docker) ]]
then

View File

@@ -6,23 +6,31 @@ if [[ ! $(which docker) && ! $(docker --version) ]]; then
exit
fi
# create private key and public key
openssl genrsa -out private 2048
chmod 0400 private
openssl rsa -in private -out public -pubout
if [[ ! -n $DOMAIN ]]; then
export DOMAIN=fyipe.com
fi
# value of DKIM dns record
echo "DKIM DNS TXT Record"
echo "DNS Selector: fyipe._domainkey"
echo "DNS Value: v=DKIM1;p=$(grep -v '^-' public | tr -d '\n')"
export PRIVATE_KEY=$(cat private | base64)
if [[ ! -n $DKIM_PRIVATE_KEY ]]; then
# create private key and public key
echo "Setup private and public key"
openssl genrsa -out private 2048
chmod 0400 private
openssl rsa -in private -out public -pubout
# value of DKIM dns record
echo "DKIM DNS TXT Record"
echo "DNS Selector: fyipe._domainkey"
echo "DNS Value: v=DKIM1;p=$(grep -v '^-' public | tr -d '\n')"
export DKIM_PRIVATE_KEY=$(cat private | base64)
fi
# generate tls_cert.pem and tls_key.pem files with there keys
openssl req -x509 -nodes -days 2190 -newkey rsa:2048 -keyout tls_key.pem -out tls_cert.pem -subj "/C=US/ST=Massachusetts/L=Boston/O=Hackerbay/CN=globalminimalism.com"
# Encode your tls to base64 and export it
export TLS_KEY=$(cat tls_key.pem | base64)
export TLS_CERT=$(cat tls_cert.pem | base64)
if [[ ! -n $TLS_KEY ]] && [[ ! -n $TLS_CERT ]]; then
# generate tls_cert.pem and tls_key.pem files with there keys
echo "Setup tls_cert and tls_key"
openssl req -x509 -nodes -days 2190 -newkey rsa:2048 -keyout tls_key.pem -out tls_cert.pem -subj "/C=US/ST=Massachusetts/L=Boston/O=Hackerbay/CN=$DOMAIN"
# Encode your tls to base64 and export it
export TLS_KEY=$(cat tls_key.pem | base64)
export TLS_CERT=$(cat tls_cert.pem | base64)
fi
sudo chmod +x ./uninstall.sh
sudo ./uninstall.sh