Merge pull request #134 from KunoiSayami/master

feat: Install script support Arch Linux
This commit is contained in:
undefined authored and GitHub committed 2021-05-07 20:33:34 +08:00
commit c315deffda
1 file changed
+42 -18
+42 -18
View File
@@ -6,8 +6,14 @@ 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 = `\
# load nvm env(by hydro installer)
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
`;
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';
@@ -26,11 +32,12 @@ const osinfoFile = fs.readfile('/etc/os-release');
const lines = osinfoFile.split('\n'); const lines = osinfoFile.split('\n');
const values = {}; const values = {};
for (const line of lines) { for (const line of lines) {
if (!line.trim()) continue;
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[1].startsWith('"')) values[d[0]] = d[1].substr(1, d[1].length - 2);
else values[d[0]] = d[1]; else values[d[0].toLowerCase()] = d[1];
} }
if (['ubuntu', 'arch'].includes(values.id)) log.fatal('不支持的系统'); if (!['ubuntu', 'arch'].includes(values.id)) log.fatal('不支持的系统');
const Arch = values.id === 'arch'; const Arch = values.id === 'arch';
const steps = [ const steps = [
@@ -38,24 +45,32 @@ 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
() => { ? [
fs.writefile( 'curl -fSLO https://s3.undefined.moe/hydro/arch/libcurl-openssl-1.0-7.76.0-1-x86_64.pkg.tar.zst',
'/etc/apt/sources.list.d/mongodb-org-4.4.list', 'curl -fSLO https://s3.undefined.moe/hydro/arch/mongodb-bin-4.4.5-1-x86_64.pkg.tar.zst',
`deb [ arch=amd64 ] ${MONGODB_REPO} ${values.UBUNTU_CODENAME}/mongodb-org/4.4 multiverse`, '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',
'wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -', ]
'apt-get -qq update', : [
'apt-get -q install -y mongodb-org', () => {
], fs.writefile(
'/etc/apt/sources.list.d/mongodb-org-4.4.list',
`deb [ arch=amd64 ] ${MONGODB_REPO} ${values.UBUNTU_CODENAME}/mongodb-org/4.4 multiverse`,
);
},
'wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | apt-key add -',
'apt-get -qq update',
'apt-get -q install -y mongodb-org',
],
}, },
{ {
init: '正在安装 NVM / Installing NVM', init: '正在安装 NVM / Installing NVM',
@@ -81,6 +96,15 @@ 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}`);
const rc_path = `/root/.${__env['SHELL'].endsWith('zsh') ? 'zsh' : 'bash'}rc`;
if (!fs.exist(rc_path)) {
fs.writefile(rc_path, default_nvm_source_command);
} else {
const rc_file = fs.readfile(rc_path);
if (!rc_file.includes(default_nvm_source_command)) {
fs.appendfile(default_nvm_source_command);
}
}
}, },
'npm i yarn -g', 'npm i yarn -g',
], ],
@@ -118,7 +142,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 +153,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',
], ],
}, },
{ {