-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·148 lines (127 loc) · 7.19 KB
/
install.sh
File metadata and controls
executable file
·148 lines (127 loc) · 7.19 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
#!/usr/bin/env bash
# =============================================================================
# Coderive Installer
# Installs the Coderive language runtime and sets up the `coderive` command.
#
# Usage (from repo root):
# chmod +x install.sh && ./install.sh
#
# Or one-line install (downloads jar automatically):
# curl -fsSL https://raw.githubusercontent.com/DanexCodr/Coderive/main/install.sh | bash
# =============================================================================
set -euo pipefail
# ── Styling ─────────────────────────────────────────────────────────────────
BOLD="\033[1m"
GREEN="\033[32m"
YELLOW="\033[33m"
CYAN="\033[36m"
RED="\033[31m"
RESET="\033[0m"
ok() { echo -e " ${GREEN}✔${RESET} $*"; }
info() { echo -e " ${CYAN}ℹ${RESET} $*"; }
warn() { echo -e " ${YELLOW}⚠${RESET} $*"; }
fail() { echo -e " ${RED}✘${RESET} $*" >&2; exit 1; }
# ── Config ───────────────────────────────────────────────────────────────────
VERSION="$(cat "$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || pwd)/VERSION" 2>/dev/null || echo "0.8.4")"
INSTALL_DIR="${CODERIVE_HOME:-$HOME/.coderive}"
BIN_DIR="${CODERIVE_BIN:-$HOME/.local/bin}"
JAR_NAME="Coderive.jar"
REPO_JAR_PATH="docs/assets/$JAR_NAME"
REMOTE_JAR_URL="https://github.com/DanexCodr/Coderive/raw/main/docs/assets/$JAR_NAME"
# ── Banner ───────────────────────────────────────────────────────────────────
echo ""
echo -e "${BOLD}${CYAN} ██████╗ ██████╗ ██████╗ ███████╗██████╗ ██╗██╗ ██╗███████╗${RESET}"
echo -e "${BOLD}${CYAN} ██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔══██╗██║██║ ██║██╔════╝${RESET}"
echo -e "${BOLD}${CYAN} ██║ ██║ ██║██║ ██║█████╗ ██████╔╝██║██║ ██║█████╗ ${RESET}"
echo -e "${BOLD}${CYAN} ██║ ██║ ██║██║ ██║██╔══╝ ██╔══██╗██║╚██╗ ██╔╝██╔══╝ ${RESET}"
echo -e "${BOLD}${CYAN} ╚██████╗╚██████╔╝██████╔╝███████╗██║ ██║██║ ╚████╔╝ ███████╗${RESET}"
echo -e "${BOLD}${CYAN} ╚═════╝ ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝╚═╝ ╚═══╝ ╚══════╝${RESET}"
echo ""
echo -e "${BOLD} Coderive v${VERSION} Installer${RESET} — Safe. Fast. Clear."
echo ""
# ── Step 1: Java check ───────────────────────────────────────────────────────
echo -e "${BOLD}[1/4] Checking Java...${RESET}"
if ! command -v java &>/dev/null; then
fail "Java not found. Please install Java 7 or later then re-run this script.
Download from: https://adoptium.net/"
fi
JAVA_VERSION_STRING=$(java -version 2>&1 | head -1)
JAVA_MAJOR=$(echo "$JAVA_VERSION_STRING" | grep -oE '"[0-9]+' | grep -oE '[0-9]+' | head -1)
# Java 1.x notation — extract minor as the real version
if [ "$JAVA_MAJOR" = "1" ]; then
JAVA_MAJOR=$(echo "$JAVA_VERSION_STRING" | grep -oE '"1\.[0-9]+' | grep -oE '\.[0-9]+' | tr -d '.')
fi
if [ -z "$JAVA_MAJOR" ]; then
warn "Could not parse Java version — assuming it meets the Java 7+ requirement."
elif [ "$JAVA_MAJOR" -lt 7 ]; then
fail "Java $JAVA_MAJOR detected, but Coderive requires Java 7 or later."
fi
ok "Java ${JAVA_MAJOR} detected"
# ── Step 2: Create install directory ─────────────────────────────────────────
echo ""
echo -e "${BOLD}[2/4] Creating install directory...${RESET}"
mkdir -p "$INSTALL_DIR"
mkdir -p "$BIN_DIR"
ok "Install directory: $INSTALL_DIR"
# ── Step 3: Install the jar ───────────────────────────────────────────────────
echo ""
echo -e "${BOLD}[3/4] Installing Coderive.jar...${RESET}"
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || pwd)"
LOCAL_JAR="$SCRIPT_DIR/$REPO_JAR_PATH"
if [ -f "$LOCAL_JAR" ]; then
cp "$LOCAL_JAR" "$INSTALL_DIR/$JAR_NAME"
ok "Copied from local repository"
else
info "Local jar not found — downloading from GitHub..."
if command -v curl &>/dev/null; then
curl -fsSL "$REMOTE_JAR_URL" -o "$INSTALL_DIR/$JAR_NAME" \
|| fail "Download failed. Check your internet connection and try again."
elif command -v wget &>/dev/null; then
wget -q "$REMOTE_JAR_URL" -O "$INSTALL_DIR/$JAR_NAME" \
|| fail "Download failed. Check your internet connection and try again."
else
fail "Neither curl nor wget found. Install one of them and re-run."
fi
ok "Downloaded Coderive.jar"
fi
# ── Step 4: Create the `coderive` wrapper ────────────────────────────────────
echo ""
echo -e "${BOLD}[4/4] Creating 'coderive' command...${RESET}"
WRAPPER="$BIN_DIR/coderive"
cat > "$WRAPPER" <<EOF
#!/usr/bin/env bash
# Coderive v${VERSION} runner — generated by install.sh
exec java -cp "${INSTALL_DIR}/${JAR_NAME}" cod.runner.CommandRunner "\$@"
EOF
chmod +x "$WRAPPER"
ok "'coderive' installed to $WRAPPER"
# ── PATH reminder ─────────────────────────────────────────────────────────────
echo ""
if [[ ":$PATH:" != *":$BIN_DIR:"* ]]; then
warn "$BIN_DIR is not in your PATH."
echo ""
echo -e " Add the following line to your ${BOLD}~/.bashrc${RESET} (or ${BOLD}~/.zshrc${RESET}):"
echo ""
echo -e " ${CYAN}export PATH=\"\$HOME/.local/bin:\$PATH\"${RESET}"
echo ""
echo -e " Then reload your shell:"
echo -e " ${CYAN}source ~/.bashrc${RESET}"
echo ""
else
ok "$BIN_DIR is already in PATH"
fi
# ── Done ─────────────────────────────────────────────────────────────────────
echo -e "${BOLD}${GREEN} ✔ Coderive v${VERSION} is ready!${RESET}"
echo ""
echo -e " Try it now:"
echo ""
echo -e " Create a file ${CYAN}hello.cod${RESET} with:"
echo -e " ${CYAN}name := in(text, \"What's your name? \")${RESET}"
echo -e " ${CYAN}out(\"Hello, {name}! Welcome to Coderive.\")${RESET}"
echo ""
echo -e " Then run:"
echo -e " ${CYAN}coderive hello.cod${RESET}"
echo ""
echo -e " Or try the web playground:"
echo -e " ${CYAN}https://coderive-lang.github.io/Coderive${RESET}"
echo ""