Skip to content

Commit 7fdced8

Browse files
committed
add install script
Signed-off-by: tdruez <tdruez@aboutcode.org>
1 parent 4470224 commit 7fdced8

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

install.sh

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#!/usr/bin/env bash
2+
# DejaCode installer — no root required, works on macOS and Linux.
3+
# Usage: curl -sSL https://raw.githubusercontent.com/aboutcode-org/dejacode/compose-files/install.sh | bash
4+
set -euo pipefail
5+
6+
REPO="https://raw.githubusercontent.com/aboutcode-org/dejacode/compose-files"
7+
INSTALL_DIR="${DEJACODE_HOME:-$HOME/dejacode}"
8+
BIN_DIR="$HOME/.local/bin"
9+
WRAPPER="$BIN_DIR/dejacode"
10+
11+
# ── Output helpers ────────────────────────────────────────────────────────────
12+
BOLD='\033[1m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; RED='\033[0;31m'; NC='\033[0m'
13+
info() { echo -e "${BLUE}${NC} $1"; }
14+
success() { echo -e "${GREEN}${NC} $1"; }
15+
die() { echo -e "${RED}${NC} $1" >&2; exit 1; }
16+
17+
# ── Prerequisites ─────────────────────────────────────────────────────────────
18+
command -v docker &>/dev/null || die "Docker is required. See https://docs.docker.com/get-docker/"
19+
docker info &>/dev/null || die "Docker daemon is not running. Please start Docker first."
20+
command -v curl &>/dev/null || die "curl is required."
21+
22+
# ── Installation directory ────────────────────────────────────────────────────
23+
info "Installing DejaCode in ${BOLD}$INSTALL_DIR${NC}"
24+
mkdir -p "$INSTALL_DIR/data/postgresql"
25+
cd "$INSTALL_DIR"
26+
27+
# ── Download files ────────────────────────────────────────────────────────────
28+
info "Downloading compose.yml"
29+
curl -sSL "$REPO/compose.yml" -o compose.yml
30+
31+
info "Downloading database seed data"
32+
curl -sSL "$REPO/data/postgresql/initdb.sql.gz" -o data/postgresql/initdb.sql.gz
33+
34+
info "Downloading environment template"
35+
curl -sSL "$REPO/.env.run" -o .env.run
36+
37+
# ── Generate docker.env with a secure secret key ──────────────────────────────
38+
info "Generating secret key"
39+
SECRET_KEY=$(LC_ALL=C tr -dc 'A-Za-z0-9!@#%^&*(-_=+)' < /dev/urandom | head -c 50)
40+
sed "s|^SECRET_KEY=.*|SECRET_KEY=$SECRET_KEY|" .env.run > docker.env
41+
rm .env.run
42+
43+
# ── Install wrapper command ───────────────────────────────────────────────────
44+
info "Installing dejacode command to $WRAPPER"
45+
mkdir -p "$BIN_DIR"
46+
curl -sSL "$REPO/bin/dejacode" -o "$WRAPPER"
47+
# Hardcode install dir into the wrapper
48+
sed -i.bak "s|^INSTALL_DIR=.*|INSTALL_DIR=\"$INSTALL_DIR\"|" "$WRAPPER" && rm "$WRAPPER.bak"
49+
chmod +x "$WRAPPER"
50+
51+
# ── Add ~/.local/bin to PATH if needed ───────────────────────────────────────
52+
add_to_path() {
53+
local rc="$1"
54+
[ -f "$rc" ] || return
55+
grep -q '\.local/bin' "$rc" && return
56+
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$rc"
57+
info "Added ~/.local/bin to PATH in $rc"
58+
}
59+
60+
if [[ "$OSTYPE" == "darwin"* ]]; then
61+
add_to_path "$HOME/.zshrc"
62+
else
63+
add_to_path "$HOME/.bashrc"
64+
add_to_path "$HOME/.profile"
65+
fi
66+
67+
# ── Start services ────────────────────────────────────────────────────────────
68+
info "Starting DejaCode"
69+
docker compose up -d
70+
71+
# ── Wait for web to respond ───────────────────────────────────────────────────
72+
info "Waiting for DejaCode to be ready"
73+
RETRIES=40
74+
until curl -fsS --max-time 5 http://localhost/ -o /dev/null 2>&1; do
75+
RETRIES=$((RETRIES - 1))
76+
[ $RETRIES -eq 0 ] && die "Timed out waiting for DejaCode to start. Run: dejacode logs"
77+
echo -n "."
78+
sleep 3
79+
done
80+
echo ""
81+
82+
# ── Done ──────────────────────────────────────────────────────────────────────
83+
success "DejaCode is running at ${BOLD}http://localhost${NC}"
84+
echo ""
85+
echo " Create your admin user: dejacode createsuperuser"
86+
echo " Stop: dejacode stop"
87+
echo " Logs: dejacode logs"
88+
echo ""
89+
echo " Reload your shell or run: source ~/.zshrc (or ~/.bashrc)"

0 commit comments

Comments
 (0)