Skip to content

Commit 499b278

Browse files
committedMar 10, 2025
Merge branch 'easy-setup' into advance-edit
2 parents c0c483e + 8c95026 commit 499b278

File tree

6 files changed

+353
-1
lines changed

6 files changed

+353
-1
lines changed
 

‎README.md

+6
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ Handles file system operations and provides a secure bridge between the frontend
7676
cd PictoPy
7777
```
7878

79+
## Automatic Setup:
80+
```bash
81+
npm run setup
82+
```
83+
84+
## Manual Setup:
7985
1. Navigate to the frontend directory:
8086
```bash
8187
cd frontend

‎frontend/scripts/setup_env.sh

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ packages=(
2929
libwebkit2gtk-4.1-dev
3030
librsvg2-dev
3131
file
32+
libgl1-mesa-glx
3233
)
3334

3435
# check and install required packages

‎frontend/scripts/setup_win.ps1

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ $env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";"
3030
# Install Visual Studio Build Tools
3131
if (-not (Test-Path "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools")) {
3232
Write-Host "Installing Visual Studio Build Tools..." -ForegroundColor Yellow
33-
choco install visualstudio2019buildtools -y --package-parameters "--add Microsoft.VisualStudio.Workload.VCTools --includeRecommended"
33+
winget install Microsoft.VisualStudio.2022.BuildTools --force --override "--wait --passive --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621"
3434
} else {
3535
Write-Host "Visual Studio Build Tools are already installed." -ForegroundColor Green
3636
}

‎scripts/setup.js

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import { spawn } from 'child_process';
2+
import os from 'os';
3+
import path from 'path';
4+
import fs from 'fs';
5+
import { fileURLToPath } from 'url';
6+
7+
const __filename = fileURLToPath(import.meta.url);
8+
const __dirname = path.dirname(__filename);
9+
10+
const bashScript = path.join(__dirname, 'setup.sh');
11+
const psScript = path.join(__dirname, 'setup.ps1');
12+
13+
let command, args;
14+
15+
if (os.platform() === 'win32') {
16+
// On Windows, use PowerShell
17+
command = 'powershell.exe';
18+
args = ['-ExecutionPolicy', 'Bypass', '-File', psScript];
19+
} else {
20+
// On Linux/macOS, use the bash script
21+
command = bashScript;
22+
args = [];
23+
24+
// Ensure the bash script is executable; if not, set the execute permission.
25+
try {
26+
fs.accessSync(bashScript, fs.constants.X_OK);
27+
} catch (err) {
28+
console.log(`File ${bashScript} is not executable. Setting execute permission...`);
29+
fs.chmodSync(bashScript, 0o755);
30+
}
31+
}
32+
33+
const proc = spawn(command, args, { stdio: 'inherit' });
34+
35+
proc.on('error', (err) => {
36+
console.error(`Failed to start setup: ${err}`);
37+
});
38+
39+
proc.on('close', (code) => {
40+
console.log(`Setup finished with exit code ${code}`);
41+
});

‎scripts/setup.ps1

