mirror of
https://gitcode.com/gh_mirrors/hy/Hydro.git
synced 2026-10-20 09:46:28 +08:00
install: use $HOME variable
This commit is contained in:
1 parent
c21adfb99a
commit
ba5950472c
2 files changed
+12
-19
No files matched your search
+11
-18
@@ -63,7 +63,7 @@ log.fatal = ((orig) => (str, ...args) => orig(locales[locale][str] || str, ...ar
|
|||||||
|
|
||||||
if (__user !== 'root') log.fatal('error.rootRequired');
|
if (__user !== 'root') log.fatal('error.rootRequired');
|
||||||
if (__arch !== 'amd64') log.fatal('error.unsupportedArch', __arch);
|
if (__arch !== 'amd64') log.fatal('error.unsupportedArch', __arch);
|
||||||
const dev = !!cli.get('dev');
|
if (!__env.HOME) log.fatal('$HOME not found');
|
||||||
if (!fs.exist('/etc/os-release')) log.fatal('error.osreleaseNotFound');
|
if (!fs.exist('/etc/os-release')) log.fatal('error.osreleaseNotFound');
|
||||||
const osinfoFile = fs.readfile('/etc/os-release');
|
const osinfoFile = fs.readfile('/etc/os-release');
|
||||||
const lines = osinfoFile.split('\n');
|
const lines = osinfoFile.split('\n');
|
||||||
@@ -159,7 +159,7 @@ const steps = [
|
|||||||
'mkdir -p /data/db /data/file ~/.hydro',
|
'mkdir -p /data/db /data/file ~/.hydro',
|
||||||
'bash -c "bash <(curl https://hydro.ac/nix.sh)"',
|
'bash -c "bash <(curl https://hydro.ac/nix.sh)"',
|
||||||
() => {
|
() => {
|
||||||
setenv('PATH', `/root/.nix-profile/bin:${__env.PATH}`);
|
setenv('PATH', `${__env.HOME}/.nix-profile/bin:${__env.PATH}`);
|
||||||
},
|
},
|
||||||
'nix-env -iA nixpkgs.unzip nixpkgs.zip nixpkgs.diffutils',
|
'nix-env -iA nixpkgs.unzip nixpkgs.zip nixpkgs.diffutils',
|
||||||
],
|
],
|
||||||
@@ -182,7 +182,7 @@ apt-get -qq update && apt-get -q install -y mongodb-org`, { retry: true }],
|
|||||||
init: 'install.nvm',
|
init: 'install.nvm',
|
||||||
skip: () => {
|
skip: () => {
|
||||||
if (!apt) return true;
|
if (!apt) return true;
|
||||||
const nvm = fs.exist('/root/.nvm');
|
const nvm = !exec('nvm -v').code;
|
||||||
const node = !exec('node -v').code;
|
const node = !exec('node -v').code;
|
||||||
if (node && !nvm) log.warn('error.nodeWithoutNVMDetected');
|
if (node && !nvm) log.warn('error.nodeWithoutNVMDetected');
|
||||||
return nvm || node;
|
return nvm || node;
|
||||||
@@ -203,7 +203,7 @@ apt-get -qq update && apt-get -q install -y mongodb-org`, { retry: true }],
|
|||||||
skip: () => !exec('node -v').code && !exec('yarn -v').code,
|
skip: () => !exec('node -v').code && !exec('yarn -v').code,
|
||||||
operations: apt ? [
|
operations: apt ? [
|
||||||
() => {
|
() => {
|
||||||
const res = exec1('bash -c "source /root/.nvm/nvm.sh && nvm install 14"', {
|
const res = exec1(`bash -c "source ${__env.HOME}/.nvm/nvm.sh && nvm install 14"`, {
|
||||||
NVM_NODEJS_ORG_MIRROR: getMirror('node'),
|
NVM_NODEJS_ORG_MIRROR: getMirror('node'),
|
||||||
});
|
});
|
||||||
let ver;
|
let ver;
|
||||||
@@ -213,9 +213,9 @@ apt-get -qq update && apt-get -q install -y mongodb-org`, { retry: true }],
|
|||||||
log.error('error.nodeVersionParseFail');
|
log.error('error.nodeVersionParseFail');
|
||||||
return 'retry';
|
return 'retry';
|
||||||
}
|
}
|
||||||
setenv('PATH', `/root/.nvm/versions/node/v${ver}/bin:${__env.PATH}`);
|
setenv('PATH', `${__env.HOME}/.nvm/versions/node/v${ver}/bin:${__env.PATH}`);
|
||||||
const shell = __env.SHELL ? __env.SHELL.split('/') : ['bash'];
|
const shell = __env.SHELL ? __env.SHELL.split('/') : ['bash'];
|
||||||
const rc = `/root/.${shell[shell.length - 1]}rc`;
|
const rc = `${__env.HOME}/.${shell[shell.length - 1]}rc`;
|
||||||
if (!fs.exist(rc)) fs.writefile(rc, source_nvm);
|
if (!fs.exist(rc)) fs.writefile(rc, source_nvm);
|
||||||
else {
|
else {
|
||||||
const file = fs.readfile(rc);
|
const file = fs.readfile(rc);
|
||||||
@@ -262,20 +262,13 @@ apt-get -qq update && apt-get -q install -y mongodb-org`, { retry: true }],
|
|||||||
{
|
{
|
||||||
init: 'install.hydro',
|
init: 'install.hydro',
|
||||||
operations: [
|
operations: [
|
||||||
...(dev
|
['yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge', { retry: true }],
|
||||||
? [
|
() => fs.writefile(`${__env.HOME}/.hydro/addon.json`, '["@hydrooj/ui-default","@hydrooj/hydrojudge"]'),
|
||||||
['rm -rf /root/Hydro && git clone https://github.com/hydro-dev/Hydro.git /root/Hydro', { retry: true }],
|
|
||||||
['cd /root/Hydro && yarn', { retry: true }],
|
|
||||||
'cd /root/Hydro && yarn build:ui',
|
|
||||||
['yarn global add npx', { retry: true }],
|
|
||||||
]
|
|
||||||
: [['yarn global add hydrooj @hydrooj/ui-default @hydrooj/hydrojudge', { retry: true }]]),
|
|
||||||
() => fs.writefile('/root/.hydro/addon.json', '["@hydrooj/ui-default","@hydrooj/hydrojudge"]'),
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
init: 'install.createDatabaseUser',
|
init: 'install.createDatabaseUser',
|
||||||
skip: () => fs.exist('/root/.hydro/config.json'),
|
skip: () => fs.exist(`${__env.HOME}/.hydro/config.json`),
|
||||||
operations: [
|
operations: [
|
||||||
'pm2 start mongod',
|
'pm2 start mongod',
|
||||||
() => sleep(5000),
|
() => sleep(5000),
|
||||||
@@ -286,7 +279,7 @@ apt-get -qq update && apt-get -q install -y mongodb-org`, { retry: true }],
|
|||||||
roles: [{ role: 'readWrite', db: 'hydro' }]
|
roles: [{ role: 'readWrite', db: 'hydro' }]
|
||||||
})`),
|
})`),
|
||||||
'mongo 127.0.0.1:27017/hydro /tmp/createUser.js',
|
'mongo 127.0.0.1:27017/hydro /tmp/createUser.js',
|
||||||
() => fs.writefile('/root/.hydro/config.json', JSON.stringify({
|
() => fs.writefile(`${__env.HOME}/.hydro/config.json`, JSON.stringify({
|
||||||
host: '127.0.0.1',
|
host: '127.0.0.1',
|
||||||
port: 27017,
|
port: 27017,
|
||||||
name: 'hydro',
|
name: 'hydro',
|
||||||
@@ -337,7 +330,7 @@ apt-get -qq update && apt-get -q install -y mongodb-org`, { retry: true }],
|
|||||||
init: 'install.done',
|
init: 'install.done',
|
||||||
operations: [
|
operations: [
|
||||||
() => {
|
() => {
|
||||||
DATABASE_PASSWORD = loadconfig('/root/.hydro/config.json').password;
|
DATABASE_PASSWORD = loadconfig(`${__env.HOME}/.hydro/config.json`).password;
|
||||||
},
|
},
|
||||||
() => log.info('extra.restartTerm'),
|
() => log.info('extra.restartTerm'),
|
||||||
() => log.info('extra.dbUser'),
|
() => log.info('extra.dbUser'),
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ if (!argv.args[0] || argv.args[0] === 'cli') {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (operation === 'create') {
|
if (operation === 'create') {
|
||||||
name ||= '/root/addon';
|
name ||= `${os.homedir()}/addon`;
|
||||||
fs.mkdirSync(name);
|
fs.mkdirSync(name);
|
||||||
child.execSync('yarn init -y', { cwd: name });
|
child.execSync('yarn init -y', { cwd: name });
|
||||||
fs.mkdirSync(`${name}/templates`);
|
fs.mkdirSync(`${name}/templates`);
|
||||||
|
|||||||
Reference in new issue
Block a user