-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.sh
executable file
·45 lines (37 loc) · 1.07 KB
/
setup.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/bash
cd "$(dirname "$0")" || exit
is_valid_sk_key() {
local api_key=$1
local pattern="^sk-[a-zA-Z0-9]{48}$"
[[ $api_key =~ $pattern ]] && return 0 || return 1
}
echo -n "Enter your OpenAI Key (eg: sk...) or press enter to continue with no key: "
read OPENAI_API_KEY
if is_valid_sk_key $OPENAI_API_KEY || [ -z "$OPENAI_API_KEY" ]; then
echo "Valid API key"
else
echo "Invalid API key. Please ensure that you have billing set up on your OpenAI account"
exit
fi
NEXTAUTH_SECRET=$(openssl rand -base64 32)
ENV="NODE_ENV=development\n\
NEXTAUTH_SECRET=$NEXTAUTH_SECRET\n\
NEXTAUTH_URL=http://localhost:3000\n\
OPENAI_API_KEY=$OPENAI_API_KEY\n\
DATABASE_URL=$DATABASE_URL\n\
cd next
printf $ENV > .env
printf $ENV > .env.docker
if [ "$1" = "--docker" ]; then
source .env.docker
docker build --build-arg NODE_ENV=$NODE_ENV -t mackgpt .
docker run -d --name mackgpt -p 3000:3000 -v $(pwd)/db:/app/db mackgpt
elif [ "$1" = "--docker-compose" ]; then
cd ..
docker-compose up -d --remove-orphans
else
./prisma/useSqlite.sh
npm install
prisma db push
npm run dev
fi