-
Notifications
You must be signed in to change notification settings - Fork 5
/
install-urocissa.mjs
195 lines (174 loc) · 6.13 KB
/
install-urocissa.mjs
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import os from "os";
import { execSync } from "child_process";
import { existsSync, readdirSync, copyFileSync, rmSync } from "fs";
import { resolve, join } from "path";
const args = process.argv.slice(2);
const debug = args.includes("--debug");
const update = args.includes("--update");
// Define project directories
const projectRoot = resolve();
const backendDir = join(projectRoot, "gallery-backend");
const frontendDir = join(projectRoot, "gallery-frontend");
// Helper function to execute shell commands
function runCommand(command, options = {}) {
try {
execSync(command, { stdio: "inherit", ...options });
} catch (error) {
console.error(`Error executing command: ${command}`);
process.exit(1);
}
}
// Helper function to check if a command exists
function commandExists(command) {
try {
execSync(`${command}`, { stdio: "pipe" });
return true;
} catch {
return false;
}
}
// Perform update tasks
if (update) {
console.log("Update mode enabled. Performing update tasks...");
// Step 1: Pull the latest changes
console.log("Pulling the latest changes from the repository...");
runCommand("git pull", { cwd: projectRoot });
// Step 2: Rebuild the backend
console.log("Rebuilding the backend...");
const buildCommand = debug
? "cargo build"
: "cargo build --profile dev-release";
runCommand(buildCommand, { cwd: backendDir });
// Step 3: Rebuild the frontend
console.log("Rebuilding the frontend...");
runCommand("npm run build", { cwd: frontendDir });
console.log("Update completed successfully!");
process.exit(0);
}
// Install FFmpeg
if (!commandExists("ffmpeg -version")) {
console.log("FFmpeg is not installed. Installing FFmpeg...");
if (os.platform() === "win32") {
// Windows installation: Download and extract FFmpeg
const ffmpegUrl =
"https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-essentials.zip";
const ffmpegArchiveName = "ffmpeg.zip";
let extractedDir;
try {
console.log(`Downloading FFmpeg from ${ffmpegUrl}...`);
runCommand(`curl -L -o ${ffmpegArchiveName} ${ffmpegUrl}`);
console.log("Extracting FFmpeg...");
runCommand(`tar -xf ${ffmpegArchiveName}`);
// Locate the extracted directory
extractedDir = readdirSync(".").find(
(dir) => dir.startsWith("ffmpeg-") && dir.endsWith("-essentials_build")
);
if (extractedDir) {
const ffmpegPath = resolve(join(extractedDir, "bin", "ffmpeg.exe"));
if (existsSync(ffmpegPath)) {
copyFileSync(ffmpegPath, "ffmpeg.exe");
console.log("FFmpeg setup complete!");
} else {
console.error(
"Failed to locate FFmpeg binary in the extracted directory."
);
process.exit(1);
}
} else {
console.error(
"Failed to locate the extracted FFmpeg directory. Ensure the archive was extracted properly."
);
process.exit(1);
}
} finally {
console.log("Cleaning up temporary files...");
try {
if (existsSync(ffmpegArchiveName)) {
rmSync(ffmpegArchiveName); // Delete the zip file
console.log(`${ffmpegArchiveName} removed.`);
}
if (extractedDir && existsSync(extractedDir)) {
rmSync(extractedDir, { recursive: true, force: true }); // Delete the extracted folder
console.log(`${extractedDir} removed.`);
}
} catch (cleanupError) {
console.error(`Cleanup failed: ${cleanupError.message}`);
}
}
} else if (os.platform() === "linux") {
// Linux installation: Use apt
console.log("Installing FFmpeg using apt...");
runCommand("sudo apt update");
runCommand("sudo apt install -y ffmpeg");
console.log("FFmpeg installed successfully.");
} else {
console.error(`Unsupported operating system: ${os.platform()}`);
process.exit(1);
}
} else {
console.log("FFmpeg is already installed.");
}
// Install Rust
if (!commandExists("rustup --version")) {
console.log("Rust is not installed. Installing Rust...");
if (os.platform() === "win32") {
// Windows installation
const rustInstallerUrl =
process.arch === "x64"
? "https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe"
: "https://static.rust-lang.org/rustup/dist/i686-pc-windows-msvc/rustup-init.exe";
const installerPath = "rustup-init.exe";
console.log(`Downloading Rust installer from ${rustInstallerUrl}...`);
try {
runCommand(`curl -L -o ${installerPath} ${rustInstallerUrl}`);
console.log("Running Rust installer...");
runCommand(installerPath);
} finally {
console.log("Cleaning up the installer file...");
try {
rmSync(installerPath);
console.log("Installer file removed.");
} catch (error) {
console.error(`Failed to remove the installer file: ${error.message}`);
}
}
} else if (os.platform() === "linux") {
// Linux installation
console.log("Installing Rust using rustup script...");
runCommand(
`curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh`
);
console.log(
"Rust installed successfully. You may need to restart your terminal to use Rust."
);
} else {
console.error(`Unsupported operating system: ${os.platform()}`);
process.exit(1);
}
} else {
console.log("Rust is already installed.");
}
// Configure and build the backend
console.log("Configuring backend settings...");
if (!existsSync(join(backendDir, ".env"))) {
copyFileSync(join(backendDir, ".env.default"), join(backendDir, ".env"));
}
if (!existsSync(join(backendDir, "Rocket.toml"))) {
copyFileSync(
join(backendDir, "Rocket.default.toml"),
join(backendDir, "Rocket.toml")
);
}
runCommand(debug ? "cargo build" : "cargo build --profile dev-release", {
cwd: backendDir,
});
// Configure and build the frontend
console.log("Configuring frontend settings...");
if (!existsSync(join(frontendDir, "config.ts"))) {
copyFileSync(
join(frontendDir, "config.default.ts"),
join(frontendDir, "config.ts")
);
}
runCommand("npm run build", { cwd: frontendDir });
console.log("Setup complete. Your project is ready for use!");