Repository navigation
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·246 lines (213 loc) · 9.35 KB
/
Copy pathinstall.sh
File metadata and controls
executable file
·246 lines (213 loc) · 9.35 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
#!/usr/bin/env bash
# ──────────────────────────────────────────────────────────────────────────────
# Xpress++ installer
#
# What this does:
# 1. Detects your OS and installs all required dependencies
# (cmake, g++, jsoncpp, openssl, zlib, and Drogon)
# 2. Builds the `xp` CLI from source
# 3. Installs it to ~/.local/bin/xp
#
# Usage:
# curl -sSfL https://raw.githubusercontent.com/aaryan359/xpresspp/main/install.sh | bash
# -- or --
# ./install.sh
# ──────────────────────────────────────────────────────────────────────────────
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
INSTALL_DIR="${HOME}/.local/bin"
XP_BINARY="${ROOT_DIR}/cli/build/xp"
XP_WRAPPER="${INSTALL_DIR}/xp"
# ── Colour helpers ────────────────────────────────────────────────────────────
if [ -t 1 ]; then
GREEN="\033[32m"; CYAN="\033[36m"; YELLOW="\033[33m"
RED="\033[31m"; BOLD="\033[1m"; DIM="\033[2m"; RESET="\033[0m"
else
GREEN=""; CYAN=""; YELLOW=""; RED=""; BOLD=""; DIM=""; RESET=""
fi
step() { echo -e "${CYAN} ▸ ${RESET}${1}"; }
ok() { echo -e "${GREEN}${BOLD} ✓ ${RESET}${1}"; }
warn() { echo -e "${YELLOW}${BOLD} ⚠ ${RESET}${YELLOW}${1}${RESET}"; }
die() { echo -e "${RED}${BOLD}\n ✗ ${1}${RESET}\n" >&2; exit 1; }
divider() { echo -e "${DIM} ────────────────────────────────────────────${RESET}"; }
# ── Detect OS ─────────────────────────────────────────────────────────────────
detect_os() {
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "macos"
elif [ -f /etc/os-release ]; then
# shellcheck disable=SC1091
source /etc/os-release
case "$ID" in
ubuntu|debian|linuxmint|pop) echo "debian" ;;
arch|manjaro|endeavouros) echo "arch" ;;
fedora|rhel|centos|almalinux) echo "fedora" ;;
opensuse*|sles) echo "suse" ;;
*)
if command -v apt-get &>/dev/null; then echo "debian"
elif command -v pacman &>/dev/null; then echo "arch"
elif command -v dnf &>/dev/null; then echo "fedora"
else die "Unsupported OS: $ID. Please install Drogon manually: https://github.com/drogonframework/drogon/wiki/ENG-02-Installation"
fi
;;
esac
elif command -v apt-get &>/dev/null; then echo "debian"
elif command -v pacman &>/dev/null; then echo "arch"
elif command -v dnf &>/dev/null; then echo "fedora"
else die "Cannot detect OS. Please install dependencies manually and re-run this script."
fi
}
# ── Install system build tools and Drogon's dependencies ─────────────────────
install_deps() {
local os="$1"
step "Installing build dependencies for ${os}..."
case "$os" in
debian)
sudo apt-get update -qq
sudo apt-get install -y --no-install-recommends \
build-essential git cmake \
libssl-dev libjsoncpp-dev zlib1g-dev \
libpq-dev uuid-dev libmariadb-dev libsqlite3-dev \
ca-certificates curl wget
;;
macos)
if ! command -v brew &>/dev/null; then
step "Installing Homebrew..."
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
fi
brew install cmake jsoncpp openssl zlib ossp-uuid sqlite libpq
;;
arch)
sudo pacman -Sy --noconfirm \
base-devel git cmake \
jsoncpp openssl zlib uuid \
postgresql-libs sqlite mariadb-libs
;;
fedora)
sudo dnf install -y \
gcc-c++ git cmake \
openssl-devel jsoncpp-devel zlib-devel \
libuuid-devel libpq-devel sqlite-devel mariadb-devel
;;
suse)
sudo zypper install -y \
gcc-c++ git cmake \
libopenssl-devel jsoncpp-devel zlib-devel \
postgresql-devel sqlite3-devel
;;
esac
ok "Build dependencies installed."
}
# ── Check if Drogon is already installed ──────────────────────────────────────
drogon_installed() {
# Check for the cmake config file that Drogon installs
local search_paths=(
"/usr/local/lib/cmake/Drogon"
"/usr/lib/cmake/Drogon"
"/opt/homebrew/lib/cmake/Drogon" # macOS ARM
"/usr/local/Cellar" # macOS Intel
)
for p in "${search_paths[@]}"; do
[ -d "$p" ] && return 0
done
# Try pkg-config or cmake itself
cmake --find-package -DNAME=Drogon -DCOMPILER_ID=GNU -DLANGUAGE=CXX \
-DMODE=EXIST &>/dev/null 2>&1 && return 0
return 1
}
# ── Install Drogon from source ────────────────────────────────────────────────
install_drogon() {
if drogon_installed; then
ok "Drogon is already installed — skipping."
return 0
fi
step "Building Drogon from source (this takes a few minutes)..."
local tmp_dir
tmp_dir="$(mktemp -d)"
trap 'rm -rf "$tmp_dir"' RETURN
git clone --depth 1 --recurse-submodules \
https://github.com/drogonframework/drogon.git \
"${tmp_dir}/drogon"
cmake -S "${tmp_dir}/drogon" -B "${tmp_dir}/drogon/build" \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_EXAMPLES=OFF \
-DBUILD_CTL=OFF \
-DBUILD_ORM=ON \
>/dev/null
cmake --build "${tmp_dir}/drogon/build" --parallel "$(nproc 2>/dev/null || echo 4)"
sudo cmake --install "${tmp_dir}/drogon/build" >/dev/null
ok "Drogon installed successfully."
}
# ── Build the xp CLI ──────────────────────────────────────────────────────────
build_cli() {
step "Building the xp CLI..."
cmake -S "${ROOT_DIR}/cli" -B "${ROOT_DIR}/cli/build" \
-DCMAKE_BUILD_TYPE=Release >/dev/null
cmake --build "${ROOT_DIR}/cli/build" --parallel "$(nproc 2>/dev/null || echo 4)"
ok "CLI built at ${XP_BINARY}"
}
# ── Install the wrapper script ─────────────────────────────────────────────────
install_wrapper() {
mkdir -p "${INSTALL_DIR}"
cat > "${XP_WRAPPER}" << EOF
#!/usr/bin/env bash
export XPRESSPP_HOME="${ROOT_DIR}"
exec "${XP_BINARY}" "\$@"
EOF
chmod +x "${XP_WRAPPER}"
ok "Installed: ${XP_WRAPPER}"
}
# ── Ensure ~/.local/bin is in PATH ────────────────────────────────────────────
ensure_path() {
if [[ ":${PATH}:" != *":${INSTALL_DIR}:"* ]]; then
warn "~/.local/bin is not in your PATH."
echo ""
echo " Add this line to your shell config file:"
local shell_config
shell_config="${HOME}/.bashrc"
if [[ "${SHELL}" == *"zsh"* ]]; then
shell_config="${HOME}/.zshrc"
elif [[ "${SHELL}" == *"fish"* ]]; then
shell_config="${HOME}/.config/fish/config.fish"
fi
echo -e "${CYAN} echo 'export PATH=\"\$HOME/.local/bin:\$PATH\"' >> ${shell_config}${RESET}"
echo -e "${CYAN} source ${shell_config}${RESET}"
echo ""
fi
}
# ── Main ──────────────────────────────────────────────────────────────────────
main() {
echo ""
echo -e "${CYAN}${BOLD} Xpress++ Installer${RESET}"
divider
local os
os=$(detect_os)
step "Detected OS: ${os}"
echo ""
install_deps "${os}"
echo ""
# If running standalone (e.g. via curl | bash or copying just the install.sh file)
if [ ! -d "${ROOT_DIR}/cli" ]; then
step "Cloning Xpress++ core repository to ${HOME}/.xpresspp..."
rm -rf "${HOME}/.xpresspp"
git clone --depth 1 https://github.com/aaryan359/xpresspp.git "${HOME}/.xpresspp"
ROOT_DIR="${HOME}/.xpresspp"
XP_BINARY="${ROOT_DIR}/cli/build/xp"
XP_WRAPPER="${INSTALL_DIR}/xp"
fi
install_drogon
echo ""
build_cli
echo ""
install_wrapper
echo ""
divider
echo -e "${GREEN}${BOLD} All done! Xpress++ is installed.${RESET}"
echo ""
echo -e " Run your first project:"
echo -e "${CYAN} xp create my-api${RESET}"
echo -e "${CYAN} cd my-api${RESET}"
echo -e "${CYAN} xp dev${RESET}"
echo ""
ensure_path
}
main