From 58ef0d495e528beac2ed80891a4f57b9c8e0b13f Mon Sep 17 00:00:00 2001 From: Emily Boudreaux Date: Fri, 21 Mar 2025 11:42:01 -0400 Subject: [PATCH] build(mk): added auto ninja installer --- mk | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 57 insertions(+), 2 deletions(-) diff --git a/mk b/mk index cf93850..62c03c0 100755 --- a/mk +++ b/mk @@ -183,8 +183,63 @@ fi log "${BLUE}[Info] Checking if Ninja is installed...${NC}" if ! command -v ninja &> /dev/null; then log "${RED}[Error] Ninja is not installed. Exiting...${NC}" - log "${YELLOW}[Info] Please install Ninja and try again.${NC}" - exit 1 + + # Check if the user would like to try to install ninja by getting input + installNinja=0 + while true; do + read -p "Would you like to try to install Ninja? [y/n]: " yn + case $yn in + [Yy]* ) installNinja=1; break;; + [Nn]* ) break;; + * ) echo "Please answer yes or no.";; + esac + done + if [[ $installNinja -eq 1 ]]; then + # check if pip is installed + if ! command -v pip &> /dev/null; then + log "${RED}[Error] pip is not installed. Exiting...${NC}" + log "${YELLOW}[Info] Please install pip and try again.${NC}" + exit 1 + else + log "${MAGENTA}[Success] pip is installed. Continuing...${NC}" + fi + + # check if python3 is installed + if ! command -v python3 &> /dev/null; then + log "${RED}[Error] python3 is not installed. Exiting...${NC}" + log "${YELLOW}[Info] Please install python3 and try again.${NC}" + log "${YELLOW}[INFO] If you have python3 installed, please add it to your PATH.${NC}" + exit 1 + else + log "${MAGENTA}[Success] python3 is installed. Continuing...${NC}" + fi + + # Check if the venv ~/.4DSSE_env exists + if [[ ! -d "$HOME/.4DSSE_env" ]]; then + log "${BLUE}[Info] Creating virtual environment...${NC}" + python3 -m venv "$HOME/.4DSSE_env" + source "$HOME/.4DSSE_env/bin/activate" + log "${GREEN}[Success] Virtual environment created.${NC}" + else + log "${MAGENTA}[Succsess] Virtual environment already exists. Skipping...${NC}" + fi + + # install ninja + log "${BLUE}[Info] Installing Ninja...${NC}" + pip install ninja + + # confirm ninja is installed + if ! command -v ninja &> /dev/null; then + log "${RED}[Error] Ninja did not install properly. Exiting...${NC}" + log "${YELLOW}[Info] Please manually install Ninja and try again.${NC}" + exit 1 + else + log "${GREEN}[Success] Ninja installed.${NC}" + fi + else + log "${YELLOW}[Info] Please install Ninja and try again.${NC}" + exit 1 + fi else log "${MAGENTA}[Success] Ninja is installed. Continuing...${NC}" fi