+154
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
# Check if running as Administrator
2+
$principal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
3+
if (-not $principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
4+
Write-Host "This script must be run as Administrator. Please re-run PowerShell as Administrator." -ForegroundColor Red
5+
exit 1
6+
}
7+
8+
Write-Host "Starting Windows setup..." -ForegroundColor Yellow
9+
10+
function Test-Command($command) {
11+
try { Get-Command $command -ErrorAction Stop; return $true } catch { return $false }
12+
}
13+
14+
function Install-Chocolatey {
15+
Set-ExecutionPolicy Bypass -Scope Process -Force
16+
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
17+
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
18+
}
19+
20+
# ---- Install Chocolatey if not installed ----
21+
if (-not (Test-Command choco)) {
22+
Write-Host "Chocolatey is not installed. Installing..." -ForegroundColor Yellow
23+
Install-Chocolatey
24+
} else {
25+
Write-Host "Chocolatey is already installed." -ForegroundColor Green
26+
}
27+
28+
# Refresh PATH environment variable
29+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
30+
31+
# ---- Install Visual Studio Build Tools (if not present) ----
32+
Write-Host "Installing Visual Studio Build Tools..." -ForegroundColor Yellow
33+
winget install Microsoft.VisualStudio.2022.BuildTools --force --override "--wait --passive --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.Windows11SDK.22621"
34+
35+
# ---- Check if Visual C++ Build Tools (cl.exe) are available ----
36+
$vsPath = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Tools\MSVC"
37+
if (Test-Path $vsPath) {
38+
$latestVersion = (Get-ChildItem $vsPath | Sort-Object Name -Descending | Select-Object -First 1).Name
39+
$clPath = Join-Path -Path $vsPath -ChildPath "$latestVersion\bin\Hostx64\x64\cl.exe"
40+
41+
if (Test-Path $clPath) {
42+
Write-Host "Visual C++ Build Tools found at: $clPath" -ForegroundColor Green
43+
# Add to PATH if not already there
44+
$env:Path = "$vsPath\$latestVersion\bin\Hostx64\x64;$env:Path"
45+
} else {
46+
Write-Host "Visual C++ Build Tools (cl.exe) not found." -ForegroundColor Red
47+
Write-Host "Please open the Visual Studio Installer and ensure the 'Desktop development with C++' workload is installed:" -ForegroundColor Yellow
48+
Write-Host " 1. Open the Visual Studio Installer." -ForegroundColor Yellow
49+
Write-Host " 2. Choose 'Modify' on your Visual Studio Build Tools installation." -ForegroundColor Yellow
50+
Write-Host " 3. Ensure that the 'Desktop development with C++' workload is selected." -ForegroundColor Yellow
51+
}
52+
} else {
53+
Write-Host "Visual Studio Build Tools installation path not found." -ForegroundColor Red
54+
Write-Host "Please open the Visual Studio Installer and ensure the 'Desktop development with C++' workload is installed:" -ForegroundColor Yellow
55+
Write-Host " 1. Open the Visual Studio Installer." -ForegroundColor Yellow
56+
Write-Host " 2. Choose 'Modify' on your Visual Studio Build Tools installation." -ForegroundColor Yellow
57+
Write-Host " 3. Ensure that the 'Desktop development with C++' workload is selected." -ForegroundColor Yellow
58+
}
59+
60+
# ---- Install Rust if not installed ----
61+
if (-not (Test-Command rustc)) {
62+
Write-Host "Installing Rust..." -ForegroundColor Yellow
63+
Invoke-WebRequest https://win.rustup.rs/x86_64 -OutFile rustup-init.exe
64+
.\rustup-init.exe -y
65+
Remove-Item rustup-init.exe
66+
67+
# Update PATH for Rust
68+
$env:Path = "$env:USERPROFILE\.cargo\bin;$env:Path"
69+
} else {
70+
Write-Host "Rust is already installed. Version: $(rustc --version)" -ForegroundColor Green
71+
}
72+
73+
# ---- Install Node.js if not installed ----
74+
if (-not (Test-Command node)) {
75+
Write-Host "Installing Node.js..." -ForegroundColor Yellow
76+
choco install nodejs-lts -y
77+
78+
# Refresh PATH for Node.js
79+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
80+
} else {
81+
Write-Host "Node.js is already installed. Version: $(node --version)" -ForegroundColor Green
82+
}
83+
84+
# ---- Install Python 3.12 directly (without pyenv) ----
85+
if (-not (Test-Command python) -or -not ((python --version 2>&1) -match "3\.12")) {
86+
Write-Host "Installing Python 3.12..." -ForegroundColor Yellow
87+
choco install python312 -y
88+
89+
# Refresh PATH for Python
90+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
91+
92+
# Verify Python installation
93+
$pyVersion = python --version 2>&1
94+
if ($pyVersion -match "3\.12") {
95+
Write-Host "Python 3.12 is installed. Version: $pyVersion" -ForegroundColor Green
96+
} else {
97+
Write-Host "Failed to install Python 3.12. Please check your installation." -ForegroundColor Red
98+
exit 1
99+
}
100+
} else {
101+
Write-Host "Python 3.12 is already installed. Version: $(python --version)" -ForegroundColor Green
102+
}
103+
104+
# ---- Install CMake if not installed ----
105+
if (-not (Test-Command cmake)) {
106+
Write-Host "Installing CMake..." -ForegroundColor Yellow
107+
choco install cmake -y
108+
109+
# Refresh PATH for CMake
110+
$env:Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
111+
} else {
112+
Write-Host "CMake is already installed. Version: $(cmake --version)" -ForegroundColor Green
113+
}
114+
115+
# ---- Set up the frontend ----
116+
Write-Host "Setting up frontend..." -ForegroundColor Yellow
117+
try {
118+
Set-Location .\frontend\
119+
npm install
120+
121+
Set-Location .\src-tauri\
122+
cargo build
123+
124+
Set-Location ..\..
125+
Write-Host "Frontend setup completed successfully." -ForegroundColor Green
126+
} catch {
127+
Write-Host "Error setting up frontend: $_" -ForegroundColor Red
128+
Set-Location $PSScriptRoot # Return to original directory
129+
}
130+
131+
# ---- Set up the backend using Python 3.12 ----
132+
Write-Host "Setting up backend..." -ForegroundColor Yellow
133+
try {
134+
Set-Location .\backend\
135+
136+
# Create virtual environment
137+
python -m venv venv
138+
139+
# Activate virtual environment and install dependencies
140+
.\venv\Scripts\Activate.ps1
141+
python -m pip install --upgrade pip
142+
python -m pip install -r requirements.txt
143+
deactivate
144+
145+
Set-Location ..
146+
Write-Host "Backend setup completed successfully." -ForegroundColor Green
147+
} catch {
148+
Write-Host "Error setting up backend: $_" -ForegroundColor Red
149+
Set-Location $PSScriptRoot # Return to original directory
150+
}
151+
152+
Write-Host "Windows setup complete!" -ForegroundColor Green
153+
Write-Host "Please restart your computer to ensure all changes take effect." -ForegroundColor Yellow
154+

