Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·217 lines (180 loc) · 5.58 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·217 lines (180 loc) · 5.58 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
#!/bin/bash
set -e
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
FROST_DIR="/opt/frost"
FROST_REPO="https://github.com/elitan/frost.git"
FROST_VERSION=""
while getopts "v:" opt; do
case $opt in
v) FROST_VERSION="$OPTARG" ;;
*) echo "Usage: $0 [-v version]"; exit 1 ;;
esac
done
echo -e "${GREEN}Frost Installation Script${NC}"
if [ -n "$FROST_VERSION" ]; then
echo -e "Version: ${YELLOW}$FROST_VERSION${NC}"
fi
echo ""
# Check if running as root
if [ "$EUID" -ne 0 ]; then
echo -e "${RED}Please run as root (sudo)${NC}"
exit 1
fi
# Check if Linux
if [ "$(uname)" != "Linux" ]; then
echo -e "${RED}This script only supports Linux${NC}"
exit 1
fi
# Prompt for admin password
echo -e "${YELLOW}Configuration${NC}"
read -s -p "Admin password (min 8 chars): " FROST_PASSWORD
echo ""
if [ ${#FROST_PASSWORD} -lt 8 ]; then
echo -e "${RED}Password must be at least 8 characters${NC}"
exit 1
fi
# Generate JWT secret
FROST_JWT_SECRET=$(openssl rand -base64 32)
echo ""
echo -e "${YELLOW}Installing dependencies...${NC}"
# Install build tools
apt-get update -qq
apt-get install -y -qq git unzip build-essential > /dev/null
# Install Docker if not present
if ! command -v docker &> /dev/null; then
echo "Installing Docker..."
curl -fsSL https://get.docker.com | sh
systemctl enable docker
systemctl start docker
else
echo "Docker already installed"
fi
# Install Caddy if not present
if ! command -v caddy &> /dev/null; then
echo "Installing Caddy..."
apt-get install -y -qq debian-keyring debian-archive-keyring apt-transport-https curl > /dev/null
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' 2>/dev/null | gpg --dearmor --yes -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg
curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' 2>/dev/null | tee /etc/apt/sources.list.d/caddy-stable.list > /dev/null
apt-get update -qq
apt-get install -y -qq caddy > /dev/null
systemctl enable caddy
else
echo "Caddy already installed"
fi
# Configure Caddy to proxy to Frost
echo "Configuring Caddy..."
cat > /etc/caddy/Caddyfile << 'EOF'
:80 {
reverse_proxy localhost:3000
}
EOF
systemctl restart caddy
# Install Node.js if not present
if ! command -v node &> /dev/null; then
echo "Installing Node.js..."
curl -fsSL https://deb.nodesource.com/setup_22.x 2>/dev/null | bash - > /dev/null 2>&1
apt-get install -y -qq nodejs > /dev/null
else
echo "Node.js already installed"
fi
# Install Bun if not present (needed for setup script)
if ! command -v bun &> /dev/null; then
echo "Installing Bun..."
curl -fsSL https://bun.sh/install 2>/dev/null | bash > /dev/null 2>&1
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
ln -sf "$HOME/.bun/bin/bun" /usr/local/bin/bun
else
echo "Bun already installed"
fi
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
echo ""
echo -e "${YELLOW}Setting up Frost...${NC}"
# Clone or update Frost
if [ -d "$FROST_DIR" ]; then
echo "Removing existing installation..."
rm -rf "$FROST_DIR"
fi
echo "Cloning Frost..."
git clone "$FROST_REPO" "$FROST_DIR"
git config --global --add safe.directory "$FROST_DIR"
cd "$FROST_DIR"
if [ -n "$FROST_VERSION" ]; then
echo "Checking out version $FROST_VERSION..."
git checkout "$FROST_VERSION"
fi
# Create data directory
mkdir -p "$FROST_DIR/data"
# Create .env file
cat > "$FROST_DIR/.env" << EOF
FROST_JWT_SECRET=$FROST_JWT_SECRET
NODE_ENV=production
EOF
# Install dependencies and build
echo "Installing dependencies..."
NODE_ENV=development npm install --legacy-peer-deps --silent
echo "Building..."
npm run build
echo "Running migrations..."
bun run migrate
# Run setup to set admin password (uses bun:sqlite)
echo "Setting admin password..."
bun run setup "$FROST_PASSWORD" || {
echo -e "${RED}Failed to set admin password. Check bun installation.${NC}"
exit 1
}
# Create systemd service
echo ""
echo -e "${YELLOW}Creating systemd service...${NC}"
cat > /etc/systemd/system/frost.service << EOF
[Unit]
Description=Frost
After=network.target docker.service caddy.service
[Service]
Type=simple
WorkingDirectory=$FROST_DIR
ExecStartPre=/bin/bash -c 'test -f $FROST_DIR/data/.update-requested && curl -fsSL https://raw.githubusercontent.com/elitan/frost/main/update.sh | bash -s -- --pre-start || true'
ExecStart=/usr/bin/npm run start
Restart=on-failure
EnvironmentFile=$FROST_DIR/.env
[Install]
WantedBy=multi-user.target
EOF
# Reload systemd and start services
systemctl daemon-reload
systemctl enable frost
systemctl restart frost
# Wait for Frost to start
echo "Waiting for Frost to start..."
sleep 3
# Health check
if curl -s -o /dev/null -w "" http://localhost:3000 2>/dev/null; then
echo "Frost is running"
else
echo -e "${YELLOW}Warning: Could not reach Frost. Check: journalctl -u frost -f${NC}"
fi
# Get server IP
SERVER_IP=$(curl -s ifconfig.me 2>/dev/null || curl -s api.ipify.org 2>/dev/null || echo "YOUR_SERVER_IP")
# Generate API key from JWT secret
FROST_API_KEY=$(echo -n "${FROST_JWT_SECRET}frost-api-key" | sha256sum | cut -c1-32)
echo ""
echo -e "${GREEN}Installation complete!${NC}"
echo ""
echo -e "Frost is running at: ${GREEN}http://$SERVER_IP${NC}"
echo ""
echo -e "API Key: ${YELLOW}$FROST_API_KEY${NC}"
echo "(use with X-Frost-Token header)"
echo ""
echo "Next steps:"
echo " 1. Point your domain to $SERVER_IP"
echo " 2. Go to Settings in Frost to configure domain and SSL"
echo ""
echo "Useful commands:"
echo " systemctl status frost - check status"
echo " systemctl restart frost - restart"
echo " journalctl -u frost -f - view logs"
echo " /opt/frost/update.sh - update to latest version"