-
Notifications
You must be signed in to change notification settings - Fork 0
🥯 [just] v4.2: script for installing pre-requisites #48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ee6366f
1860e09
3a1b419
051e2da
fcee35c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,258 @@ | ||||||||||
| #!/usr/bin/env bash | ||||||||||
| # Install prerequisites for just recipes | ||||||||||
| # | ||||||||||
| # Usage: ./.just/install-prerequisites.sh | ||||||||||
| # | ||||||||||
| # This script checks for required tools (just, gh, shellcheck, markdownlint-cli2, jq) | ||||||||||
| # and helps install them: | ||||||||||
| # | ||||||||||
| # - macOS: Automatically installs missing tools using Homebrew | ||||||||||
| # - Linux: Displays installation commands for manual execution | ||||||||||
| # - Other: Shows links to installation documentation | ||||||||||
| # | ||||||||||
| # Run multiple times to verify installations completed successfully. | ||||||||||
|
|
||||||||||
| set -euo pipefail # strict mode | ||||||||||
|
|
||||||||||
| # ANSI color codes | ||||||||||
| RED='\033[0;31m' | ||||||||||
| GREEN='\033[0;32m' | ||||||||||
| YELLOW='\033[1;33m' | ||||||||||
| BLUE='\033[0;34m' | ||||||||||
| CYAN='\033[0;36m' | ||||||||||
| MAGENTA='\033[0;35m' | ||||||||||
| NC='\033[0m' # No Color | ||||||||||
|
|
||||||||||
| echo -e "${MAGENTA}Checking prerequisites for just recipes...${NC}" | ||||||||||
| echo "" | ||||||||||
|
|
||||||||||
| MISSING=() | ||||||||||
| INSTALLED=() | ||||||||||
|
|
||||||||||
| # check each prerequisite | ||||||||||
| if command -v just &> /dev/null; then | ||||||||||
| INSTALLED+=("just") | ||||||||||
| else | ||||||||||
| MISSING+=("just") | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| if command -v gh &> /dev/null; then | ||||||||||
| INSTALLED+=("gh") | ||||||||||
| else | ||||||||||
| MISSING+=("gh") | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| if command -v shellcheck &> /dev/null; then | ||||||||||
| INSTALLED+=("shellcheck") | ||||||||||
| else | ||||||||||
| MISSING+=("shellcheck") | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| if command -v markdownlint-cli2 &> /dev/null; then | ||||||||||
| INSTALLED+=("markdownlint-cli2") | ||||||||||
| else | ||||||||||
| MISSING+=("markdownlint-cli2") | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| if command -v jq &> /dev/null; then | ||||||||||
| INSTALLED+=("jq") | ||||||||||
| else | ||||||||||
| MISSING+=("jq") | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| # report what's already installed | ||||||||||
| if [[ ${#INSTALLED[@]} -gt 0 ]]; then | ||||||||||
| echo -e "${GREEN}Already installed:${NC}" | ||||||||||
| for tool in "${INSTALLED[@]}"; do | ||||||||||
| echo -e " ${GREEN}✓${NC} $tool" | ||||||||||
| done | ||||||||||
| echo "" | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| # if everything is installed, we're done | ||||||||||
| if [[ ${#MISSING[@]} -eq 0 ]]; then | ||||||||||
| echo -e "${GREEN}All prerequisites are installed!${NC}" | ||||||||||
| exit 0 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| # report what's missing | ||||||||||
| echo -e "${YELLOW}Missing prerequisites:${NC}" | ||||||||||
| for tool in "${MISSING[@]}"; do | ||||||||||
| echo -e " ${YELLOW}✗${NC} $tool" | ||||||||||
| done | ||||||||||
| echo "" | ||||||||||
|
|
||||||||||
| # detect OS and provide installation instructions | ||||||||||
| if [[ "$OSTYPE" == "darwin"* ]]; then | ||||||||||
| echo -e "${BLUE}Detected macOS. Installing with Homebrew...${NC}" | ||||||||||
| echo "" | ||||||||||
|
|
||||||||||
| if ! command -v brew &> /dev/null; then | ||||||||||
| echo -e "${RED}Homebrew is not installed!${NC}" | ||||||||||
| echo "Install Homebrew first: https://brew.sh" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| INSTALL_SUCCESS=() | ||||||||||
| INSTALL_FAILED=() | ||||||||||
|
|
||||||||||
| for tool in "${MISSING[@]}"; do | ||||||||||
| case "$tool" in | ||||||||||
| just) | ||||||||||
| echo -e "${CYAN}Installing just...${NC}" | ||||||||||
| if brew install just; then | ||||||||||
| INSTALL_SUCCESS+=("just") | ||||||||||
| else | ||||||||||
| INSTALL_FAILED+=("just") | ||||||||||
| echo -e "${RED}Failed to install just${NC}" | ||||||||||
| fi | ||||||||||
| ;; | ||||||||||
| gh) | ||||||||||
| echo -e "${CYAN}Installing GitHub CLI...${NC}" | ||||||||||
| if brew install gh; then | ||||||||||
| INSTALL_SUCCESS+=("gh") | ||||||||||
| echo -e "${YELLOW}Don't forget to authenticate: gh auth login${NC}" | ||||||||||
| else | ||||||||||
| INSTALL_FAILED+=("gh") | ||||||||||
| echo -e "${RED}Failed to install gh${NC}" | ||||||||||
| fi | ||||||||||
| ;; | ||||||||||
| shellcheck) | ||||||||||
| echo -e "${CYAN}Installing shellcheck...${NC}" | ||||||||||
| if brew install shellcheck; then | ||||||||||
| INSTALL_SUCCESS+=("shellcheck") | ||||||||||
| else | ||||||||||
| INSTALL_FAILED+=("shellcheck") | ||||||||||
| echo -e "${RED}Failed to install shellcheck${NC}" | ||||||||||
| fi | ||||||||||
| ;; | ||||||||||
| markdownlint-cli2) | ||||||||||
| echo -e "${CYAN}Installing markdownlint-cli2...${NC}" | ||||||||||
| if ! command -v npm &> /dev/null; then | ||||||||||
| echo -e "${RED}npm is not installed! Install Node.js first.${NC}" | ||||||||||
| echo "Install Node.js: brew install node" | ||||||||||
| INSTALL_FAILED+=("markdownlint-cli2") | ||||||||||
| elif npm install -g markdownlint-cli2; then | ||||||||||
| INSTALL_SUCCESS+=("markdownlint-cli2") | ||||||||||
| else | ||||||||||
| INSTALL_FAILED+=("markdownlint-cli2") | ||||||||||
| echo -e "${RED}Failed to install markdownlint-cli2${NC}" | ||||||||||
| fi | ||||||||||
| ;; | ||||||||||
| jq) | ||||||||||
| echo -e "${CYAN}Installing jq...${NC}" | ||||||||||
| if brew install jq; then | ||||||||||
| INSTALL_SUCCESS+=("jq") | ||||||||||
| else | ||||||||||
| INSTALL_FAILED+=("jq") | ||||||||||
| echo -e "${RED}Failed to install jq${NC}" | ||||||||||
| fi | ||||||||||
| ;; | ||||||||||
| esac | ||||||||||
| done | ||||||||||
|
|
||||||||||
| echo "" | ||||||||||
| if [[ ${#INSTALL_SUCCESS[@]} -gt 0 ]]; then | ||||||||||
| echo -e "${GREEN}Successfully installed:${NC}" | ||||||||||
| for tool in "${INSTALL_SUCCESS[@]}"; do | ||||||||||
| echo -e " ${GREEN}✓${NC} $tool" | ||||||||||
| done | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| if [[ ${#INSTALL_FAILED[@]} -gt 0 ]]; then | ||||||||||
| echo "" | ||||||||||
| echo -e "${RED}Failed to install:${NC}" | ||||||||||
| for tool in "${INSTALL_FAILED[@]}"; do | ||||||||||
| echo -e " ${RED}✗${NC} $tool" | ||||||||||
| done | ||||||||||
| echo "" | ||||||||||
| echo -e "${YELLOW}Run this script again to retry or install manually.${NC}" | ||||||||||
| exit 1 | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| elif [[ "$OSTYPE" == "linux-gnu"* ]]; then | ||||||||||
| echo -e "${BLUE}Detected Linux. Showing installation commands...${NC}" | ||||||||||
| echo "" | ||||||||||
|
|
||||||||||
| # detect package manager | ||||||||||
| if command -v apt-get &> /dev/null; then | ||||||||||
| PKG_MGR="apt-get" | ||||||||||
| echo -e "${BLUE}Using apt-get package manager${NC}" | ||||||||||
| elif command -v dnf &> /dev/null; then | ||||||||||
| PKG_MGR="dnf" | ||||||||||
| echo -e "${BLUE}Using dnf package manager${NC}" | ||||||||||
| elif command -v pacman &> /dev/null; then | ||||||||||
| PKG_MGR="pacman" | ||||||||||
| echo -e "${BLUE}Using pacman package manager${NC}" | ||||||||||
| else | ||||||||||
| echo -e "${YELLOW}Could not detect package manager. Manual installation required.${NC}" | ||||||||||
| PKG_MGR="manual" | ||||||||||
| fi | ||||||||||
|
|
||||||||||
| for tool in "${MISSING[@]}"; do | ||||||||||
| case "$tool" in | ||||||||||
| just) | ||||||||||
| if [[ "$PKG_MGR" == "apt-get" ]]; then | ||||||||||
| echo -e "${CYAN}Install just:${NC}" | ||||||||||
| echo " wget -qO - 'https://proget.makedeb.org/debian-feeds/prebuilt-mpr.pub' | gpg --dearmor | sudo tee /usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg 1> /dev/null" | ||||||||||
| echo " echo \"deb [arch=all,\$(dpkg --print-architecture) signed-by=/usr/share/keyrings/prebuilt-mpr-archive-keyring.gpg] https://proget.makedeb.org prebuilt-mpr \$(lsb_release -cs)\" | sudo tee /etc/apt/sources.list.d/prebuilt-mpr.list" | ||||||||||
| echo " sudo apt update && sudo apt install just" | ||||||||||
| elif [[ "$PKG_MGR" == "dnf" ]]; then | ||||||||||
| echo -e "${CYAN}Install just:${NC} sudo dnf install just" | ||||||||||
| elif [[ "$PKG_MGR" == "pacman" ]]; then | ||||||||||
| echo -e "${CYAN}Install just:${NC} sudo pacman -S just" | ||||||||||
| else | ||||||||||
| echo -e "${CYAN}Install just:${NC} See https://github.com/casey/just#installation" | ||||||||||
| fi | ||||||||||
| ;; | ||||||||||
| gh) | ||||||||||
| echo -e "${CYAN}Install GitHub CLI:${NC} See https://github.com/cli/cli/blob/trunk/docs/install_linux.md" | ||||||||||
| echo -e "${YELLOW}Don't forget to authenticate: gh auth login${NC}" | ||||||||||
| ;; | ||||||||||
| shellcheck) | ||||||||||
| if [[ "$PKG_MGR" == "apt-get" ]]; then | ||||||||||
| echo -e "${CYAN}Install shellcheck:${NC} sudo apt-get install shellcheck" | ||||||||||
| elif [[ "$PKG_MGR" == "dnf" ]]; then | ||||||||||
| echo -e "${CYAN}Install shellcheck:${NC} sudo dnf install shellcheck" | ||||||||||
| elif [[ "$PKG_MGR" == "pacman" ]]; then | ||||||||||
| echo -e "${CYAN}Install shellcheck:${NC} sudo pacman -S shellcheck" | ||||||||||
|
||||||||||
| echo -e "${CYAN}Install shellcheck:${NC} sudo pacman -S shellcheck" | |
| echo -e "${CYAN}Install shellcheck:${NC} sudo pacman -S shellcheck" | |
| else | |
| echo -e "${CYAN}Install shellcheck:${NC} See https://github.com/koalaman/shellcheck#installing" |
Copilot
AI
Dec 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The jq installation case is missing a fallback message for manual installation when PKG_MGR is 'manual', unlike the just tool which provides a link. Consider adding an else clause for consistency.
| echo -e "${CYAN}Install jq:${NC} sudo pacman -S jq" | |
| echo -e "${CYAN}Install jq:${NC} sudo pacman -S jq" | |
| else | |
| echo -e "${CYAN}Install jq manually:${NC} See https://jqlang.github.io/jq/download/" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These complex multi-line installation commands are difficult to read and maintain. Consider breaking them into separate echo statements or storing them in a heredoc for better readability.