-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathinstall.sh
More file actions
186 lines (147 loc) · 4.87 KB
/
Copy pathinstall.sh
File metadata and controls
186 lines (147 loc) · 4.87 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
#!/usr/bin/env bash
set -euo pipefail
echo "Installing Stellar Portfolio Rebalancer..."
# Colors
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
RED='\033[0;31m'
NC='\033[0m'
REQUIRED_NODE_VERSION="20.19.0"
REQUIRED_NPM_VERSION="10.0.0"
print_status() {
echo -e "${GREEN}[OK]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARN]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1" >&2
}
fail() {
print_error "$1"
exit 1
}
require_command() {
local command_name="$1"
local install_hint="$2"
if ! command -v "${command_name}" >/dev/null 2>&1; then
fail "${command_name} is required but was not found. ${install_hint}"
fi
}
version_at_least() {
local actual="$1"
local required="$2"
node -e "
const actual = process.argv[1].split('.').map(Number);
const required = process.argv[2].split('.').map(Number);
for (let i = 0; i < 3; i += 1) {
if ((actual[i] || 0) > (required[i] || 0)) process.exit(0);
if ((actual[i] || 0) < (required[i] || 0)) process.exit(1);
}
process.exit(0);
" "${actual}" "${required}"
}
run_step() {
local description="$1"
shift
print_status "${description}"
"$@" || fail "${description} failed. Review the command output above and try again."
}
run_npm_install() {
local directory="$1"
local label="$2"
print_status "Installing ${label} dependencies..."
(
cd "${directory}"
npm install
) || fail "npm install failed for ${label} dependencies."
}
# Check Node.js and npm versions.
check_node() {
require_command "node" "Install Node.js ${REQUIRED_NODE_VERSION} or later: https://nodejs.org/"
require_command "npm" "Install npm ${REQUIRED_NPM_VERSION} or later. It is bundled with supported Node.js releases."
local node_version
node_version="$(node -p "process.versions.node")"
if ! version_at_least "${node_version}" "${REQUIRED_NODE_VERSION}"; then
fail "Node.js ${node_version} is not supported. Please install Node.js ${REQUIRED_NODE_VERSION} or later."
fi
local npm_version
npm_version="$(npm -v)"
if ! version_at_least "${npm_version}" "${REQUIRED_NPM_VERSION}"; then
fail "npm ${npm_version} is not supported. Please install npm ${REQUIRED_NPM_VERSION} or later."
fi
print_status "Node.js ${node_version} and npm ${npm_version} are compatible"
}
# Check Rust toolchain and required WebAssembly target.
check_rust() {
require_command "rustc" "Install Rust with rustup: https://rustup.rs/"
require_command "cargo" "Install Rust with rustup: https://rustup.rs/"
require_command "rustup" "Install Rust with rustup so targets can be managed: https://rustup.rs/"
local rustc_version
rustc_version="$(rustc --version)"
local cargo_version
cargo_version="$(cargo --version)"
if ! rustup target list --installed | grep -qx "wasm32-unknown-unknown"; then
run_step "Installing Rust wasm32-unknown-unknown target" rustup target add wasm32-unknown-unknown
fi
print_status "Rust toolchain detected (${rustc_version}; ${cargo_version})"
}
# Check Soroban CLI.
check_soroban() {
require_command "soroban" "Install it with: cargo install --locked soroban-cli"
local soroban_version
soroban_version="$(soroban --version)"
print_status "Soroban CLI detected (${soroban_version})"
}
# Install dependencies.
install_deps() {
run_npm_install "." "root"
run_npm_install "backend" "backend"
run_npm_install "frontend" "frontend"
run_step "Checking contracts" bash -c "cd contracts && cargo check"
}
# Setup environment files.
copy_env_if_available() {
local source_file="$1"
local target_file="$2"
if [ -f "${target_file}" ]; then
return
fi
if [ -f "${source_file}" ]; then
cp "${source_file}" "${target_file}"
print_status "Created ${target_file}"
else
print_warning "Skipped ${target_file}; ${source_file} does not exist"
fi
}
setup_env() {
print_status "Setting up environment files..."
copy_env_if_available ".env.example" ".env"
copy_env_if_available "frontend/.env.example" "frontend/.env"
copy_env_if_available "backend/.env.example" "backend/.env"
print_warning "Please update the .env files with your configuration"
}
# Create necessary directories.
create_dirs() {
mkdir -p backend/logs
mkdir -p deployment/ssl
print_status "Created necessary directories"
}
# Main installation.
main() {
echo "Stellar Portfolio Rebalancer Installation"
echo "========================================="
check_node
check_rust
check_soroban
install_deps
setup_env
create_dirs
print_status "Installation completed successfully!"
echo ""
echo "Next steps:"
echo "1. Update environment files (.env, frontend/.env, backend/.env)"
echo "2. Run 'npm run dev' to start development servers"
echo "3. Visit http://localhost:3000 to view the application"
}
main "$@"