|
23 | 23 | set -e |
24 | 24 | export DEBIAN_FRONTEND=noninteractive |
25 | 25 |
|
| 26 | +echo "Checking Python version..." |
| 27 | +# This command will fail if the Python version is less than 3.12 |
| 28 | +if ! python3 -c 'import sys; assert sys.version_info >= (3, 12)' 2>/dev/null; then |
| 29 | + # If the command fails, print an error |
| 30 | + CURRENT_VERSION=$(python3 --version 2>&1) # Get the full version string |
| 31 | + echo -e "\n\e[31mERROR: Outdated Python Version! You are currently using $CURRENT_VERSION, but MaxDiffusion requires Python version 3.12 or higher.\e[0m" |
| 32 | + # Ask the user if they want to create a virtual environment with uv |
| 33 | + read -p "Would you like to create a Python 3.12 virtual environment using uv? (y/n) " -n 1 -r |
| 34 | + echo # Move to a new line after input |
| 35 | + if [[ $REPLY =~ ^[Yy]$ ]]; then |
| 36 | + # Check if uv is installed first; if not, install uv |
| 37 | + if ! command -v uv &> /dev/null; then |
| 38 | + pip install uv |
| 39 | + fi |
| 40 | + maxdiffusion_dir=$(pwd) |
| 41 | + cd |
| 42 | + # Ask for the venv name |
| 43 | + read -p "Please enter a name for your new virtual environment (default: maxdiffusion_venv): " venv_name |
| 44 | + # Use a default name if the user provides no input |
| 45 | + if [ -z "$venv_name" ]; then |
| 46 | + venv_name="maxdiffusion_venv" |
| 47 | + echo "No name provided. Using default name: '$venv_name'" |
| 48 | + fi |
| 49 | + echo "Creating virtual environment '$venv_name' with Python 3.12..." |
| 50 | + uv venv --python 3.12 "$venv_name" --seed |
| 51 | + printf '%s\n' "$(realpath -- "$venv_name")" >> /tmp/venv_created |
| 52 | + echo -e "\n\e[32mVirtual environment '$venv_name' created successfully!\e[0m" |
| 53 | + echo "To activate it, run the following command:" |
| 54 | + echo -e "\e[33m source ~/$venv_name/bin/activate\e[0m" |
| 55 | + echo "After activating the environment, please re-run this script." |
| 56 | + cd $maxdiffusion_dir |
| 57 | + else |
| 58 | + echo "Exiting. Please upgrade your Python environment to continue." |
| 59 | + fi |
| 60 | + # Exit the script since the initial Python check failed |
| 61 | + exit 1 |
| 62 | +fi |
| 63 | +echo "Python version check passed. Continuing with script." |
| 64 | +echo "--------------------------------------------------" |
| 65 | + |
26 | 66 | (sudo bash || bash) <<'EOF' |
27 | 67 | mkdir -p /etc/needrestart/conf.d |
28 | 68 | echo '$nrconf{restart} = "a";' > /etc/needrestart/conf.d/99-noninteractive.conf |
|
0 commit comments