11#! /usr/bin/env bash
22# DejaCode installer: no root required, works on macOS and Linux.
33# Usage: curl -sSL https://raw.githubusercontent.com/aboutcode-org/dejacode/main/install.sh | bash
4+ # Build from source: curl -sSL .../install.sh | bash -s -- --from-source
45set -eu
56
7+ FROM_SOURCE=false
8+ [ " ${1:- } " = " --from-source" ] && FROM_SOURCE=true
9+
610REPO=" https://raw.githubusercontent.com/aboutcode-org/dejacode/main"
11+ GIT_REPO=" https://github.com/aboutcode-org/dejacode.git"
712INSTALL_DIR=" ${DEJACODE_HOME:- $HOME / .dejacode} "
813BIN_DIR=" $HOME /.local/bin"
914WRAPPER=" $BIN_DIR /dejacode"
15+ COMPOSE_FILES=" -f compose.yml"
16+ $FROM_SOURCE && COMPOSE_FILES=" -f compose.yml -f compose.build.yml"
1017
1118# ── Output helpers ────────────────────────────────────────────────────────────
1219BOLD=' \033[1m' ; GREEN=' \033[0;32m' ; BLUE=' \033[0;34m' ; RED=' \033[0;31m' ; NC=' \033[0m'
@@ -18,25 +25,49 @@ die() { echo -e "${RED}✗${NC} $1" >&2; exit 1; }
1825command -v docker & > /dev/null || die " Docker is required. See https://docs.docker.com/get-docker/"
1926docker info & > /dev/null || die " Docker daemon is not running. Please start Docker first."
2027command -v curl & > /dev/null || die " curl is required."
28+ $FROM_SOURCE && { command -v git & > /dev/null || die " git is required for --from-source." ; }
29+
30+ # ── Guard: existing installation ─────────────────────────────────────────────
31+ if [ -f " $INSTALL_DIR /.env" ]; then
32+ die " An existing DejaCode installation was found at $INSTALL_DIR .
33+ To reinstall (e.g. switch to --from-source), run these steps manually:
34+ dejacode down
35+ mv \" $INSTALL_DIR \" \" ${INSTALL_DIR} .bak\"
36+ DEJACODE_HOME=\" $INSTALL_DIR \" curl -sSL https://raw.githubusercontent.com/aboutcode-org/dejacode/main/install.sh | bash -s -- --from-source
37+ cp \" ${INSTALL_DIR} .bak/.env\" \" $INSTALL_DIR /.env\"
38+ dejacode restart
39+ Your original installation is preserved at ${INSTALL_DIR} .bak for rollback."
40+ fi
2141
2242# ── Installation directory ────────────────────────────────────────────────────
2343info " Installing DejaCode in ${BOLD} $INSTALL_DIR ${NC} "
24- mkdir -p " $INSTALL_DIR /data/postgresql"
25- cd " $INSTALL_DIR "
44+ cd " $( dirname " $INSTALL_DIR " ) "
2645
27- # ── Download files ────────────────────────────────────────────────────────────
28- info " Downloading compose.yml"
29- curl -sSL " $REPO /compose.yml" -o compose.yml
46+ if $FROM_SOURCE ; then
47+ # ── Clone repository (shallow) ────────────────────────────────────────────
48+ info " Cloning DejaCode source (latest main)"
49+ git clone --depth 1 " $GIT_REPO " " $INSTALL_DIR "
50+ mkdir -p " $INSTALL_DIR /data/postgresql"
51+ else
52+ # ── Download files ────────────────────────────────────────────────────────
53+ mkdir -p " $INSTALL_DIR /data/postgresql"
54+ cd " $INSTALL_DIR "
3055
31- info " Downloading database seed data "
32- curl -sSL " $REPO /data/postgresql/initdb.sql.gz " -o data/postgresql/initdb.sql.gz
56+ info " Downloading compose.yml "
57+ curl -sSL " $REPO /compose.yml " -o compose.yml
3358
34- info " Downloading docker.env "
35- curl -sSL " $REPO /docker.env " -o docker.env
59+ info " Downloading database seed data "
60+ curl -sSL " $REPO /data/postgresql/initdb.sql.gz " -o data/postgresql/initdb.sql.gz
3661
37- info " Downloading nginx configuration"
38- mkdir -p etc/nginx/conf.d
39- curl -sSL " $REPO /etc/nginx/conf.d/default.conf" -o etc/nginx/conf.d/default.conf
62+ info " Downloading docker.env"
63+ curl -sSL " $REPO /docker.env" -o docker.env
64+
65+ info " Downloading nginx configuration"
66+ mkdir -p etc/nginx/conf.d
67+ curl -sSL " $REPO /etc/nginx/conf.d/default.conf" -o etc/nginx/conf.d/default.conf
68+ fi
69+
70+ cd " $INSTALL_DIR "
4071
4172# ── Generate .env with a secure secret key ────────────────────────────────────
4273info " Generating .env"
@@ -67,7 +98,7 @@ printf '%s\n' \
6798 ' echo "DejaCode has been uninstalled."' \
6899 ' ;;' \
69100 ' *)' \
70- ' cd " $INSTALL_DIR" && exec docker compose "$@" ' \
101+ " cd \"\ $ INSTALL_DIR\ " && exec docker compose $COMPOSE_FILES \"\$ @ \" " \
71102 ' ;;' \
72103 ' esac' \
73104 > " $WRAPPER "
91122
92123# ── Start services ────────────────────────────────────────────────────────────
93124info " Starting DejaCode"
94- docker compose up -d
125+ # shellcheck disable=SC2086
126+ docker compose $COMPOSE_FILES up --build -d
95127
96128# ── Wait for web to respond ───────────────────────────────────────────────────
97129info " Waiting for DejaCode to be ready"
0 commit comments