Skip to content

Commit f183035

Browse files
committed
Install: Add generated shell scripts for all platforms
1 parent 2522363 commit f183035

10 files changed

Lines changed: 1677 additions & 0 deletions
Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# MHKiT-MATLAB Step 1: Conda Detection
2+
# Generated from template - DO NOT EDIT DIRECTLY
3+
# Report issues: https://github.com/MHKiT-Software/MHKiT-MATLAB/issues/new
4+
5+
$ErrorActionPreference = "Stop" # Exit on any error
6+
7+
# Script configuration
8+
$CONDA_ENV_NAME = "mhkit-matlab-env"
9+
$PYTHON_VERSION = "3.11"
10+
$MHKIT_VERSION = "0.9"
11+
$GITHUB_ISSUES = "https://github.com/MHKiT-Software/MHKiT-MATLAB/issues/new"
12+
13+
# Logging functions
14+
function Write-Info {
15+
param([string]$Message)
16+
Write-Host "[INFO] $Message" -ForegroundColor Green
17+
}
18+
19+
function Write-Success {
20+
param([string]$Message)
21+
Write-Host "[SUCCESS] $Message" -ForegroundColor Cyan
22+
}
23+
24+
function Write-Warning {
25+
param([string]$Message)
26+
Write-Host "[WARNING] $Message" -ForegroundColor Yellow
27+
}
28+
29+
function Write-Error {
30+
param([string]$Message)
31+
Write-Host "[ERROR] $Message" -ForegroundColor Red
32+
Write-Host "[ERROR] Please report this issue: $GITHUB_ISSUES" -ForegroundColor Red
33+
}
34+
35+
# Function to test if a conda installation works
36+
function Test-Conda {
37+
param([string]$CondaPath)
38+
39+
Write-Info "Testing conda at: $CondaPath"
40+
41+
# Test if the conda executable exists
42+
if (Test-Path $CondaPath) {
43+
try {
44+
# Test if conda info works (this is the most reliable test)
45+
$null = & "$CondaPath" info 2>$null
46+
$condaVersion = & "$CondaPath" --version 2>$null
47+
$condaLocation = & "$CondaPath" info --base 2>$null
48+
Write-Success "Working conda found!"
49+
Write-Info " Version: $condaVersion"
50+
Write-Info " Location: $condaLocation"
51+
return $true
52+
} catch {
53+
Write-Warning "Conda executable found but 'conda info' failed"
54+
return $false
55+
}
56+
} else {
57+
return $false
58+
}
59+
}
60+
61+
# OS and Architecture Detection
62+
$OSType = "Windows"
63+
$ArchType = $env:PROCESSOR_ARCHITECTURE
64+
# Function to check if conda is available
65+
function Find-Conda {
66+
Write-Info "Starting comprehensive conda detection..."
67+
68+
# Step 1: Check if conda is already in PATH and working
69+
try {
70+
$condaCmd = Get-Command conda -ErrorAction SilentlyContinue
71+
if ($condaCmd) {
72+
Write-Info "Found conda in PATH"
73+
if (Test-Conda $condaCmd.Source) {
74+
Write-Output "CONDA_DETECTED=true"
75+
Write-Output "CONDA_PATH=$($condaCmd.Source)"
76+
return
77+
} else {
78+
Write-Warning "Conda in PATH is not working properly"
79+
}
80+
}
81+
} catch {
82+
# Continue to other detection methods
83+
}
84+
85+
# Step 2: Check environment variables
86+
$envValue = [Environment]::GetEnvironmentVariable("CONDA_EXE")
87+
if ($envValue) {
88+
Write-Info "Checking environment variable CONDA_EXE: $envValue"
89+
$condaFromEnv = ""
90+
if ("CONDA_EXE" -eq "CONDA_EXE") {
91+
$condaFromEnv = $envValue
92+
} elseif ("CONDA_EXE" -eq "CONDA_PREFIX") {
93+
$condaFromEnv = Join-Path $envValue "Scripts\conda.exe"
94+
}
95+
96+
if ($condaFromEnv -and (Test-Conda $condaFromEnv)) {
97+
Write-Output "CONDA_DETECTED=true"
98+
Write-Output "CONDA_PATH=$condaFromEnv"
99+
return
100+
}
101+
}
102+
$envValue = [Environment]::GetEnvironmentVariable("CONDA_PREFIX")
103+
if ($envValue) {
104+
Write-Info "Checking environment variable CONDA_PREFIX: $envValue"
105+
$condaFromEnv = ""
106+
if ("CONDA_PREFIX" -eq "CONDA_EXE") {
107+
$condaFromEnv = $envValue
108+
} elseif ("CONDA_PREFIX" -eq "CONDA_PREFIX") {
109+
$condaFromEnv = Join-Path $envValue "Scripts\conda.exe"
110+
}
111+
112+
if ($condaFromEnv -and (Test-Conda $condaFromEnv)) {
113+
Write-Output "CONDA_DETECTED=true"
114+
Write-Output "CONDA_PATH=$condaFromEnv"
115+
return
116+
}
117+
}
118+
119+
# Step 3: Check all common installation paths systematically
120+
Write-Info "Checking common conda installation paths..."
121+
$pathsToCheck = @(
122+
[Environment]::ExpandEnvironmentVariables("%USERPROFILE%\miniconda3\Scripts\conda.exe"),
123+
[Environment]::ExpandEnvironmentVariables("%USERPROFILE%\miniconda3\condabin\conda.bat"),
124+
[Environment]::ExpandEnvironmentVariables("%USERPROFILE%\Miniconda3\Scripts\conda.exe"),
125+
[Environment]::ExpandEnvironmentVariables("%USERPROFILE%\Anaconda3\Scripts\conda.exe"),
126+
[Environment]::ExpandEnvironmentVariables("%USERPROFILE%\anaconda3\Scripts\conda.exe"),
127+
[Environment]::ExpandEnvironmentVariables("C:\ProgramData\Miniconda3\Scripts\conda.exe"),
128+
[Environment]::ExpandEnvironmentVariables("C:\ProgramData\Anaconda3\Scripts\conda.exe"),
129+
[Environment]::ExpandEnvironmentVariables("C:\tools\miniconda3\Scripts\conda.exe"),
130+
[Environment]::ExpandEnvironmentVariables("C:\tools\Miniconda3\Scripts\conda.exe"),
131+
[Environment]::ExpandEnvironmentVariables("%LOCALAPPDATA%\Continuum\miniconda3\Scripts\conda.exe"),
132+
[Environment]::ExpandEnvironmentVariables("%LOCALAPPDATA%\Continuum\anaconda3\Scripts\conda.exe")
133+
)
134+
135+
foreach ($path in $pathsToCheck) {
136+
if (Test-Conda $path) {
137+
Write-Output "CONDA_DETECTED=true"
138+
Write-Output "CONDA_PATH=$path"
139+
return
140+
}
141+
}
142+
143+
Write-Info "No working conda installation found"
144+
Write-Output "CONDA_DETECTED=false"
145+
}
146+
147+
# Main execution
148+
function Main {
149+
Write-Info "Step 1: Detecting conda installation..."
150+
Find-Conda
151+
}
152+
153+
# Run main function
154+
Main
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
#!/bin/bash
2+
3+
# MHKiT-MATLAB Step 1: Conda Detection
4+
# Generated from template - DO NOT EDIT DIRECTLY
5+
# Report issues: https://github.com/MHKiT-Software/MHKiT-MATLAB/issues/new
6+
7+
set -e # Exit on any error
8+
9+
# Script configuration
10+
CONDA_ENV_NAME="mhkit-matlab-env"
11+
PYTHON_VERSION="3.11"
12+
MHKIT_VERSION="0.9"
13+
GITHUB_ISSUES="https://github.com/MHKiT-Software/MHKiT-MATLAB/issues/new"
14+
15+
# Logging functions
16+
log_info() {
17+
echo "[INFO] $1"
18+
}
19+
20+
log_success() {
21+
echo "[SUCCESS] $1"
22+
}
23+
24+
log_warning() {
25+
echo "[WARNING] $1"
26+
}
27+
28+
log_error() {
29+
echo "[ERROR] $1"
30+
echo "[ERROR] Please report this issue: $GITHUB_ISSUES"
31+
}
32+
33+
# Function to expand path with environment variables and ~
34+
expand_path() {
35+
local path="$1"
36+
# Expand ~ to $HOME
37+
path="${path/#\~/$HOME}"
38+
# Expand environment variables
39+
path=$(eval echo "$path")
40+
echo "$path"
41+
}
42+
43+
# Function to test if a conda installation works
44+
test_conda_installation() {
45+
local conda_path="$1"
46+
log_info "Testing conda at: $conda_path"
47+
48+
# Test if the conda executable exists and is executable
49+
if [[ -x "$conda_path" ]]; then
50+
# Test if conda info works (this is the most reliable test)
51+
if "$conda_path" info >/dev/null 2>&1; then
52+
local conda_version=$("$conda_path" --version 2>/dev/null || echo "unknown")
53+
local conda_location=$("$conda_path" info --base 2>/dev/null || echo "unknown")
54+
log_success "Working conda found!"
55+
log_info " Version: $conda_version"
56+
log_info " Location: $conda_location"
57+
return 0
58+
else
59+
log_warning "Conda executable found but 'conda info' failed"
60+
return 1
61+
fi
62+
else
63+
return 1
64+
fi
65+
}
66+
67+
# OS Detection
68+
OS_TYPE=$(uname)
69+
ARCH_TYPE=$(uname -m)
70+
# Function to check if conda is available
71+
detect_conda() {
72+
log_info "Starting comprehensive conda detection..."
73+
74+
# Step 1: Check if conda is already in PATH and working
75+
if command -v conda >/dev/null 2>&1; then
76+
log_info "Found conda in PATH"
77+
if test_conda_installation "$(command -v conda)"; then
78+
echo "CONDA_DETECTED=true"
79+
echo "CONDA_PATH=$(command -v conda)"
80+
return 0
81+
else
82+
log_warning "Conda in PATH is not working properly"
83+
fi
84+
fi
85+
86+
# Step 2: Check environment variables
87+
if [[ -n "$${CONDA_EXE:-}" ]]; then
88+
log_info "Checking environment variable CONDA_EXE: $${CONDA_EXE}"
89+
local conda_from_env=""
90+
if [[ "CONDA_EXE" == "CONDA_EXE" ]]; then
91+
conda_from_env="$${CONDA_EXE}"
92+
elif [[ "CONDA_EXE" == "CONDA_PREFIX" ]]; then
93+
conda_from_env="$${CONDA_EXE}/bin/conda"
94+
fi
95+
96+
if [[ -n "$conda_from_env" ]]; then
97+
conda_from_env=$(expand_path "$conda_from_env")
98+
if test_conda_installation "$conda_from_env"; then
99+
echo "CONDA_DETECTED=true"
100+
echo "CONDA_PATH=$conda_from_env"
101+
return 0
102+
fi
103+
fi
104+
fi
105+
if [[ -n "$${CONDA_PREFIX:-}" ]]; then
106+
log_info "Checking environment variable CONDA_PREFIX: $${CONDA_PREFIX}"
107+
local conda_from_env=""
108+
if [[ "CONDA_PREFIX" == "CONDA_EXE" ]]; then
109+
conda_from_env="$${CONDA_PREFIX}"
110+
elif [[ "CONDA_PREFIX" == "CONDA_PREFIX" ]]; then
111+
conda_from_env="$${CONDA_PREFIX}/bin/conda"
112+
fi
113+
114+
if [[ -n "$conda_from_env" ]]; then
115+
conda_from_env=$(expand_path "$conda_from_env")
116+
if test_conda_installation "$conda_from_env"; then
117+
echo "CONDA_DETECTED=true"
118+
echo "CONDA_PATH=$conda_from_env"
119+
return 0
120+
fi
121+
fi
122+
fi
123+
124+
# Step 3: Check all common installation paths systematically
125+
log_info "Checking common conda installation paths..."
126+
local paths_to_check=(
127+
"~/miniconda3/bin/conda"
128+
"~/miniconda3/condabin/conda"
129+
"~/anaconda3/bin/conda"
130+
"~/anaconda3/condabin/conda"
131+
"/opt/miniconda3/bin/conda"
132+
"/opt/miniconda3/condabin/conda"
133+
"/opt/anaconda3/bin/conda"
134+
"/opt/anaconda3/condabin/conda"
135+
"/usr/local/miniconda3/bin/conda"
136+
"/usr/local/miniconda3/condabin/conda"
137+
"/usr/local/anaconda3/bin/conda"
138+
"/usr/local/anaconda3/condabin/conda"
139+
"/usr/bin/conda"
140+
"/usr/local/bin/conda"
141+
"~/.local/bin/conda"
142+
"/opt/homebrew/bin/conda"
143+
"/opt/homebrew/condabin/conda"
144+
"/usr/local/Caskroom/miniconda/base/bin/conda"
145+
"/usr/local/Caskroom/miniconda/base/condabin/conda"
146+
)
147+
148+
for path in "${paths_to_check[@]}"; do
149+
local expanded_path=$(expand_path "$path")
150+
if test_conda_installation "$expanded_path"; then
151+
echo "CONDA_DETECTED=true"
152+
echo "CONDA_PATH=$expanded_path"
153+
return 0
154+
fi
155+
done
156+
157+
log_info "No working conda installation found"
158+
echo "CONDA_DETECTED=false"
159+
return 1
160+
}
161+
162+
# Main execution
163+
main() {
164+
log_info "Step 1: Detecting conda installation..."
165+
detect_conda
166+
}
167+
168+
# Run main function
169+
main "$@"

0 commit comments

Comments
 (0)