MCP Terminal Server
by dillip285
- bin
#!/usr/bin/env bash
#
# Setup script for Genkit engineering.
#
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0
# NOTE: This script is not specific to any particular runtime. It is intended to
# be used as a convenience script for eng so that all the runtimes are set up in
# a consistent manner so that pre-commit hooks run properly and the environment
# is consistent.
# TODO: This script is nowhere close to perfect. At a later date, we can replace
# this with something like nix to have a reproducible environment. For now this
# is a convenience script just to get eng started as quickly as possible.
if ((EUID == 0)) && [[ -z ${DANGEROUSLY_RUN_AS_ROOT+x} ]]; then
echo "Please do not run as root unless DANGEROUSLY_RUN_AS_ROOT is set."
exit 1
fi
[[ ${EUID} != 0 ]] && set -euo pipefail
TOP_DIR=$(git rev-parse --show-toplevel)
PNPM_VERSION="10.2.0"
NODE_VERSION="23"
NVM_VERSION="0.40.1"
AUDIENCE="eng"
while getopts ":a:" opt; do
case ${opt} in
a)
AUDIENCE="${OPTARG}"
;;
\?)
echo "Invalid option: -${OPTARG}" >&2
exit 1
;;
*)
echo "Unsupported option: -${OPTARG}" >&2
exit 1
;;
esac
done
if [[ -z ${AUDIENCE} ]]; then
echo "Audience flag (-a) is required."
echo "Usage: $0 -a <eng|ci>"
exit 1
fi
OS_NAME=$(uname)
PYTHON_CLI_TOOLS=(
"httpie" # HTTP client. See: https://httpie.io/
"mypy" # Static type checker. See: https://mypy.readthedocs.io/en/stable/
"ruff" # Fast linter. See: https://github.com/astral-sh/ruff
)
# Updates your shell profile to include a path.
function genkit::update_path() {
local new_path="$1"
# Remove trailing slash if present.
new_path="${new_path%/}"
# Check if path is already in PATH
if [[ ":$PATH:" != *":$new_path:"* ]]; then
if [ -n "${ZSH_VERSION:-}" ]; then
echo "export PATH=\"$new_path:\$PATH\"" >>"$HOME/.zshrc"
else
echo "export PATH=\"$new_path:\$PATH\"" >>"$HOME/.bashrc"
fi
export PATH="$new_path:$PATH"
echo "Path $new_path added successfully"
else
echo "Path $new_path already exists in PATH"
fi
}
function genkit::preconfigure_environment() {
git clean -Xfd
genkit::update_path "$HOME/.cargo/bin"
genkit::update_path "$HOME/.local/bin"
genkit::update_path "$HOME/.local/share/pnpm"
genkit::update_path "$HOME/go/bin"
genkit::update_path "$HOME/google-cloud-sdk/bin"
}
# Install all the required tools common to all audiences.
function genkit::install_prerequisites() {
genkit::preconfigure_environment
if [[ ${OS_NAME} == "Darwin" && -x "$(command -v brew)" ]]; then
# Darwin-based systems.
brew install \
cmake \
curl \
fd \
gh \
go \
python3 \
ripgrep
elif [[ -x "$(command -v apt)" ]]; then
sudo apt update -y && sudo apt upgrade -y
# Check if the OS is Ubuntu 22.04 (or a derivative) since some of our eng
# use it.
if lsb_release -a | grep -q "Description:.*Ubuntu 22.04"; then
sudo add-apt-repository -y ppa:longsleep/golang-backports
sudo apt update
sudo apt install -y golang-go
else
sudo apt install -y golang
fi
if lsb_release -a | grep -q "Description:.*Ubuntu"; then
sudo apt install -y build-essential
fi
# Debian-based systems.
sudo apt install -y \
cmake \
curl \
fd-find \
gh \
python3 \
ripgrep
elif [[ -x "$(command -v dnf)" ]]; then
# Fedora-based systems.
sudo dnf install -y \
cmake \
curl \
fd-find \
gh \
go \
python3 \
ripgrep
else
echo "Unsupported OS. Please install tools manually."
fi
genkit::install_rust
genkit::install_uv
genkit::install_and_configure_nvm
genkit::install_pnpm
}
function genkit::install_rust() {
# Install rust.
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
rustup update
}
# Install uv for Python versioning, packaging, and workspace management.
function genkit::install_uv() {
curl -LsSf https://astral.sh/uv/install.sh | sh
}
# Install pnpm for JavaScript package management.
# See: https://github.com/pnpm/pnpm/issues/6217
function genkit::install_pnpm() {
curl -fsSL https://get.pnpm.io/install.sh |
env ENV="$HOME/.bashrc" \
SHELL="$(which bash)" \
PNPM_VERSION="${PNPM_VERSION}" \
bash -
}
# Install node version manager.
function genkit::install_and_configure_nvm() {
export NVM_DIR="$HOME/.config/nvm"
mkdir -p "$NVM_DIR"
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh | bash
[ -s "$NVM_DIR/nvm.sh" ] && source "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && source "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install "${NODE_VERSION}"
nvm use "${NODE_VERSION}"
nvm alias default "${NODE_VERSION}"
}
# Install the Google Cloud SDK.
function genkit::install_google_cloud_sdk() {
# This depends on Python 3.11 and installs it for the user on some systems.
if command -v gcloud &>/dev/null; then
gcloud config set disable_usage_reporting true
gcloud components update
else
curl https://sdk.cloud.google.com | bash -s -- --disable-prompts
gcloud config set disable_usage_reporting true
fi
}
# Install all the required tools that have been written in Go.
function genkit::install_go_cli_tools_ci() {
go install github.com/google/go-licenses@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
go install oss.terrastruct.com/d2@latest
}
# Install all the required tools that have been written in Go.
function genkit::install_go_cli_tools_eng() {
go install github.com/Gelio/go-global-update@latest
go install github.com/captainhook-go/captainhook/cmd/captainhook@latest
go install github.com/google/addlicense@latest
go install github.com/google/go-licenses@latest
go install github.com/jesseduffield/lazygit@latest
go install golang.org/x/vuln/cmd/govulncheck@latest
go install oss.terrastruct.com/d2@latest
}
# Install all the required tools that have been written in Rust. We're assuming
# that the user has already installed rust and cargo.
function genkit::install_cargo_cli_tools_eng() {
cargo install --locked \
convco \
pylyzer \
rust-parallel \
taplo-cli
}
# Install NPM packages.
function genkit::install_pnpm_cli_tools() {
# Genkit CLI: https://firebase.google.com/docs/genkit/devtools
# Biome: https://biomejs.dev/
pnpm add -g \
@biomejs/biome \
prettier
}
# Install all the Python-related formatter and static analysis tools.
function genkit::install_python_cli_tools() {
for package in "${PYTHON_CLI_TOOLS[@]}"; do
uv tool install "${package}"
done
}
# Install documentation site generator.
function genkit::install_docs_cli_tools() {
# Install d2.
curl -fsSL https://d2lang.com/install.sh | sh -s --
# Engineering documentation site generator.
# See: https://squidfunk.github.io/mkdocs-material/
uv tool install \
mkdocs \
--with mkdocs-autorefs \
--with mkdocs-d2-plugin \
--with mkdocs-literate-nav \
--with mkdocs-material \
--with mkdocs-mermaid2-plugin \
--with mkdocs-minify-plugin \
--with mkdocstrings[python]
}
# Configure the commit message template.
function genkit::configure_commit_template() {
echo "Setting up commit message template..."
ln -sf "${TOP_DIR}/COMMIT_MESSAGE_TEMPLATE" "${TOP_DIR}/.git/COMMIT_MESSAGE_TEMPLATE"
git config commit.template "${TOP_DIR}/.git/COMMIT_MESSAGE_TEMPLATE"
}
# Install pre-commit hooks.
function genkit::install_pre_commit_hooks() {
genkit::configure_commit_template
captainhook install -f -c "${TOP_DIR}/captainhook.json"
}
# Setup genkit.
function genkit::setup_genkit() {
pushd "${TOP_DIR}"
pnpm i
pnpm run setup
popd
}
# Install all the common packages.
function genkit::install_common_packages() {
export PNPM_HOME="$HOME/.local/share/pnpm"
genkit::install_prerequisites
genkit::install_python_cli_tools
genkit::install_docs_cli_tools
genkit::install_pnpm_cli_tools
}
# Install all the required tools for CI.
function genkit::install_ci_packages() {
genkit::install_common_packages
genkit::install_go_cli_tools_ci
}
# Install all the required tools for engineering.
function genkit::install_eng_packages() {
genkit::install_common_packages
genkit::install_go_cli_tools_eng
genkit::install_cargo_cli_tools_eng
genkit::install_pre_commit_hooks
genkit::install_google_cloud_sdk
genkit::setup_genkit
}
# Entry point for the setup script.
function genkit::main() {
case "${AUDIENCE}" in
eng)
genkit::install_eng_packages
;;
ci)
genkit::install_ci_packages
;;
*)
echo "Unsupported audience: ${AUDIENCE}"
exit 1
;;
esac
echo "Please restart your shell."
}
genkit::main