added metascript
This commit is contained in:
54
bootstrap.sh
Executable file
54
bootstrap.sh
Executable file
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# This is a metascript called by parent scripts to verify the execution environment.
|
||||
# It checks if the current shell is bash or not. If not, it terminates execution.
|
||||
|
||||
if [ -z "${BASH_VERSION:-}" ]; then
|
||||
echo "Error: This script must be run using bash." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Add a shortcut function 'b' to user's shell configurations if not already present
|
||||
add_b_alias() {
|
||||
local target_files=()
|
||||
[ -f "$HOME/.bashrc" ] && target_files+=("$HOME/.bashrc")
|
||||
[ -f "$HOME/.zshrc" ] && target_files+=("$HOME/.zshrc")
|
||||
|
||||
for config_file in "${target_files[@]}"; do
|
||||
# 1. Clean up old unmarkered function if it exists
|
||||
if grep -q "Shortcut for downloading bootstrap/install scripts" "$config_file" 2>/dev/null; then
|
||||
sed -i '/# Shortcut for downloading bootstrap\/install scripts/,/^}/d' "$config_file"
|
||||
fi
|
||||
|
||||
# 2. Clean up old markered function if it exists
|
||||
if grep -q "# >>> bootstrap-cli b function >>>" "$config_file" 2>/dev/null; then
|
||||
sed -i '/# >>> bootstrap-cli b function >>>/,/# <<< bootstrap-cli b function <<</d' "$config_file"
|
||||
fi
|
||||
|
||||
# 3. Append the new markered function block
|
||||
echo "Adding/updating helper function 'b' to $config_file..."
|
||||
cat << 'EOF' >> "$config_file"
|
||||
|
||||
# >>> bootstrap-cli b function >>>
|
||||
# Shortcut for downloading and running bootstrap/install scripts
|
||||
b() {
|
||||
if [ -z "$1" ]; then
|
||||
echo "Usage: b <script_name> [args...]" >&2
|
||||
return 1
|
||||
fi
|
||||
local script_name="$1"
|
||||
shift
|
||||
curl -fsSL "https://adityagupta.dev/b/${script_name}" | bash -s -- "$@"
|
||||
}
|
||||
# <<< bootstrap-cli b function <<<
|
||||
EOF
|
||||
done
|
||||
}
|
||||
|
||||
add_b_alias
|
||||
|
||||
# Source ~/.bashrc to make changes immediately available
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
echo "Sourcing ~/.bashrc..."
|
||||
. "$HOME/.bashrc"
|
||||
fi
|
||||
@@ -1,6 +1,26 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Run metascript to check if the shell is bash
|
||||
PARENT_DIR="$(dirname "$0")/.."
|
||||
METASCRIPT_LOCAL="$PARENT_DIR/bootstrap.sh"
|
||||
METASCRIPT_URL="https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/bootstrap.sh"
|
||||
|
||||
if [ -f "$METASCRIPT_LOCAL" ]; then
|
||||
. "$METASCRIPT_LOCAL"
|
||||
else
|
||||
if command -v wget >/dev/null 2>&1; then
|
||||
eval "$(wget -qO- "$METASCRIPT_URL")"
|
||||
elif command -v curl >/dev/null 2>&1; then
|
||||
eval "$(curl -fsSL "$METASCRIPT_URL")"
|
||||
else
|
||||
echo "Error: Neither wget nor curl is installed to fetch bootstrap.sh." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
|
||||
NVIM_VERSION="0.11.7"
|
||||
NVIM_URL="https://github.com/neovim/neovim/releases/download/v${NVIM_VERSION}/nvim-linux-x86_64.tar.gz"
|
||||
NVIM_INSTALL_DIR="/opt/nvim"
|
||||
@@ -48,20 +68,26 @@ check_config_dir() {
|
||||
}
|
||||
|
||||
install_packages() {
|
||||
echo "Detecting distribution..."
|
||||
echo "Detecting distribution and installing dependencies..."
|
||||
|
||||
if command -v pacman >/dev/null 2>&1; then
|
||||
echo "Arch Linux detected"
|
||||
sudo pacman -Sy --needed git wget tar
|
||||
sudo pacman -Sy --needed git wget tar curl unzip ripgrep fd cmake make gcc python nodejs npm xclip wl-clipboard fzf
|
||||
|
||||
elif command -v apt >/dev/null 2>&1; then
|
||||
echo "Debian/Ubuntu detected"
|
||||
sudo apt update
|
||||
sudo apt install -y git wget tar
|
||||
sudo apt install -y git wget tar curl unzip ripgrep fd-find cmake build-essential python3 python3-pip python3-venv nodejs npm xclip wl-clipboard fzf
|
||||
|
||||
# Create a symlink for fd-find if it doesn't already exist as fd
|
||||
if ! command -v fd >/dev/null 2>&1 && command -v fdfind >/dev/null 2>&1; then
|
||||
echo "Creating symlink for fd..."
|
||||
sudo ln -sf "$(command -v fdfind)" /usr/local/bin/fd
|
||||
fi
|
||||
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
echo "Fedora detected"
|
||||
sudo dnf install -y git wget tar
|
||||
sudo dnf install -y git wget tar curl unzip ripgrep fd-find cmake make gcc gcc-c++ python3 python3-pip nodejs npm xclip wl-clipboard fzf
|
||||
|
||||
else
|
||||
echo "Unsupported distribution."
|
||||
|
||||
Reference in New Issue
Block a user