#! /bin/bash

py_ver=$(python3 -V) # Get the Python3 version.
pip_ver="$(pip --version)" # Get the Pip version.
pip_arr=(${pip_ver// / }) # Split the pip version information by a space. We are only interested in the version information which will be at index 1.

pip_lib=$(python3 -c 'exec("import sys; a = \"\\n\".join(sys.path).strip().split(\"\\n\")[1]; print(a)")') # Get the location of the primary Python lib. Used for determining if the pip environment is externally managed.

pip_tk=$(python3 -c 'exec("try: import tkinter; print(\"Tkinter is installed\")\nexcept ModuleNotFoundError as ex: print(\"Tkinter is not installed\")")') # Try to import the tkinter module, if an ModuleNotFoundError occurs then tkinter needs to be installed.
pip_imgtk=$(python3 -c 'exec("try: from PIL import ImageTk; print(\"ImageTK is installed\")\nexcept ImportError as ex: print(\"ImageTK is not installed\")")') # Try to import the ImageTK module, if an ImportError occurs then ImageTK needs to be installed.

./Installer "${py_ver//Python /}" "${pip_arr[1]}" "${pip_tk}" "${pip_imgtk}" "$PWD" "${pip_lib}" # Pass the collected Python/Pip version, and tkinter/imagetk install status to the Installer as arguments.

exit
