-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.ps1
83 lines (72 loc) · 2.84 KB
/
setup.ps1
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
#------------------------------------------------------------------------------
# Author: Clive Bostock
# Date: 16 December 2024
# Name: setup.ps1
# Descr: Script to set up the application environment, including creating a
# virtual environment, checking/installing pip, installing dependencies,
# and configuring scripts.
#------------------------------------------------------------------------------
# Initialize step counter
$step = 0
$PROG_PATH = $MyInvocation.MyCommand.Path
$APP_HOME = Split-Path -Parent $PROG_PATH
# Change to the application directory
Push-Location -Path $APP_HOME
# Define variables
$VENV_DIR = "venv" # Change this if you want a different name for the virtual environment
$BIN_DIR = "bin" # Directory containing shell scripts
# Step 1: Check if pip is installed
$step++
$step_desc = "Check if pip is installed"
Write-Host "Step ${step}: ${step_desc}..."
if (-not (Get-Command pip -ErrorAction SilentlyContinue)) {
Write-Host "pip not found. Installing pip..."
Invoke-WebRequest -Uri "https://bootstrap.pypa.io/get-pip.py" -OutFile "get-pip.py"
python get-pip.py
Remove-Item -Path "get-pip.py" -Force
} else {
Write-Host "pip is already installed."
}
# Step 2: Create virtual environment (recreate if it exists)
$step++
$step_desc = "Create virtual environment (recreate if it exists)"
Write-Host "Step ${step}: ${step_desc}..."
if (Test-Path $VENV_DIR) {
Write-Host "Recreating virtual environment in: $VENV_DIR"
Remove-Item -Recurse -Force -Path $VENV_DIR
} else {
Write-Host "Creating virtual environment in: $VENV_DIR"
}
python -m venv $VENV_DIR
# Step 3: Activate the virtual environment
$step++
$step_desc = "Activate the virtual environment"
Write-Host "Step ${step}: ${step_desc}..."
$venvPython = Join-Path -Path $VENV_DIR -ChildPath "Scripts\python.exe"
if (-not (Test-Path $venvPython)) {
Write-Host "Error: Python not found in the virtual environment. Exiting."
Exit 1
}
Write-Host "Activating virtual environment..."
# Step 4: Upgrade pip to ensure you're using the latest version
Write-Host "Upgrading pip..."
& $venvPython -m pip install --upgrade pip
# Step 5: Perform the packages install
$step++
$step_desc = "Perform the packages install"
Write-Host "Step ${step}: ${step_desc}..."
& $venvPython -m pip install .
# Step 6: Set executable permissions for shell scripts (on non-Windows systems)
$step++
$step_desc = "Set executable permissions for shell scripts"
Write-Host "Step ${step}: ${step_desc}..."
if ($IsWindows -eq $false) {
Write-Host "Setting executable permissions for shell scripts..."
chmod +x (Join-Path -Path $BIN_DIR -ChildPath "conn_mgr.sh")
chmod +x (Join-Path -Path $BIN_DIR -ChildPath "ora_tapi.sh")
} else {
Write-Host "Skipping permission changes on Windows."
}
Write-Host "Setup completed successfully!"
# Return to the original directory
Pop-Location