‎scripts/setup.sh

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/bin/bash
2+
3+
# Colors for terminal output
4+
RED='\033[0;31m'
5+
GREEN='\033[0;32m'
6+
YELLOW='\033[0;33m'
7+
NC='\033[0m'
8+
9+
echo -e "${YELLOW}Starting setup...${NC}"
10+
11+
OS_TYPE=$(uname)
12+
13+
if [ "$OS_TYPE" = "Linux" ]; then
14+
if command -v apt-get &> /dev/null; then
15+
echo -e "${YELLOW}Detected Linux with apt-get. Installing dependencies...${NC}"
16+
apt-get update
17+
18+
echo "deb http://archive.ubuntu.com/ubuntu jammy main universe multiverse" | tee /etc/apt/sources.list.d/ubuntu-jammy.list
19+
echo "deb http://security.ubuntu.com/ubuntu jammy-security main universe multiverse" | tee -a /etc/apt/sources.list.d/ubuntu-jammy-security.list
20+
21+
apt-get install -y \
22+
curl build-essential libgtk-3-dev libwebkit2gtk-4.0-dev libappindicator3-dev git \
23+
wget xz-utils libssl-dev libglib2.0-dev libgirepository1.0-dev pkg-config \
24+
software-properties-common libjavascriptcoregtk-4.0-dev libjavascriptcoregtk-4.1-dev \
25+
libsoup-3.0-dev libwebkit2gtk-4.1-dev librsvg2-dev file libglib2.0-dev libgl1-mesa-glx \
26+
27+
else
28+
echo -e "${RED}apt-get not found on Linux. Please install the following dependencies manually:${NC}"
29+
echo -e " curl, build-essential, libgtk-3-dev, libwebkit2gtk-4.0-dev, libappindicator3-dev,"
30+
echo -e " wget, xz-utils, libssl-dev, libglib2.0-dev, libgirepository1.0-dev, pkg-config,"
31+
echo -e " software-properties-common, libjavascriptcoregtk-4.0-dev, libjavascriptcoregtk-4.1-dev,"
32+
echo -e " libsoup-3.0-dev, libwebkit2gtk-4.1-dev, librsvg2-dev, file, libgl1-mesa-glx"
33+
echo -e "${RED}Also please install Rust from https://rustup.rs${NC}"
34+
exit 1
35+
fi
36+
37+
elif [ "$OS_TYPE" = "Darwin" ]; then
38+
echo -e "${YELLOW}Detected macOS. Installing dependencies using Homebrew...${NC}"
39+
if ! command -v brew &> /dev/null; then
40+
echo -e "${RED}Homebrew is not installed. Please install it from https://brew.sh${NC}"
41+
exit 1
42+
fi
43+
brew update
44+
brew install \
45+
curl \
46+
git \
47+
cmake \
48+
pkg-config \
49+
gtk+3 \
50+
webkit2gtk \
51+
libappindicator \
52+
wget \
53+
xz \
54+
openssl@3 \
55+
glib \
56+
gobject-introspection \
57+
gtk-mac-integration \
58+
javascriptcoregtk \
59+
webkit2gtk-4.1 \
60+
libsoup \
61+
librsvg \
62+
gcc
63+
64+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
65+
source "$HOME/.cargo/env"
66+
67+
xcode-select --install
68+
69+
brew tap homebrew/cask
70+
brew install --cask xquartz
71+
72+
brew install gtk+3 --with-jasper --with-quartz-relocation
73+
74+
else
75+
echo -e "${RED}Unsupported OS: $OS_TYPE. Please install system dependencies manually.${NC}"
76+
exit 1
77+
fi
78+
79+
# Install pyenv if not already installed
80+
if ! command -v pyenv &> /dev/null; then
81+
echo "Installing pyenv..."
82+
curl https://pyenv.run | bash
83+
84+
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
85+
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
86+
echo 'eval "$(pyenv init --path)"' >> ~/.bashrc
87+
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
88+
89+
export PYENV_ROOT="$HOME/.pyenv"
90+
export PATH="$PYENV_ROOT/bin:$PATH"
91+
eval "$(pyenv init --path)"
92+
eval "$(pyenv init -)"
93+
fi
94+
95+
echo "Installing Python 3.12..."
96+
pyenv install 3.12.0
97+
pyenv global 3.12.0
98+
99+
python_version=$(python --version)
100+
echo "Installed: $python_version"
101+
102+
103+
# ---- Install Rust (if not already installed) ----
104+
if ! command -v rustc &> /dev/null; then
105+
echo -e "${RED}Rust is not installed. Installing...${NC}"
106+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
107+
source $HOME/.cargo/env
108+
rustup default stable
109+
rustup update
110+
else
111+
echo -e "${GREEN}Rust is installed. Version: $(rustc --version)${NC}"
112+
echo -e "${YELLOW}Updating Rust...${NC}"
113+
rustup update
114+
fi
115+
116+
# ---- Install Node.js and npm (if not installed) ----
117+
if ! command -v node &> /dev/null; then
118+
echo -e "${RED}Node.js is not installed. Installing...${NC}"
119+
if [ "$OS_TYPE" = "Linux" ]; then
120+
curl -fsSL https://deb.nodesource.com/setup_18.x | -E bash -
121+
apt-get install -y nodejs
122+
elif [ "$OS_TYPE" = "Darwin" ]; then
123+
brew install node
124+
fi
125+
else
126+
echo -e "${GREEN}Node.js is installed. Version: $(node --version)${NC}"
127+
echo -e "${GREEN}npm version: $(npm --version)${NC}"
128+
fi
129+
130+
$HOME/.cargo/env
131+
132+
# ---- Set up the backend ----
133+
echo -e "${YELLOW}Setting up backend...${NC}"
134+
cd backend
135+
python -m venv venv
136+
source venv/bin/activate
137+
pip install --upgrade pip
138+
pip install -r requirements.txt
139+
deactivate
140+
cd ..
141+
142+
# ---- Set up the frontend ----
143+
echo -e "${YELLOW}Setting up frontend...${NC}"
144+
cd frontend
145+
npm install
146+
cd src-tauri || { echo -e "${RED}src-tauri directory not found${NC}"; exit 1; }
147+
cargo build || { echo -e "${RED}Cargo build failed in src-tauri. Please check your Tauri setup.${NC}"; exit 1; }
148+
cd ../../
149+
150+
echo -e "${GREEN}Setup complete!${NC}, restart the terminal to apply changes."

0 commit comments

Comments
 (0)
Please sign in to comment.