From 368457ecce07be94fdb678c5b2aa59ea334d85f6 Mon Sep 17 00:00:00 2001 From: Dmitrii Date: Wed, 22 Apr 2026 09:23:01 -0400 Subject: [PATCH] fix: move dep checks into scripts/check_deps.sh for robustness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces fragile one-liner Makefile chain with a proper shell script. Tries: sudo -n apt → python3 -m pip --user → get-pip.py bootstrap. Prints a clear manual-install message if all automated paths fail. Co-Authored-By: Claude Sonnet 4.6 --- Makefile | 14 +------------ scripts/check_deps.sh | 48 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 13 deletions(-) create mode 100755 scripts/check_deps.sh diff --git a/Makefile b/Makefile index f4cf846..fefd5cb 100644 --- a/Makefile +++ b/Makefile @@ -39,19 +39,7 @@ help: # Setup commands check-deps: - @echo "Checking system dependencies..." - @which python3 >/dev/null 2>&1 || \ - { echo "Installing python3..." && sudo -n apt-get install -y python3 2>/dev/null || \ - { echo "ERROR: python3 not found. Run: sudo apt-get install -y python3" ; exit 1 ; } ; } - @python3 -c "import cryptography" 2>/dev/null || { \ - echo "Installing python3-cryptography..." ; \ - sudo -n apt-get install -y python3-cryptography 2>/dev/null || \ - python3 -m pip install --user cryptography 2>/dev/null || \ - { python3 -m ensurepip --upgrade 2>/dev/null && python3 -m pip install --user cryptography 2>/dev/null ; } || \ - { echo "ERROR: Cannot install python3-cryptography. Run: sudo apt-get install python3-cryptography" ; exit 1 ; } ; } - @python3 -c "import cryptography" >/dev/null 2>&1 || \ - { echo "ERROR: python3-cryptography still not found. Run: sudo apt-get install python3-cryptography" ; exit 1 ; } - @echo "Dependencies OK." + @sh scripts/check_deps.sh setup: check-deps @echo "Setting up Personal Internet Cell..." diff --git a/scripts/check_deps.sh b/scripts/check_deps.sh new file mode 100755 index 0000000..241046c --- /dev/null +++ b/scripts/check_deps.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Install Python dependencies needed by setup_cell.py +set -e + +echo "Checking system dependencies..." + +# Ensure python3 is available +if ! command -v python3 >/dev/null 2>&1; then + echo "Installing python3..." + sudo apt-get install -y python3 || { echo "ERROR: python3 not found and could not install it."; exit 1; } +fi + +# Check if cryptography is already importable +if python3 -c "import cryptography" 2>/dev/null; then + echo "Dependencies OK." + exit 0 +fi + +echo "Installing python3-cryptography..." + +# 1. Try apt (works if sudo is passwordless or interactive TTY is available) +if sudo -n apt-get install -y python3-cryptography 2>/dev/null; then + echo "Dependencies OK." + exit 0 +fi + +# 2. Try pip (module form, covers both pip3 and python3 -m pip) +if python3 -m pip install --user cryptography 2>/dev/null; then + echo "Dependencies OK." + exit 0 +fi + +# 3. Bootstrap pip via get-pip.py, then install +if command -v curl >/dev/null 2>&1; then + curl -sSL https://bootstrap.pypa.io/get-pip.py -o /tmp/get-pip.py 2>/dev/null \ + && python3 /tmp/get-pip.py --user -q 2>/dev/null \ + && python3 -m pip install --user cryptography 2>/dev/null \ + && { echo "Dependencies OK."; exit 0; } +fi + +# 4. No automated path worked — ask the user to install manually +echo "" +echo "ERROR: Could not install python3-cryptography automatically." +echo "Please run the following command and then retry:" +echo "" +echo " sudo apt-get install -y python3-cryptography" +echo "" +exit 1