mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 01:38:19 +08:00
installer: add gawk
This commit is contained in:
3 files changed
+45
-11
No files matched your search
+29
-10
@@ -7,15 +7,21 @@ import { existsSync, readFileSync, writeFileSync } from 'fs';
|
|||||||
import net from 'net';
|
import net from 'net';
|
||||||
import os, { cpus } from 'os';
|
import os, { cpus } from 'os';
|
||||||
import { createInterface } from 'readline/promises';
|
import { createInterface } from 'readline/promises';
|
||||||
import { supportsHyperlink } from 'supports-hyperlinks';
|
import supportsHyperlink from 'supports-hyperlinks';
|
||||||
|
|
||||||
const isSupported = supportsHyperlink(process.stdout);
|
const isSupported = supportsHyperlink.stdout;
|
||||||
const OSC = '\u001B]';
|
const OSC = '\u001B]';
|
||||||
const BEL = '\u0007';
|
const BEL = '\u0007';
|
||||||
const SEP = ';';
|
const SEP = ';';
|
||||||
export const link = isSupported ? (text: string, url: string) => [
|
export const link = isSupported ? (text: string, url: string) => [
|
||||||
OSC, '8', SEP, SEP, url, BEL, text, OSC, '8', SEP, SEP, BEL,
|
OSC, '8', SEP, SEP, url, BEL, text, OSC, '8', SEP, SEP, BEL,
|
||||||
].join('') : (text: string, url: string) => `${text} < ${url} > `;
|
].join('') : (text: string, url: string) => `${text} < ${url} > `;
|
||||||
|
const freemem = os.freemem();
|
||||||
|
const smallMemory = (freemem < 1024 * 1024 * 1024);
|
||||||
|
|
||||||
|
const nixInstall = (...packages: string[]) => (smallMemory
|
||||||
|
? packages.map((t) => `nix-env -iA ${t.includes('.') ? t : `nixpkgs.${t}`}`).join(' && ')
|
||||||
|
: `nix-env -iA ${packages.map((t) => (t.includes('.') ? t : `nixpkgs.${t}`)).join(' ')}`);
|
||||||
|
|
||||||
const warnings: [string, ...any[]][] = [];
|
const warnings: [string, ...any[]][] = [];
|
||||||
|
|
||||||
@@ -46,6 +52,7 @@ const locales = {
|
|||||||
'error.unsupportedArch': '不支持的架构 %s ,请尝试手动安装。',
|
'error.unsupportedArch': '不支持的架构 %s ,请尝试手动安装。',
|
||||||
'error.osreleaseNotFound': '无法获取系统版本信息(/etc/os-release 文件未找到),请尝试手动安装。',
|
'error.osreleaseNotFound': '无法获取系统版本信息(/etc/os-release 文件未找到),请尝试手动安装。',
|
||||||
'error.unsupportedOS': '不支持的操作系统 %s ,请尝试手动安装,',
|
'error.unsupportedOS': '不支持的操作系统 %s ,请尝试手动安装,',
|
||||||
|
'error.centos': 'CentOS 及其变种系统因系统内核过低,无法安装 Hydro,强烈建议使用其他系统。若确有需求,请升级 Linux 内核至 4.4+ 后再手动安装 Hydro。',
|
||||||
'install.preparing': '正在初始化安装...',
|
'install.preparing': '正在初始化安装...',
|
||||||
'install.mongodb': '正在安装 mongodb...',
|
'install.mongodb': '正在安装 mongodb...',
|
||||||
'install.createDatabaseUser': '正在创建数据库用户...',
|
'install.createDatabaseUser': '正在创建数据库用户...',
|
||||||
@@ -85,6 +92,8 @@ then restart and run the script again.`,
|
|||||||
'error.unsupportedArch': 'Unsupported architecture %s, please try to install manually.',
|
'error.unsupportedArch': 'Unsupported architecture %s, please try to install manually.',
|
||||||
'error.osreleaseNotFound': 'Unable to get system version information (/etc/os-release file not found), please try to install manually.',
|
'error.osreleaseNotFound': 'Unable to get system version information (/etc/os-release file not found), please try to install manually.',
|
||||||
'error.unsupportedOS': 'Unsupported operating system %s, please try to install manually.',
|
'error.unsupportedOS': 'Unsupported operating system %s, please try to install manually.',
|
||||||
|
'error.centos': `CentOS and its derivatives are not supported due to low system kernel versions.
|
||||||
|
It is strongly recommended to use other systems. If you really need it, please upgrade the Linux kernel to 4.4+ and manually install Hydro.`,
|
||||||
'install.preparing': 'Initializing installation...',
|
'install.preparing': 'Initializing installation...',
|
||||||
'install.mongodb': 'Installing mongodb...',
|
'install.mongodb': 'Installing mongodb...',
|
||||||
'install.createDatabaseUser': 'Creating database user...',
|
'install.createDatabaseUser': 'Creating database user...',
|
||||||
@@ -347,6 +356,18 @@ const Steps = () => [
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
async () => {
|
||||||
|
if (process.env.IGNORE_CENTOS) return;
|
||||||
|
const res = exec('yum -h');
|
||||||
|
if (res.code) return;
|
||||||
|
if (!process.argv.includes('--unsupported-centos')) {
|
||||||
|
log.warn('error.centos');
|
||||||
|
process.exit(1);
|
||||||
|
} else {
|
||||||
|
log.warn('warn.centos');
|
||||||
|
warnings.push(['warn.centos']);
|
||||||
|
}
|
||||||
|
},
|
||||||
async () => {
|
async () => {
|
||||||
if (!avx && !installAsJudge) {
|
if (!avx && !installAsJudge) {
|
||||||
log.warn('note.avx');
|
log.warn('note.avx');
|
||||||
@@ -397,9 +418,7 @@ ${nixConfBase}`);
|
|||||||
exec('nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs', { stdio: 'inherit' });
|
exec('nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs', { stdio: 'inherit' });
|
||||||
exec('nix-channel --update', { stdio: 'inherit' });
|
exec('nix-channel --update', { stdio: 'inherit' });
|
||||||
},
|
},
|
||||||
`nix-env -iA ${[
|
nixInstall('pm2', 'yarn', 'esbuild', 'bash', 'unzip', 'zip', 'diffutils', 'patch', 'screen', 'gawk'),
|
||||||
'pm2', 'yarn', 'esbuild', 'bash', 'unzip', 'zip', 'diffutils', 'patch', 'screen', 'gawk',
|
|
||||||
].map((i) => `nixpkgs.${i}`).join(' ')}`,
|
|
||||||
'yarn config set disable-self-update-check true',
|
'yarn config set disable-self-update-check true',
|
||||||
async () => {
|
async () => {
|
||||||
const rl = createInterface(process.stdin, process.stdout);
|
const rl = createInterface(process.stdin, process.stdout);
|
||||||
@@ -450,20 +469,20 @@ ${nixConfBase}`);
|
|||||||
"openssl-1.1.1z"
|
"openssl-1.1.1z"
|
||||||
];
|
];
|
||||||
}`),
|
}`),
|
||||||
`nix-env -iA hydro.mongodb${avx ? 7 : 4}${CN ? '-cn' : ''} nixpkgs.mongosh nixpkgs.mongodb-tools`,
|
nixInstall(`hydro.mongodb${avx ? 7 : 4}${CN ? '-cn' : ''}`, 'mongosh', 'mongodb-tools'),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: 'install.compiler',
|
init: 'install.compiler',
|
||||||
operations: [
|
operations: [
|
||||||
'nix-env -iA nixpkgs.gcc nixpkgs.python3',
|
nixInstall('gcc', 'python3'),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: 'install.sandbox',
|
init: 'install.sandbox',
|
||||||
skip: () => !exec('hydro-sandbox --help').code,
|
skip: () => !exec('hydro-sandbox --help').code,
|
||||||
operations: [
|
operations: [
|
||||||
'nix-env -iA nixpkgs.go-judge',
|
nixInstall('go-judge'),
|
||||||
'ln -sf $(which go-judge) /usr/local/bin/hydro-sandbox',
|
'ln -sf $(which go-judge) /usr/local/bin/hydro-sandbox',
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -472,7 +491,7 @@ ${nixConfBase}`);
|
|||||||
skip: () => installAsJudge || noCaddy || existsSync(`${process.env.HOME}/.hydro/Caddyfile`),
|
skip: () => installAsJudge || noCaddy || existsSync(`${process.env.HOME}/.hydro/Caddyfile`),
|
||||||
hidden: installAsJudge,
|
hidden: installAsJudge,
|
||||||
operations: [
|
operations: [
|
||||||
'nix-env -iA nixpkgs.caddy',
|
nixInstall('caddy'),
|
||||||
() => writeFileSync(`${process.env.HOME}/.hydro/Caddyfile`, Caddyfile),
|
() => writeFileSync(`${process.env.HOME}/.hydro/Caddyfile`, Caddyfile),
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -660,7 +679,7 @@ ${nixConfBase}`);
|
|||||||
{
|
{
|
||||||
init: 'install.postinstall',
|
init: 'install.postinstall',
|
||||||
operations: [
|
operations: [
|
||||||
'echo "layout=1" >/etc/HYDRO_INSTALLER',
|
'echo "layout=2" >/etc/HYDRO_INSTALLER',
|
||||||
'echo "vm.swappiness = 1" >>/etc/sysctl.conf',
|
'echo "vm.swappiness = 1" >>/etc/sysctl.conf',
|
||||||
'sysctl -p',
|
'sysctl -p',
|
||||||
// dont retry this as it usually fails
|
// dont retry this as it usually fails
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { execSync } from 'child_process';
|
||||||
|
import fs from 'fs';
|
||||||
import { Context, Schema, UserModel } from 'hydrooj';
|
import { Context, Schema, UserModel } from 'hydrooj';
|
||||||
import { startPerformanceTest } from './performance-test';
|
import { startPerformanceTest } from './performance-test';
|
||||||
|
|
||||||
@@ -7,4 +9,17 @@ export async function apply(ctx: Context) {
|
|||||||
if (that.session.uid === 2) await UserModel.setSuperAdmin(2);
|
if (that.session.uid === 2) await UserModel.setSuperAdmin(2);
|
||||||
});
|
});
|
||||||
ctx.addScript('performance-test', 'test', Schema.object({ enable5: Schema.boolean().default(false) }), startPerformanceTest);
|
ctx.addScript('performance-test', 'test', Schema.object({ enable5: Schema.boolean().default(false) }), startPerformanceTest);
|
||||||
|
const installerFileExists = fs.existsSync('/etc/HYDRO_INSTALLER');
|
||||||
|
if (!installerFileExists) return;
|
||||||
|
const content = fs.readFileSync('/etc/HYDRO_INSTALLER', 'utf-8');
|
||||||
|
const val: Record<string, string> = {};
|
||||||
|
for (const line of content.split('\n')) {
|
||||||
|
const [key, value] = line.split('=').map((i) => i?.trim());
|
||||||
|
if (key && value) val[key] = value;
|
||||||
|
}
|
||||||
|
if (val.layout === '1') {
|
||||||
|
execSync('nix-env -iA nixpkgs.gawk');
|
||||||
|
execSync('pm2 restart hydro-sandbox');
|
||||||
|
fs.writeFileSync('/etc/HYDRO_INSTALLER', content.replace('layout=1', 'layout=2'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
{
|
{
|
||||||
"name": "@hydrooj/a11y",
|
"name": "@hydrooj/a11y",
|
||||||
"version": "0.0.2"
|
"version": "0.0.3"
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user