-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.sh
More file actions
executable file
·125 lines (103 loc) · 3.22 KB
/
Copy pathsetup.sh
File metadata and controls
executable file
·125 lines (103 loc) · 3.22 KB
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env bash
#------------------------------------------------------------------------------
# Author: Clive Bostock
# Date: 16 December 2024
# Name: setup.sh
# Descr: Script to set up the application environment, including creating a
# virtual environment, checking/installing pip, installing dependencies,
# and configuring scripts. Determines Python interpreter based on the
# system.
# Optional: Unpacks Oracle Instant Client if -c option is used, and flattens.
#------------------------------------------------------------------------------
realpath() {
if command -v readlink >/dev/null 2>&1; then
readlink -f "$1"
else
cd "$(dirname "$1")" && pwd
fi
}
# ---------------------------- New Variables ----------------------------
VENV_DIR=".venv"
step=0
PROG_PATH=$(realpath "$0")
APP_HOME=$(dirname "${PROG_PATH}")
BIN_DIR="bin"
UTILS_DIR="utils"
ORACLE_CLIENT_DIR="oracle_client"
CLIENT_ZIP=""
# ---------------------------- Parse Arguments ----------------------------
usage() {
echo "Usage: $0 [-c <instant_client_zip>]"
echo " -c <zip>: Optional Oracle Instant Client ZIP to unpack"
exit 1
}
while getopts "c:h" opt; do
case "$opt" in
c) CLIENT_ZIP="$OPTARG" ;;
h) usage ;;
*) usage ;;
esac
done
# Exit on any error
set -e
pushd "${APP_HOME}"
# Step 0: Oracle Instant Client unzip (if specified)
if [[ -n "$CLIENT_ZIP" ]]; then
echo "Step 0: Unpacking Oracle Instant Client from: $CLIENT_ZIP"
if [[ ! -f "$CLIENT_ZIP" ]]; then
echo "Error: ZIP file not found: $CLIENT_ZIP"
exit 1
fi
echo "Unzipping Oracle Instant Client to: $ORACLE_CLIENT_DIR"
rm -rf "$ORACLE_CLIENT_DIR"
mkdir -p "$ORACLE_CLIENT_DIR"
TMP_DIR=$(mktemp -d)
unzip -q "$CLIENT_ZIP" -d "$TMP_DIR"
INNER_DIR=$(find "$TMP_DIR" -maxdepth 1 -type d -name "instantclient_*" | head -n 1)
if [[ -z "$INNER_DIR" ]]; then
echo "Error: Could not find instantclient_* directory in extracted zip."
rm -rf "$TMP_DIR"
exit 1
fi
mv "$INNER_DIR"/* "$ORACLE_CLIENT_DIR"
rm -rf "$TMP_DIR"
echo "Instant Client unpacked and flattened into $ORACLE_CLIENT_DIR"
fi
# Continue with environment setup
source utils/utils.env
set_python
let step=${step}+1
step_desc="Check if pip is installed"
echo "Step ${step}: ${step_desc}..."
let step=${step}+1
step_desc="Create virtual environment if it doesn't exist"
echo "Step ${step}: ${step_desc}..."
$PYTHON -m venv "$VENV_DIR"
source_venv
ensure_pip
let step=${step}+1
step_desc="Activate the virtual environment"
echo "Step ${step}: ${step_desc}..."
VENV_PYTHON="${APP_HOME}/${VENV_DIR}/${SOURCE_DIR}/python"
if [ ! -x "$VENV_PYTHON" ]; then
echo "Error: Python not found in the virtual environment. Exiting."
exit 1
fi
echo "Upgrading pip..."
"$VENV_PYTHON" -m pip install --upgrade pip
let step=${step}+1
step_desc="Perform the packages install"
echo "Step ${step}: ${step_desc}..."
"$VENV_PYTHON" -m pip install .
let step=${step}+1
step_desc="Set executable permissions for shell script"
echo "Step ${step}: ${step_desc}..."
echo "Setting executable permissions for shell scripts..."
if [ -d "$BIN_DIR" ]; then
chmod +x "$BIN_DIR"/*.sh
fi
if [ -d "$UTILS_DIR" ]; then
chmod +x "$UTILS_DIR"/*.sh
fi
echo "Setup completed successfully!"
popd