-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·157 lines (136 loc) · 5.52 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·157 lines (136 loc) · 5.52 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
#!/usr/bin/env bash
set -e
# ============================================================
# Adaptive Learner Installer
# Downloads and starts the adaptive learning platform.
#
# Usage:
# curl -fsSL https://raw.githubusercontent.com/astrapi69/adaptive-learner/main/install.sh | bash
#
# Or download and run:
# chmod +x install.sh && ./install.sh
# ============================================================
VERSION="${ADAPTIVE_LEARNER_VERSION:-v2.5.0}"
REPO="astrapi69/adaptive-learner"
INSTALL_DIR="${ADAPTIVE_LEARNER_DIR:-$HOME/adaptive-learner}"
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m'
echo -e "${BLUE}"
echo "============================================================"
echo " Adaptive Learner"
echo " Adaptive learning platform built on PluginForge"
echo "============================================================"
echo -e "${NC}"
echo " Version: ${VERSION}"
echo ""
# --- Check Docker ---
if ! command -v docker &> /dev/null; then
echo -e "${RED}Error: Docker is not installed.${NC}"
echo ""
echo "Please install Docker:"
echo " https://docs.docker.com/get-docker/"
echo ""
echo "Then run again:"
echo " curl -fsSL https://raw.githubusercontent.com/${REPO}/main/install.sh | bash"
exit 1
fi
if ! docker info &> /dev/null 2>&1; then
echo -e "${RED}Error: Docker is not running.${NC}"
echo "Please start Docker and try again."
exit 1
fi
if ! docker compose version &> /dev/null 2>&1; then
echo -e "${RED}Error: Docker Compose is not available.${NC}"
echo "Please install Docker Compose: https://docs.docker.com/compose/install/"
exit 1
fi
echo -e "${GREEN}Docker and Docker Compose found.${NC}"
# --- Download ---
# When an existing install is detected, we delete and re-clone
# instead of trying to update in-place. Previous installs were
# shallow clones whose git state cannot be reliably updated across
# major version jumps (different refspecs, missing remote branches,
# detached HEAD from tag-only clones). Re-cloning is fast (small
# repo) and eliminates an entire class of platform-specific git bugs.
# The only user artifact in the repo directory is .env - we preserve it.
BACKUP_ENV=""
if [ -d "$INSTALL_DIR/.git" ]; then
echo -e "${YELLOW}AdaptiveLearner is already installed in ${INSTALL_DIR}${NC}"
echo "Updating to ${VERSION}..."
if [ -f "$INSTALL_DIR/.env" ]; then
BACKUP_ENV=$(mktemp)
cp "$INSTALL_DIR/.env" "$BACKUP_ENV"
echo -e "${GREEN}Backed up .env configuration.${NC}"
fi
rm -rf "$INSTALL_DIR"
fi
echo -e "${BLUE}Downloading AdaptiveLearner ${VERSION}...${NC}"
# Try git clone first (preferred)
if command -v git &> /dev/null; then
git clone --depth 1 --branch "$VERSION" "https://github.com/${REPO}.git" "$INSTALL_DIR" 2>/dev/null || \
git clone --depth 1 "https://github.com/${REPO}.git" "$INSTALL_DIR"
else
# Fallback: download tarball
echo "Git not found, downloading archive..."
mkdir -p "$INSTALL_DIR"
TARBALL_URL="https://github.com/${REPO}/archive/refs/tags/${VERSION}.tar.gz"
if command -v curl &> /dev/null; then
curl -fsSL "$TARBALL_URL" | tar xz --strip-components=1 -C "$INSTALL_DIR" 2>/dev/null || {
# Tag might not exist yet, try main
curl -fsSL "https://github.com/${REPO}/archive/refs/heads/main.tar.gz" | tar xz --strip-components=1 -C "$INSTALL_DIR"
}
elif command -v wget &> /dev/null; then
wget -qO- "$TARBALL_URL" | tar xz --strip-components=1 -C "$INSTALL_DIR" 2>/dev/null || {
wget -qO- "https://github.com/${REPO}/archive/refs/heads/main.tar.gz" | tar xz --strip-components=1 -C "$INSTALL_DIR"
}
else
echo -e "${RED}Error: Neither git, curl, nor wget found.${NC}"
exit 1
fi
fi
# Restore .env from previous install (preserved above)
if [ -n "$BACKUP_ENV" ] && [ -f "$BACKUP_ENV" ]; then
mv "$BACKUP_ENV" "$INSTALL_DIR/.env"
echo -e "${GREEN}Restored .env configuration from previous install.${NC}"
fi
cd "$INSTALL_DIR"
# --- Create .env if missing ---
if [ ! -f .env ]; then
echo -e "${YELLOW}Creating configuration...${NC}"
cp .env.example .env
# Generate random secret key
SECRET=$(python3 -c "import secrets; print(secrets.token_hex(32))" 2>/dev/null || \
openssl rand -hex 32 2>/dev/null || \
head -c 32 /dev/urandom | xxd -p 2>/dev/null || \
echo "adaptive-learner-$(date +%s)-random")
if [[ "$OSTYPE" == "darwin"* ]]; then
sed -i '' "s/change-me-to-a-random-secret/$SECRET/" .env
else
sed -i "s/change-me-to-a-random-secret/$SECRET/" .env
fi
echo -e "${GREEN}Configuration created.${NC}"
fi
# --- Read port from .env ---
PORT=$(grep -E '^ADAPTIVE_LEARNER_PORT=' .env 2>/dev/null | cut -d= -f2 || echo "7880")
PORT=${PORT:-7880}
# --- Build and start ---
echo ""
echo -e "${BLUE}Building and starting AdaptiveLearner (this may take a few minutes the first time)...${NC}"
echo ""
docker compose -f docker-compose.prod.yml up --build -d
echo ""
echo -e "${GREEN}========================================${NC}"
echo -e "${GREEN} AdaptiveLearner is running!${NC}"
echo -e "${GREEN}========================================${NC}"
echo ""
echo -e " Open: ${BLUE}http://localhost:${PORT}${NC}"
echo ""
echo -e " Installed in: ${INSTALL_DIR}"
echo ""
echo -e " Stop: ${YELLOW}cd ${INSTALL_DIR} && ./stop.sh${NC}"
echo -e " Start: ${YELLOW}cd ${INSTALL_DIR} && ./start.sh${NC}"
echo -e " Uninstall: ${YELLOW}cd ${INSTALL_DIR} && ./stop.sh && cd ~ && rm -rf ${INSTALL_DIR}${NC}"
echo ""