Skip to content

Commit a1154a1

Browse files
committed
bunch of stuff
1 parent ff1b5bc commit a1154a1

File tree

6 files changed

+220
-2
lines changed

6 files changed

+220
-2
lines changed

AutorestartAPI/index.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const childProcess = require('child_process');
2+
const axios = require('axios');
3+
4+
// im aware node has a built in wait function, i dont know the name of the module so too bad cry about it
5+
const wait = (ms) => {
6+
return new Promise((resolve) => {
7+
setTimeout(() => {
8+
resolve();
9+
}, ms);
10+
});
11+
};
12+
13+
const func = async () => {
14+
console.log('Running periodic check...');
15+
let response;
16+
let worked = true;
17+
try {
18+
response = await axios.get('https://projects.penguinmod.com/api');
19+
} catch {
20+
worked = false;
21+
}
22+
if (worked) {
23+
worked = response.status < 200 || response.status >= 300;
24+
}
25+
if (!worked) {
26+
console.log('API failed to respond properly, restarting');
27+
try {
28+
childProcess.execSync('sudo systemctl restart penguinmod-api');
29+
await wait(3000); // specially requested by josh :bleh:
30+
childProcess.execSync('sudo systemctl restart cloudflared');
31+
console.log('API should be restarted!');
32+
} catch (err) {
33+
console.error('Failed to restart API and Cloudflared!', err);
34+
}
35+
}
36+
};
37+
setInterval(func, 60000);
38+
func();

AutorestartAPI/package-lock.json

Lines changed: 105 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AutorestartAPI/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "autorestartapi",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "",
10+
"dependencies": {
11+
"axios": "^1.6.5"
12+
}
13+
}

BlocksDownloader/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PreInstalledLinkRepos/config.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"gui": "C:/Users/User/Documents/_LocalPenguinMod/penguinmod.github.io",
3+
"markdown": "C:/Users/User/Documents/_LocalPenguinMod/PenguinMod-MarkDown",
4+
"packager": "C:/Users/User/Documents/_LocalPenguinMod/PenguinMod-Packager",
5+
"audio": "C:/Users/User/Documents/_LocalPenguinMod/PenguinMod-Audio",
6+
"paint": "C:/Users/User/Documents/_LocalPenguinMod/PenguinMod-Paint",
7+
"render": "C:/Users/User/Documents/_LocalPenguinMod/PenguinMod-Render",
8+
"render-fonts": "C:/Users/User/Documents/_LocalPenguinMod/penguinmod-render-fonts",
9+
"storage": "C:/Users/User/Documents/_LocalPenguinMod/PenguinMod-Storage",
10+
"vm": "C:/Users/User/Documents/_LocalPenguinMod/PenguinMod-Vm",
11+
"entryPoints": [
12+
"gui",
13+
"packager"
14+
]
15+
}

PreInstalledLinkRepos/index.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
const fs = require('fs')
2+
const { exec } = require("child_process");
3+
const path = require('path')
4+
const conf = require('./config.json')
5+
const pmLink = /^(github:PenguinMod|git\+https:\/\/github\.com\/PenguinMod)(-Dev)?\/PenguinMod-([\w-]+)(.git)?#[\w-]+$/i
6+
const fileExists = path =>
7+
new Promise(resolve => {
8+
fs.access(path, fs.constants.R_OK | fs.constants.W_OK | fs.constants.F_OK, err => {
9+
resolve(!err)
10+
});
11+
})
12+
const handled = {}
13+
14+
const ittr = async entry => {
15+
const packagePath = path.join(conf[entry], 'package.json')
16+
const packJson = require(packagePath)
17+
const dependencies = Object.entries(Object.assign({}, packJson.dependencies, packJson.devDependencies))
18+
.filter(package => package[1].startsWith('github:PenguinMod') || package[1].startsWith('git+https://github.com/PenguinMod'))
19+
.map(package => {
20+
const match = package[1].match(pmLink)
21+
const name = match[3].toLowerCase()
22+
return [name, conf[name], package[0]]
23+
})
24+
.filter(([_, path]) => path)
25+
26+
for (const dep of dependencies) {
27+
const [name, src, module] = dep
28+
if (name === 'blocks') continue;
29+
console.log('linking', name, 'to', entry)
30+
const dest = path.join(conf[entry], 'node_modules', module)
31+
if (name === 'render-fonts') {
32+
console.log(src, dest);
33+
}
34+
fs.rmSync(dest, {
35+
recursive: true
36+
})
37+
fs.symlinkSync(src, dest)
38+
if (!handled[name]) ittr(name)
39+
}
40+
handled[entry] = true
41+
}
42+
43+
console.log('starting link...')
44+
for (const name of conf.entryPoints) {
45+
ittr(name)
46+
}
47+
console.log('finnished link...')

0 commit comments

Comments
 (0)