Update versioninfo.py
[PyUPC-EAN.git] / setupalt
blobf28a7aef93754f8f25acc27e5cce27e624a1ccc8
1 #!/usr/bin/env bash
3 # Set default command paths if not already defined
4 RMFILE="${RMFILE:-$(command -v rm) -rf}"
5 PYTHON="${PYTHON:-$(command -v python)}"
6 MKDIR="${MKDIR:-$(command -v mkdir) -p}"
7 INSTALL="${INSTALL:-$(command -v install) -v -c}"
9 # Determine the Python library installation path
10 PREFIX="${PREFIX:-$(${PYTHON} -c 'from distutils.sysconfig import get_python_lib; print(get_python_lib())')}"
12 # Function to execute a command and print it
13 run_command() {
14 echo "$1"
15 eval "$1"
18 # Function to create directory if it doesn't exist
19 ensure_directory() {
20 [ -z "$1" ] || run_command "${MKDIR} \"$1\""
23 # Function to install Python files
24 install_python_file() {
25 run_command "${INSTALL} \"$1\" \"$2\""
28 # Function to compile Python files
29 compile_python_files() {
30 run_command "${PYTHON} -m compileall \"$PREFIX/$1\""
31 run_command "${PYTHON} -O -m compileall \"$PREFIX/$1\""
34 # Main installation process
35 main() {
36 local OLDCWD="$(pwd)"
38 echo "Installing Python Module upcean"
40 # Check for required Python modules
41 for module in PIL readline; do
42 if ! ${PYTHON} -c "import $module" &>/dev/null; then
43 echo "Required Python module '$module' not found."
44 exit 1
46 done
48 # Create installation directory if necessary
49 ensure_directory "$PREFIX/upcean"
51 # Copy files to the target directory
52 for file in ./upcean/*; do
53 install_python_file "$file" "$PREFIX/upcean/$(basename "$file")"
54 done
56 # Compile the installed files
57 run_command "cd \"$PREFIX\""
58 compile_python_files "upcean"
59 run_command "cd \"$OLDCWD\""
61 echo "Finished installing Python Module upcean"
64 # Execute main installation function
65 main