ocis-deployment/gen-secrets.sh

61 lines
1.6 KiB
Bash

#!/bin/sh
script_name=$0
force=$(test "$1" = force && echo true || echo false)
function usage() {
if test $# -gt 0
then
echo "$@"
echo
echo ---------
echo
fi
echo "$script_name [force]"
echo generates secrets
echo overwrites files if "force" is passed as an argument
exit 1
}
# Generate a random base64 string of $1 random bytes. The length argument is the
# number of bytes the base64 string represents, not the length of the string.
function randomString() {
openssl rand -base64 ${1:-36}
}
openssl version > /dev/null || usage error: openssl is not installed
if test -s mounts/wopi/wopi.secret && test $force = false
then
echo WOPI secret already exists, not generating a new secret
else
randomString 48 > mounts/wopi/wopi.secret
fi
source ./.env
if test -z "$COLLABORA_ADMIN_USER"
then
echo COLLABORA_ADMIN_USER=$(randomString 24) >> .env
else
if test $force = false
then
echo Collabora username already generated, not overwriting
else
echo Collabora username was already $COLLABORA_ADMIN_USER, overwriting
sed -i "s/^(COLLABORA_ADMIN_USER=).+\$/\1$(randomString 24)/" .env
fi
fi
if test -z "$COLLABORA_ADMIN_PASSWORD"
then
echo COLLABORA_ADMIN_PASSWORD=$(randomString 36) >> .env
else
if test $force = false
then
echo Collabora password already generated, not overwriting
else
echo Collabora password was already $COLLABORA_ADMIN_PASSWORD, overwriting
sed -i "s/^(COLLABORA_ADMIN_PASSWORD=).+\$/\1$(randomString 24)/" .env
fi
fi