bin/gen_key.sh

17 lines
410 B
Bash
Executable File

#!/bin/bash
errcho() {
echo $* >&2
}
if [[ $1 != '-y' ]]; then
errcho -e "\033[31mERROR: \033[0mThis will overwrite your current key."
errcho -e "\033[31mERROR: \033[0mRun it again with -y as first argument to confirm."
exit 1
fi
KEY=$(cat /dev/urandom | tr -dc '[:alpha:]' | fold -w 32 | head -n 1)
sed -i "s/^SESSION_SECRET=[a-zA-Z0-9]*$/SESSION_SECRET=$KEY/g" .env
echo Your key is $KEY