feat: Install script support Arch Linux

* Fixed multiple bugs
This commit is contained in:
KunoiSayami committed 2021-05-07 20:18:51 +08:00
1 parent 34cd4d62e9
commit 8e9ec3ca23
1 file changed
+34 -9
+34 -9
View File
@@ -6,8 +6,22 @@ let MINIO_ACCESS_KEY = randomstring(32);
let MINIO_SECRET_KEY = randomstring(32); let MINIO_SECRET_KEY = randomstring(32);
let DATABASE_PASSWORD = randomstring(32); let DATABASE_PASSWORD = randomstring(32);
const default_nvm_source_command = '\n# load nvm env(by hydro installer)\nexport NVM_DIR="$HOME/.nvm"\n[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"\n';
let install_env = function () {
let rc_path = '/root/.' + (__env["SHELL"].endsWith('zsh') ? 'zsh' : 'bash') + 'rc';
if (!fs.exist(rc_path)) {
fs.writefile(rc_path, default_nvm_source_command);
return;
}
let rc_file = fs.readfile(rc_path);
if (!rc_file.includes(default_nvm_source_command)) {
fs.appendfile(default_nvm_source_command);
}
}
if (__arch !== 'amd64') log.fatal('不支持的架构 %s ,请尝试手动安装', __arch); if (__arch !== 'amd64') log.fatal('不支持的架构 %s ,请尝试手动安装', __arch);
const china = (cli.prompt('此服务器是否位于国内?(Y/n)') || 'y') === 'y'; const china = (cli.prompt('此服务器是否位于中国大陆?(Y/n) ') || 'y') === 'y';
const NVM_NODEJS_ORG_MIRROR = china const NVM_NODEJS_ORG_MIRROR = china
? 'https://mirrors.tuna.tsinghua.edu.cn/nodejs-release' ? 'https://mirrors.tuna.tsinghua.edu.cn/nodejs-release'
: 'https://nodejs.org/dist'; : 'https://nodejs.org/dist';
@@ -27,10 +41,13 @@ const lines = osinfoFile.split('\n');
const values = {}; const values = {};
for (const line of lines) { for (const line of lines) {
const d = line.split('='); const d = line.split('=');
if (d[1].startsWith('"')) values[d[0]] = d[1].substr(1, d[1].length - 2); if (d.length == 1) {
else values[d[0]] = d[1]; continue
} }
if (['ubuntu', 'arch'].includes(values.id)) log.fatal('不支持的系统'); if (d[1].startsWith('"')) values[d[0]] = d[1].substr(1, d[1].length - 2);
else values[d[0].toLowerCase()] = d[1];
}
if (!['ubuntu', 'arch'].includes(values.id)) log.fatal('不支持的系统');
const Arch = values.id === 'arch'; const Arch = values.id === 'arch';
const steps = [ const steps = [
@@ -38,14 +55,21 @@ const steps = [
init: '正在初始化安装 / Preparing', init: '正在初始化安装 / Preparing',
operations: [ operations: [
'mkdir -p /data/db /data/file ~/.hydro', 'mkdir -p /data/db /data/file ~/.hydro',
'apt-get -qq update', Arch ? 'pacman --needed --quiet --noconfirm -Sy' : 'apt-get -qq update',
'apt-get install -y curl wget gnupg', Arch ? 'pacman --needed --quiet --noconfirm -S gnupg curl' : 'apt-get install -y curl wget gnupg',
], ],
}, },
{ {
init: '正在安装 MongoDB / Installing MongoDB', init: '正在安装 MongoDB / Installing MongoDB',
skip: () => fs.exist('/usr/bin/mongo'), skip: () => fs.exist('/usr/bin/mongo'),
operations: [ operations: Arch ?
[
'curl -fSLO https://s3.undefined.moe/hydro/arch/libcurl-openssl-1.0-7.76.0-1-x86_64.pkg.tar.zst',
'curl -fSLO https://s3.undefined.moe/hydro/arch/mongodb-bin-4.4.5-1-x86_64.pkg.tar.zst',
'curl -fSLO https://s3.undefined.moe/hydro/arch/mongodb-tools-bin-100.3.1-1-x86_64.pkg.tar.zst',
'pacman --noconfirm -U libcurl-openssl-1.0-7.76.0-1-x86_64.pkg.tar.zst mongodb-bin-4.4.5-1-x86_64.pkg.tar.zst mongodb-tools-bin-100.3.1-1-x86_64.pkg.tar.zst'
] :
[
() => { () => {
fs.writefile( fs.writefile(
'/etc/apt/sources.list.d/mongodb-org-4.4.list', '/etc/apt/sources.list.d/mongodb-org-4.4.list',
@@ -81,6 +105,7 @@ const steps = [
const res = exec1('bash -c "source /root/.nvm/nvm.sh && nvm install 14"', { NVM_NODEJS_ORG_MIRROR }); const res = exec1('bash -c "source /root/.nvm/nvm.sh && nvm install 14"', { NVM_NODEJS_ORG_MIRROR });
const ver = res.output.split('Now using node v')[1].split(' ')[0]; const ver = res.output.split('Now using node v')[1].split(' ')[0];
setenv('PATH', `/root/.nvm/versions/node/v${ver}/bin:${__env.PATH}`); setenv('PATH', `/root/.nvm/versions/node/v${ver}/bin:${__env.PATH}`);
install_env();
}, },
'npm i yarn -g', 'npm i yarn -g',
], ],
@@ -118,7 +143,7 @@ const steps = [
init: '正在安装 MinIO / Installing MinIO', init: '正在安装 MinIO / Installing MinIO',
skip: () => fs.exist('/root/.hydro/env'), skip: () => fs.exist('/root/.hydro/env'),
operations: [ operations: [
`wget ${MINIO_DOWNLOAD} -O /usr/bin/minio`, `curl -fSL ${MINIO_DOWNLOAD} -o /usr/bin/minio`,
'chmod +x /usr/bin/minio', 'chmod +x /usr/bin/minio',
() => fs.writefile( () => fs.writefile(
'/root/.hydro/env', '/root/.hydro/env',
@@ -129,7 +154,7 @@ const steps = [
{ {
init: '正在安装编译器 / Installing compiler', init: '正在安装编译器 / Installing compiler',
operations: [ operations: [
'apt-get install -y g++ fp-compiler >/dev/null', Arch ? 'pacman --needed --quiet --noconfirm -S gcc fpc' : 'apt-get install -y g++ fp-compiler >/dev/null',
], ],
}, },
{ {