--- /dev/null
+#!/usr/bin/env bash
+script_afp=$(realpath "${BASH_SOURCE[0]}")
+
+# Enforce execution for this administrative tool
+if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then
+ echo "$script_afp:: This script must be executed, not sourced."
+ return 1
+fi
+
+# without this bash takes non-matching globs literally
+shopt -s nullglob
+
+# does not presume sharing or world permissions
+umask 0077
+
+# Ensure required environment variables exist
+if [[ -z "$REPO_HOME" || -z "$PROJECT" ]]; then
+ echo "Error: REPO_HOME or PROJECT variables are undefined. Please source the setup administrator first."
+ exit 1
+fi
+
+echo "Repository Home: $REPO_HOME"
+echo "Project Name: $PROJECT"
+
+# The scratchpad must exist at the top level of the project for scanning clarity
+scratchpad="$REPO_HOME"/scratchpad
+if [[ ! -d "$scratchpad" ]]; then
+ echo "Error: scratchpad directory missing at $scratchpad"
+ exit 1
+fi
+
+#--------------------------------------------------------------------------------
+# Python name/version
+#
+
+version=3.12.3
+Python_dn=Python-"$version"
+tarf="$Python_dn".tgz
+
+# Python install directory, sibling to this project
+Python_da="$(realpath "$REPO_HOME"/../)"/"$Python_dn"
+
+#--------------------------------------------------------------------------------
+
+# Verify if the requested Python version is already built
+if [[ -x "$Python_da/bin/python3" ]]; then
+ echo "Python $version is already built and installed at $Python_da."
+else
+ # Download only if the archive is absent
+ wget -nc -P "$scratchpad" https://www.python.org/ftp/python/"$version"/"$tarf"
+
+ # Extract into the scratchpad to prevent source and installation collisions
+ source_dn="$scratchpad"/Python-src-"$version"
+ mkdir -p "$source_dn"
+ tar xzf "$scratchpad"/"$tarf" -C "$source_dn" --strip-components=1
+
+ # Explicit error reporting prevents silent administrative failures
+ cd "$source_dn" || {
+ echo "Error: Failed to change directory to $source_dn. Extraction likely failed."
+ exit 1
+ }
+
+ # Configure with developer baseline (--enable-shared) required for C extensions
+ LDFLAGS="-Wl,-rpath=$Python_da/lib" ./configure --prefix="$Python_da" --enable-optimizations --enable-shared
+
+ make -j8
+ make install
+fi
+
+# Establish the versioned executable link
+link_dir="$REPO_HOME"/shared/linked-project
+mkdir -p "$link_dir"
+cd "$link_dir" || {
+ echo "Error: Failed to navigate to linked-project directory at $link_dir"
+ exit 1
+}
+
+if [[ ! -L "$Python_dn" ]]; then
+ # The depth accurately escapes linked-project, shared, and REPO_HOME
+ ln -s ../../../"$Python_dn"/ "$Python_dn"
+ echo "Successfully created symlink for $Python_dn"
+else
+ echo "The symlink for $Python_dn already exists."
+fi
+
+# --------------------------------------------------------------------------------
+# Path & Environment Configuration Plugin
+# --------------------------------------------------------------------------------
+path_sh="$REPO_HOME"/shared/tool/PATH.sh
+touch "$path_sh"
+
+# Define the cluster of variables required by the python plugin environment
+line_env="export VIRTUAL_ENV=\"\$REPO_HOME/shared/linked-project/$Python_dn\""
+line_home="export PYTHON_HOME=\"\$VIRTUAL_ENV\""
+line_unset="unset PYTHONHOME"
+line_path="PATH=\"\$VIRTUAL_ENV/bin:\$PATH\""
+
+# Append the variables sequentially if they are missing from the configuration file
+for line in "$line_env" "$line_home" "$line_unset" "$line_path"; do
+ if ! grep -Fq "$line" "$path_sh"; then
+ echo "$line" >> "$path_sh"
+ echo "Appended plugin configuration line to PATH.sh."
+ else
+ echo "Configuration line already present in PATH.sh."
+ fi
+done
+
# --------------------------------------------------------------------------------
# project definition
-# actual absolute director path for this script file
-
+# actual absolute directory path for this script file
script_adp(){
dirname "$script_afp"
}
-# assume this script is located $REPO_HOME/tools_shared/authored and work backwards
-# to get $REPO_HOME, etc.
-
+# This script is located at $REPO_HOME/shared/tool/setup.
+# Ascend two directories to discover the absolute $REPO_HOME path.
REPO_HOME=$(dirname "$(dirname "$(script_adp)")")
echo REPO_HOME "$REPO_HOME"
export REPO_HOME PROJECT PROMPT_DECOR
-# --------------------------------------------------------------------------------
-# Project wide Tool setup
-#
-
-export VIRTUAL_ENV="$REPO_HOME/shared/linked-project/Python"
-export PYTHON_HOME="$VIRTUAL_ENV"
-unset PYTHONHOME
-
-
-# --------------------------------------------------------------------------------
-# PATH
-# precedence: last defined, first discovered
-
- PATH="$REPO_HOME/shared/authored:$PATH"
- PATH="$REPO_HOME/shared/made:$PATH"
- PATH="$REPO_HOME/shared/tool:$PATH"
-
- # Remove duplicates
- clean_path() {
- PATH=$(echo ":$PATH" | awk -v RS=: -v ORS=: '!seen[$0]++' | sed 's/^://; s/:$//')
- }
- clean_path
- export PATH
-
# --------------------------------------------------------------------------------
# the following functions are provided for other scripts to use.
# at the top of files that make use of these functions put the following line:
basename "$script_afp"
}
- ## script's dirpath relative to $REPO_HOME
+ ## script's file path relative to $REPO_HOME
script_fp(){
realpath --relative-to="${REPO_HOME}" "$script_afp"
}
export -f script_adp script_fn script_dp script_fp
+# --------------------------------------------------------------------------------
+# PATH & Plugin Sourcing
+# precedence: last defined, first discovered
+
+ PATH="$REPO_HOME/shared/authored:$PATH"
+ PATH="$REPO_HOME/shared/made:$PATH"
+ PATH="$REPO_HOME/shared/tool:$PATH"
+
+ # Remove duplicates
+ clean_path() {
+ PATH=$(echo ":$PATH" | awk -v RS=: -v ORS=: '!seen[$0]++' | sed 's/^://; s/:$//')
+ }
+ clean_path
+
+ # Sourcing is wrapped in a conditional guard to prevent failure on initial bootstrapping
+ installed_tool_sh="$REPO_HOME/$(script_dp)/PATH.sh"
+ if [[ -f "$installed_tool_sh" ]]; then
+ source "$installed_tool_sh"
+ fi
+
+ export PATH
+
#--------------------------------------------------------------------------------
# used by release scripts
#
-
install_file() {
if [ "$#" -lt 3 ]; then
echo "env::install_file usage: install_file <source1> <source2> ... <target_dir> <permissions>"
if ! install -m "$perms" "$source_fp" "$target_file"; then
echo "env::install_file: Failed to install $(basename "$source_fp") to $target_dp"
return 1
- else
- echo "env::install_file: installed $(basename "$source_fp") to $target_dp with permissions $perms"
fi
done
}
if [[ -z "$ENV" ]]; then
export ENV=$(script_fp)
fi
-