forked from ishaan1013/shadow
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-script.sh
More file actions
186 lines (151 loc) · 6.31 KB
/
setup-script.sh
File metadata and controls
186 lines (151 loc) · 6.31 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
GRAY='\033[0;37m'
NC='\033[0m' # No Color
# Helper function to ask questions (with default value)
ask() {
local question="$1"
local default="$2"
local answer
if [ -n "$default" ]; then
echo -n -e "${BLUE}${question}${NC} [${GRAY}${default}${NC}]: " >&2
else
echo -n -e "${BLUE}${question}${NC}: " >&2
fi
read answer
if [ -z "$answer" ]; then
echo "$default"
else
echo "$answer"
fi
}
# Helper function to ask for required fields (with no default value)
ask_required() {
local question="$1"
local description="$2"
local value=""
while [ -z "$value" ]; do
if [ -n "$description" ]; then
echo -e "\n${YELLOW}${description}${NC}" >&2
fi
echo -n -e "${BLUE}${question}${NC}: " >&2
read value
if [ -z "$value" ]; then
echo -e "${RED}[!] This field is required. Please enter a value.${NC}" >&2
fi
done
echo "$value"
}
main() {
echo -e "${GREEN}Shadow Environment Setup${NC}"
echo "============================"
echo
echo "This script will help you set up your environment variables."
echo
proceed=$(ask "Ready to proceed? (y/N)" "N")
if [ "$(echo "$proceed" | tr '[:upper:]' '[:lower:]')" != "y" ]; then
echo "Setup cancelled."
exit 0
fi
# Database Configuration
echo -e "\n${GREEN}Database Configuration${NC}"
echo "****************************************************"
DATABASE_URL=$(ask "Database URL" "postgres://postgres:@127.0.0.1:5432/shadow_dev")
# Pinecone Configuration
echo -e "\n${GREEN}Pinecone Configuration${NC}"
echo "****************************************************"
echo "Get your API key from: https://app.pinecone.io/"
echo "Warning: If not provided, you will not be able to use indexing."
PINECONE_API_KEY=$(ask "Pinecone API Key")
PINECONE_INDEX_NAME=$(ask "Pinecone Index Name" "shadow")
# GitHub Credentials
echo -e "\n${GREEN}GitHub Credentials${NC}"
echo "****************************************************"
echo "See this guide for more information: https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/authenticating-to-the-rest-api-with-an-oauth-app"
GITHUB_CLIENT_ID=$(ask_required "GitHub Client ID")
GITHUB_CLIENT_SECRET=$(ask_required "GitHub Client Secret")
echo "See this guide for more information: https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens"
echo "Ensure that your token has the ability to: read contents of repositories (Select 'Contents' in the 'Select scopes' dropdown)"
GITHUB_PERSONAL_TOKEN=$(ask_required "GitHub Personal Access Token")
# Authentication Configuration
echo -e "\n${GREEN}Authentication Configuration${NC}"
echo "****************************************************"
gen_better_auth_secret() {
openssl rand -base64 32
}
default_secret="$(gen_better_auth_secret)"
echo "Generated random BetterAuth secret automatically."
BETTER_AUTH_SECRET="$default_secret"
# Local Development
echo -e "\n${GREEN}Local Development${NC}"
echo "****************************************************"
echo "Directory where local agent workspaces will be created:"
WORKSPACE_DIR=$(ask "Workspace Directory (absolute path)" "$(pwd)/shadow-worktree")
# Server Configuration
echo -e "\n${GREEN}Server Configuration${NC}"
echo "****************************************************"
NEXT_PUBLIC_SERVER_URL=$(ask "Frontend Server URL" "http://localhost:4000")
# Optional: Force GitHub App for frontend
echo "Defaulting FORCE_GITHUB_APP to false. Only set to true if you would like to create your own GitHub App."
NEXT_PUBLIC_FORCE_GITHUB_APP="false"
# Create server .env file
echo -e "\n${GREEN}Creating server .env file...${NC}"
cat > "apps/server/.env" << EOF
DATABASE_URL="${DATABASE_URL}"
PINECONE_API_KEY="${PINECONE_API_KEY}"
PINECONE_INDEX_NAME="${PINECONE_INDEX_NAME}"
GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
GITHUB_PERSONAL_TOKEN=${GITHUB_PERSONAL_TOKEN}
WORKSPACE_DIR=${WORKSPACE_DIR}
EOF
echo -e "${GREEN} Created apps/server/.env${NC}"
# Create frontend .env file
echo -e "${GREEN}Creating frontend .env file...${NC}"
cat > "apps/frontend/.env" << EOF
NEXT_PUBLIC_SERVER_URL="${NEXT_PUBLIC_SERVER_URL}"
NEXT_PUBLIC_FORCE_GITHUB_APP=${NEXT_PUBLIC_FORCE_GITHUB_APP}
BETTER_AUTH_SECRET=${BETTER_AUTH_SECRET}
GITHUB_CLIENT_ID=${GITHUB_CLIENT_ID}
GITHUB_CLIENT_SECRET=${GITHUB_CLIENT_SECRET}
GITHUB_PERSONAL_TOKEN=${GITHUB_PERSONAL_TOKEN}
NEXT_PUBLIC_FORCE_GITHUB_APP=${NEXT_PUBLIC_FORCE_GITHUB_APP}
DATABASE_URL="${DATABASE_URL}"
EOF
echo -e "${GREEN} Created apps/frontend/.env${NC}"
# Create packages/db .env file
echo -e "${GREEN}Creating packages/db/.env file...${NC}"
if [ -f "packages/db/.env.template" ]; then
cp "packages/db/.env.template" "packages/db/.env"
echo -e "${GREEN} Created packages/db/.env from template${NC}"
else
cat > "packages/db/.env" << EOF
DATABASE_URL="${DATABASE_URL}"
EOF
echo -e "${YELLOW} packages/db/.env.template not found; created packages/db/.env with DATABASE_URL only.${NC}"
fi
echo -e "\n${GREEN} Setup Complete!${NC}"
echo "****************************************************"
echo "Your environment files have been created:"
echo " apps/server/.env"
echo " apps/frontend/.env"
echo " packages/db/.env"
echo -e "\n${YELLOW} Next Steps:${NC}"
echo "1. Make sure your PostgreSQL database is running"
echo "2. Run database migrations: \`npm run generate\` then \`npm run db:push\` in the /packages/db directory"
echo "3. Start the development servers"
echo -e "\n${RED} Security Note:${NC}"
echo "Never commit .env files to version control!"
echo "They contain sensitive credentials."
}
trap 'echo -e "\n\nSetup cancelled."; exit 130' INT
if [ ! -f "apps/server/.env.template" ] || [ ! -f "apps/frontend/.env.template" ]; then
echo -e "${RED}[!] Error: .env.template files not found.${NC}"
echo "Please run this script from the root of the Shadow project."
exit 1
fi
main