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