-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·146 lines (127 loc) · 7.11 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·146 lines (127 loc) · 7.11 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
#!/usr/bin/env bash
# DejaCode installer: no root required, works on macOS and Linux.
# Usage: curl -sSL https://raw.githubusercontent.com/aboutcode-org/dejacode/main/install.sh | bash
# Build from source: curl -sSL .../install.sh | bash -s -- --from-source
set -eu
FROM_SOURCE=false
[ "${1:-}" = "--from-source" ] && FROM_SOURCE=true
REPO="https://raw.githubusercontent.com/aboutcode-org/dejacode/main"
GIT_REPO="https://github.com/aboutcode-org/dejacode.git"
INSTALL_DIR="${DEJACODE_HOME:-$HOME/.dejacode}"
BIN_DIR="$HOME/.local/bin"
WRAPPER="$BIN_DIR/dejacode"
COMPOSE_FILES="-f compose.yml"
$FROM_SOURCE && COMPOSE_FILES="-f compose.yml -f compose.build.yml"
# ── Output helpers ────────────────────────────────────────────────────────────
BOLD='\033[1m'; GREEN='\033[0;32m'; BLUE='\033[0;34m'; RED='\033[0;31m'; NC='\033[0m'
info() { echo -e "${BLUE}→${NC} $1"; }
success() { echo -e "${GREEN}✓${NC} $1"; }
die() { echo -e "${RED}✗${NC} $1" >&2; exit 1; }
# ── Prerequisites ─────────────────────────────────────────────────────────────
command -v docker &>/dev/null || die "Docker is required. See https://docs.docker.com/get-docker/"
docker info &>/dev/null || die "Docker daemon is not running. Please start Docker first."
command -v curl &>/dev/null || die "curl is required."
$FROM_SOURCE && { command -v git &>/dev/null || die "git is required for --from-source."; }
# ── Guard: existing installation ─────────────────────────────────────────────
if [ -f "$INSTALL_DIR/.env" ]; then
die "An existing DejaCode installation was found at $INSTALL_DIR.
To reinstall (e.g. switch to --from-source), run these steps manually:
dejacode down
mv \"$INSTALL_DIR\" \"${INSTALL_DIR}.bak\"
DEJACODE_HOME=\"$INSTALL_DIR\" curl -sSL https://raw.githubusercontent.com/aboutcode-org/dejacode/main/install.sh | bash -s -- --from-source
cp \"${INSTALL_DIR}.bak/.env\" \"$INSTALL_DIR/.env\"
dejacode restart
Your original installation is preserved at ${INSTALL_DIR}.bak for rollback."
fi
# ── Installation directory ────────────────────────────────────────────────────
info "Installing DejaCode in ${BOLD}$INSTALL_DIR${NC}"
cd "$(dirname "$INSTALL_DIR")"
if $FROM_SOURCE; then
# ── Clone repository (shallow) ────────────────────────────────────────────
info "Cloning DejaCode source (latest main)"
git clone --depth 1 "$GIT_REPO" "$INSTALL_DIR"
mkdir -p "$INSTALL_DIR/data/postgresql"
else
# ── Download files ────────────────────────────────────────────────────────
mkdir -p "$INSTALL_DIR/data/postgresql"
cd "$INSTALL_DIR"
info "Downloading compose.yml"
curl -sSL "$REPO/compose.yml" -o compose.yml
info "Downloading database seed data"
curl -sSL "$REPO/data/postgresql/initdb.sql.gz" -o data/postgresql/initdb.sql.gz
info "Downloading docker.env"
curl -sSL "$REPO/docker.env" -o docker.env
info "Downloading nginx configuration"
mkdir -p etc/nginx/conf.d
curl -sSL "$REPO/etc/nginx/conf.d/default.conf" -o etc/nginx/conf.d/default.conf
fi
cd "$INSTALL_DIR"
# ── Generate .env with a secure secret key ────────────────────────────────────
info "Generating .env"
# Read enough bytes from urandom so tr has enough after filtering, then cut to 50 chars.
# Avoids SIGPIPE/pipefail issues by not reading from an infinite stream.
SECRET_KEY=$(dd if=/dev/urandom bs=512 count=1 2>/dev/null \
| LC_ALL=C tr -dc 'A-Za-z0-9!@#%^&*(-_=+)' \
| cut -c1-50)
printf 'SECRET_KEY=%s\nALLOWED_HOSTS=localhost\nCSRF_TRUSTED_ORIGINS=http://localhost\n' \
"$SECRET_KEY" > .env
# ── Install wrapper command ───────────────────────────────────────────────────
info "Installing dejacode command to $WRAPPER"
mkdir -p "$BIN_DIR"
# Write the wrapper using printf to avoid heredoc stdin conflicts when piped via curl | bash.
printf '%s\n' \
'#!/usr/bin/env bash' \
'set -eu' \
"INSTALL_DIR=\"$INSTALL_DIR\"" \
'case "${1:-}" in' \
' uninstall)' \
' printf "This will permanently delete all DejaCode data. Type '\''yes'\'' to confirm: "' \
' read -r CONFIRM' \
' [ "$CONFIRM" = "yes" ] || { echo "Aborted."; exit 1; }' \
' docker compose --project-directory "$INSTALL_DIR" down -v --remove-orphans 2>/dev/null || true' \
' rm -rf "$INSTALL_DIR"' \
' rm -f "$0"' \
' echo "DejaCode has been uninstalled."' \
' ;;' \
' *)' \
" cd \"\$INSTALL_DIR\" && exec docker compose $COMPOSE_FILES \"\$@\"" \
' ;;' \
'esac' \
> "$WRAPPER"
chmod +x "$WRAPPER"
# ── Add ~/.local/bin to PATH if needed ───────────────────────────────────────
add_to_path() {
local rc="$1"
[ -f "$rc" ] || return
grep -q '\.local/bin' "$rc" && return
echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$rc"
info "Added ~/.local/bin to PATH in $rc"
}
if [[ "$OSTYPE" == "darwin"* ]]; then
add_to_path "$HOME/.zshrc"
else
add_to_path "$HOME/.bashrc"
add_to_path "$HOME/.profile"
fi
# ── Start services ────────────────────────────────────────────────────────────
info "Starting DejaCode"
# shellcheck disable=SC2086
docker compose $COMPOSE_FILES up --build -d
# ── Wait for web to respond ───────────────────────────────────────────────────
info "Waiting for DejaCode to be ready"
RETRIES=40
until curl -fsS --max-time 5 http://localhost/ -o /dev/null 2>/dev/null; do
RETRIES=$((RETRIES - 1))
[ $RETRIES -eq 0 ] && die "Timed out waiting for DejaCode to start. Run: dejacode logs"
echo -n "."
sleep 3
done
echo ""
# ── Done ──────────────────────────────────────────────────────────────────────
success "DejaCode is running at ${BOLD}http://localhost${NC}"
echo ""
echo " Create your admin user: dejacode exec web ./manage.py createsuperuser"
echo " Stop: dejacode down"
echo " Logs: dejacode logs -f"
echo ""
echo " Reload your shell or run: source ~/.zshrc (or ~/.bashrc)"