feat(install): add shell alias setup to install script

Swadhin Biswas committed 7 months ago
ddcc9e2
1 parent 3d51464
commit ddcc9e2
1 file changed
+80 -0
Showing 1 changed file+80-0
▼install.sh
+80-0
118
118
echo " ║ ⚡ FetchX Installer ⚡ ║"
119
119
echo " ║ Fast system info tool written in Rust ║"
120
120
echo " ╚═══════════════════════════════════════╝"
121
+echo -e "${RESET}"
122
+
123
+# ── Check prerequisites ─────────────────────────────────────────────────────
124
+info "Checking prerequisites..."
125
+
126
+if ! command_exists rustc || ! command_exists cargo; then
127
+ warn "Rust toolchain not found."
128
+ echo ""
129
+ echo -e " Install Rust with: ${BOLD}curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh${RESET}"
130
+ echo ""
131
+ read -rp "Install Rust now? [Y/n] " answer
132
+ if [[ ! "$answer" =~ ^[Nn]$ ]]; then
133
+ curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
134
+ source "$HOME/.cargo/env"
135
+ success "Rust installed!"
136
+ else
137
+ error "Rust is required to build FetchX. Aborting."
138
+ fi
139
+fi
140
+
141
+RUST_VERSION=$(rustc --version | awk '{print $2}')
142
+success "Rust $RUST_VERSION found"
143
+
144
+if ! command_exists git; then
145
+ error "git is required. Install it with your package manager."
146
+fi
147
+success "git found"
148
+
149
+# ── Clone or update repository ───────────────────────────────────────────────
150
+TMPDIR=$(mktemp -d)
151
+CLONE_DIR="$TMPDIR/fetchx"
152
+
153
+info "Cloning FetchX repository..."
154
+if git clone --depth 1 "$REPO_URL" "$CLONE_DIR" 2>/dev/null; then
155
+ success "Repository cloned"
156
+ cd "$CLONE_DIR/fetchx" # the Rust project is in the fetchx/ subdirectory
157
+else
158
+ # If clone fails, try building from current directory (local install)
159
+ if [[ -f "Cargo.toml" ]] && grep -q "fetchx" Cargo.toml 2>/dev/null; then
160
+ info "Building from local source..."
161
+ CLONE_DIR="."
162
+ else
163
+ error "Failed to clone repository and no local source found."
164
+ fi
165
+fi
166
+
167
+# ── Build ────────────────────────────────────────────────────────────────────
168
+info "Building FetchX (release mode with LTO)..."
169
+echo -e " ${YELLOW}This may take 1-2 minutes on first build...${RESET}"
170
+
171
+cargo build --release 2>&1 | while IFS= read -r line; do
172
+ if [[ "$line" == *"Compiling"* ]]; then
173
+ echo -e " ${CYAN}$line${RESET}"
174
+ fi
175
+done
176
+
177
+if [[ ! -f "target/release/$BINARY_NAME" ]]; then
178
+ error "Build failed — binary not found."
179
+fi
180
+
181
+BINARY_SIZE=$(du -h "target/release/$BINARY_NAME" | awk '{print $1}')
182
+success "Build complete! Binary size: $BINARY_SIZE"
183
+
184
+# ── Install binary ───────────────────────────────────────────────────────────
185
+info "Installing to $BINDIR..."
186
+maybe_sudo mkdir -p "$BINDIR"
187
+maybe_sudo install -m 755 "target/release/$BINARY_NAME" "$BINDIR/$BINARY_NAME"
188
+success "Installed $BINDIR/$BINARY_NAME"
189
+
190
+# ── Create default config ───────────────────────────────────────────────────
191
+CONFIG_DIR="$HOME/.config/fetchx"
192
+CONFIG_FILE="$CONFIG_DIR/config.toml"
193
+
194
+if [[ ! -f "$CONFIG_FILE" ]]; then
195
+ info "Creating default configuration..."
196
+ mkdir -p "$CONFIG_DIR"
197
+ "$BINDIR/$BINARY_NAME" --create-config 2>/dev/null || true
198
+ success "Config created at $CONFIG_FILE"
199
+else
200
+ success "Config already exists at $CONFIG_FILE"
121
201