Merge pull request #134 from KunoiSayami/master

feat: Install script support Arch Linux
pull/140/head
undefined 3 years ago committed by GitHub
commit c315deffda
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,8 +6,14 @@ let MINIO_ACCESS_KEY = randomstring(32);
let MINIO_SECRET_KEY = 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);
const china = (cli.prompt('此服务器是否位于国内?(Y/n)') || 'y') === 'y';
const china = (cli.prompt('此服务器是否位于中国大陆?(Y/n) ') || 'y') === 'y';
const NVM_NODEJS_ORG_MIRROR = china
? 'https://mirrors.tuna.tsinghua.edu.cn/nodejs-release'
: 'https://nodejs.org/dist';
@ -26,11 +32,12 @@ const osinfoFile = fs.readfile('/etc/os-release');
const lines = osinfoFile.split('\n');
const values = {};
for (const line of lines) {
if (!line.trim()) continue;
const d = line.split('=');
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 steps = [
@ -38,24 +45,32 @@ const steps = [
init: '正在初始化安装 / Preparing',
operations: [
'mkdir -p /data/db /data/file ~/.hydro',
'apt-get -qq update',
'apt-get install -y curl wget gnupg',
Arch ? 'pacman --needed --quiet --noconfirm -Sy' : 'apt-get -qq update',
Arch ? 'pacman --needed --quiet --noconfirm -S gnupg curl' : 'apt-get install -y curl wget gnupg',
],
},
{
init: '正在安装 MongoDB / Installing MongoDB',
skip: () => fs.exist('/usr/bin/mongo'),
operations: [
() => {
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',
],
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(
'/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',
@ -81,6 +96,15 @@ const steps = [
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];
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',
],
@ -118,7 +142,7 @@ const steps = [
init: '正在安装 MinIO / Installing MinIO',
skip: () => fs.exist('/root/.hydro/env'),
operations: [
`wget ${MINIO_DOWNLOAD} -O /usr/bin/minio`,
`curl -fSL ${MINIO_DOWNLOAD} -o /usr/bin/minio`,
'chmod +x /usr/bin/minio',
() => fs.writefile(
'/root/.hydro/env',
@ -129,7 +153,7 @@ const steps = [
{
init: '正在安装编译器 / Installing compiler',
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',
],
},
{

Loading…
Cancel
Save