improved routing
This commit is contained in:
23
bootstrap.sh
23
bootstrap.sh
@@ -36,9 +36,26 @@ b() {
|
||||
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 -- "$@"
|
||||
|
||||
local routes_dir="$HOME/.config/bootstrap"
|
||||
local routes_file="$routes_dir/routes.sh"
|
||||
local routes_url="https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/routes.sh"
|
||||
|
||||
mkdir -p "$routes_dir"
|
||||
|
||||
# Attempt to update the routes.sh file
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
curl -fsSL "$routes_url" -o "$routes_file" 2>/dev/null
|
||||
elif command -v wget >/dev/null 2>&1; then
|
||||
wget -qO "$routes_file" "$routes_url" 2>/dev/null
|
||||
fi
|
||||
|
||||
if [ ! -f "$routes_file" ]; then
|
||||
echo "Error: Routes file not found at $routes_file and could not be downloaded." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
bash "$routes_file" "$@"
|
||||
}
|
||||
# <<< bootstrap-cli b function <<<
|
||||
EOF
|
||||
|
||||
176
installers/install_yazi.sh
Executable file
176
installers/install_yazi.sh
Executable file
@@ -0,0 +1,176 @@
|
||||
#!/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
|
||||
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
|
||||
cleanup() {
|
||||
rm -rf "$TMP_DIR"
|
||||
}
|
||||
trap cleanup EXIT
|
||||
|
||||
confirm() {
|
||||
local prompt="$1"
|
||||
local response
|
||||
|
||||
read -r -p "$prompt [y/N]: " response </dev/tty || true
|
||||
|
||||
[[ "$response" =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
add_y_wrapper() {
|
||||
local target_files=()
|
||||
[ -f "$HOME/.bashrc" ] && target_files+=("$HOME/.bashrc")
|
||||
[ -f "$HOME/.zshrc" ] && target_files+=("$HOME/.zshrc")
|
||||
|
||||
for config_file in "${target_files[@]}"; do
|
||||
# Clean up old versions if any exist
|
||||
if grep -q "# >>> yazi wrapper >>>" "$config_file" 2>/dev/null; then
|
||||
sed -i '/# >>> yazi wrapper >>>/,/# <<< yazi wrapper <<</d' "$config_file"
|
||||
fi
|
||||
|
||||
echo "Adding yazi wrapper function 'y' to $config_file..."
|
||||
cat << 'EOF' >> "$config_file"
|
||||
|
||||
# >>> yazi wrapper >>>
|
||||
# Shell wrapper for yazi to change directory on exit
|
||||
y() {
|
||||
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
|
||||
yazi "$@" --cwd-file="$tmp"
|
||||
if cwd="$(command cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
||||
builtin cd -- "$cwd"
|
||||
fi
|
||||
rm -f -- "$tmp"
|
||||
}
|
||||
# <<< yazi wrapper <<<
|
||||
EOF
|
||||
done
|
||||
|
||||
# Source ~/.bashrc to make the alias immediately available in the current shell context (if sourced)
|
||||
if [ -f "$HOME/.bashrc" ]; then
|
||||
echo "Sourcing ~/.bashrc..."
|
||||
. "$HOME/.bashrc"
|
||||
fi
|
||||
}
|
||||
|
||||
install_yazi() {
|
||||
echo "Detecting distribution..."
|
||||
|
||||
if command -v pacman >/dev/null 2>&1; then
|
||||
echo "Arch Linux detected"
|
||||
if command -v yazi >/dev/null 2>&1; then
|
||||
if ! confirm "Yazi is already installed. Reinstall/Upgrade?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! confirm "Install Yazi and its dependencies?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Installing Yazi..."
|
||||
sudo pacman -Sy --needed yazi
|
||||
|
||||
echo "Installing dependencies subsequently..."
|
||||
sudo pacman -S --needed ffmpeg 7zip jq poppler fd ripgrep fzf zoxide resvg imagemagick
|
||||
|
||||
elif command -v apt >/dev/null 2>&1; then
|
||||
echo "Debian/Ubuntu detected"
|
||||
if command -v yazi >/dev/null 2>&1; then
|
||||
if ! confirm "Yazi is already installed. Reinstall/Upgrade?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! confirm "Install Yazi and its dependencies?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
sudo apt update
|
||||
sudo apt install -y curl wget git
|
||||
|
||||
echo "Fetching latest Yazi version from GitHub..."
|
||||
LATEST_TAG=$(curl -sL https://api.github.com/repos/sxyazi/yazi/releases/latest | grep '"tag_name":' | head -n1 | sed -E 's/.*"tag_name": "([^"]+)".*/\1/')
|
||||
if [ -z "$LATEST_TAG" ]; then
|
||||
LATEST_TAG="v26.5.6"
|
||||
fi
|
||||
|
||||
DEB_URL="https://github.com/sxyazi/yazi/releases/download/${LATEST_TAG}/yazi-x86_64-unknown-linux-gnu.deb"
|
||||
echo "Downloading Yazi ${LATEST_TAG} from ${DEB_URL}..."
|
||||
wget -qO "$TMP_DIR/yazi.deb" "$DEB_URL"
|
||||
|
||||
echo "Installing Yazi package..."
|
||||
sudo apt install -y "$TMP_DIR/yazi.deb"
|
||||
|
||||
echo "Installing dependencies subsequently..."
|
||||
sudo apt install -y ffmpeg jq poppler-utils fd-find ripgrep fzf zoxide resvg imagemagick 7zip || \
|
||||
sudo apt install -y ffmpeg jq poppler-utils fd-find ripgrep fzf zoxide resvg imagemagick p7zip-full
|
||||
|
||||
# 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"
|
||||
if command -v yazi >/dev/null 2>&1; then
|
||||
if ! confirm "Yazi is already installed. Reinstall/Upgrade?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
else
|
||||
if ! confirm "Install Yazi and its dependencies?"; then
|
||||
echo "Skipping Yazi installation."
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Installing dnf-plugins-core..."
|
||||
sudo dnf install -y dnf-plugins-core
|
||||
|
||||
echo "Enabling lihaohong/yazi copr repo..."
|
||||
sudo dnf copr enable -y lihaohong/yazi
|
||||
|
||||
echo "Installing Yazi (without weak dependencies first)..."
|
||||
sudo dnf install -y yazi --setopt=install_weak_deps=False
|
||||
|
||||
echo "Installing weak dependencies subsequently..."
|
||||
sudo dnf install -y yazi
|
||||
|
||||
else
|
||||
echo "Unsupported distribution."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
install_yazi
|
||||
add_y_wrapper
|
||||
echo
|
||||
echo "Yazi installation and configuration complete."
|
||||
}
|
||||
|
||||
main "$@"
|
||||
38
readme.md
38
readme.md
@@ -9,23 +9,23 @@ The goal is simple: reduce the number of manual steps required after installing
|
||||
| Script | Description |
|
||||
| ----------------- | --------------------------------------------------------------------- |
|
||||
| `install_nvim.sh` | Installs Neovim 0.11.7 and clones my Neovim configuration repository. |
|
||||
| `install_yazi.sh` | Installs Yazi terminal file manager and its dependencies. |
|
||||
|
||||
More scripts will be added over time.
|
||||
|
||||
## Usage
|
||||
|
||||
You can either download and inspect a script before running it:
|
||||
To bootstrap a new machine and set up the `b` command tool, run the following:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://adityagupta.dev/b/nvim -o install_nvim.sh
|
||||
less install_nvim.sh
|
||||
bash install_nvim.sh
|
||||
curl -fsSL https://adityagupta.dev/b | bash
|
||||
```
|
||||
|
||||
Or run it directly:
|
||||
Once bootstrapped, you can run any installer script using the `b` command followed by its shortcut name:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://adityagupta.dev/b/nvim | bash
|
||||
b nvim
|
||||
b yazi
|
||||
```
|
||||
|
||||
## What the Neovim Installer Does
|
||||
@@ -40,6 +40,19 @@ The Neovim bootstrap script:
|
||||
6. Creates a symlink at `/usr/local/bin/nvim`.
|
||||
7. Clones my Neovim configuration into `~/.config/nvim`.
|
||||
|
||||
## What the Yazi Installer Does
|
||||
|
||||
The Yazi bootstrap script:
|
||||
|
||||
1. Detects the Linux distribution.
|
||||
2. Prompts before installing or upgrading Yazi.
|
||||
3. Installs Yazi:
|
||||
* **Arch Linux**: Installs `yazi` via pacman.
|
||||
* **Debian / Ubuntu**: Downloads the latest `.deb` release package from GitHub and installs it.
|
||||
* **Fedora**: Enables the COPR repository (`lihaohong/yazi`) and installs `yazi` (initially skipping weak dependencies).
|
||||
4. Subsequently installs the dependencies (`ffmpeg`, `7zip` / `p7zip-full`, `jq`, `poppler`, `fd` / `fd-find`, `ripgrep`, `fzf`, `zoxide`, `resvg`, `imagemagick`) to make Yazi available quicker.
|
||||
5. Configures a shell wrapper function `y` in `~/.bashrc` and `~/.zshrc` that allows changing directory on exit.
|
||||
|
||||
Supported distributions:
|
||||
|
||||
* Arch Linux
|
||||
@@ -62,16 +75,18 @@ The scripts are intentionally straightforward Bash scripts that can be inspected
|
||||
## Repository Structure
|
||||
|
||||
```text
|
||||
installers/
|
||||
├── install_nvim.sh
|
||||
└── ...
|
||||
.
|
||||
├── bootstrap.sh
|
||||
├── routes.sh
|
||||
└── installers/
|
||||
├── install_nvim.sh
|
||||
└── install_yazi.sh
|
||||
```
|
||||
|
||||
## Future Plans
|
||||
|
||||
Potential additions include:
|
||||
|
||||
* Fish shell setup
|
||||
* Development environment bootstrap
|
||||
* Workstation setup
|
||||
* Server provisioning
|
||||
@@ -86,7 +101,8 @@ Running scripts directly from the internet is convenient but should always be ap
|
||||
If you do not trust the source, inspect the script before executing it:
|
||||
|
||||
```bash
|
||||
curl -fsSL https://adityagupta.dev/b/nvim
|
||||
curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/bootstrap.sh
|
||||
curl -fsSL https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/routes.sh
|
||||
```
|
||||
|
||||
and review the contents before piping it into a shell.
|
||||
|
||||
32
routes.sh
Executable file
32
routes.sh
Executable file
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Central routing script for bootstrap installers.
|
||||
# This file is updated automatically by the 'b' command.
|
||||
|
||||
if [ -z "${BASH_VERSION:-}" ]; then
|
||||
echo "Error: This script must be run using bash." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
SCRIPT_NAME="${1:-}"
|
||||
if [ -z "$SCRIPT_NAME" ]; then
|
||||
echo "Usage: b <script_name> [args...]" >&2
|
||||
exit 1
|
||||
fi
|
||||
shift
|
||||
|
||||
case "$SCRIPT_NAME" in
|
||||
nvim)
|
||||
echo "Launching Neovim installer..."
|
||||
curl -fsSL "https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/installers/install_nvim.sh" | bash -s -- "$@"
|
||||
;;
|
||||
yazi)
|
||||
echo "Launching Yazi installer..."
|
||||
curl -fsSL "https://git.adityagupta.dev/sortedcord/bootstrap/raw/branch/master/installers/install_yazi.sh" | bash -s -- "$@"
|
||||
;;
|
||||
*)
|
||||
echo "Error: Unknown script '$SCRIPT_NAME'." >&2
|
||||
echo "Available scripts: nvim, yazi" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
Reference in New Issue
Block a user