@@ -133,6 +133,7 @@ async function setupQuestionnaire (is_docker, db) {
|
|||||||
consola.warn(`"${p}" does not exists, trying to create it`)
|
consola.warn(`"${p}" does not exists, trying to create it`)
|
||||||
try {
|
try {
|
||||||
mkdirp.sync(p)
|
mkdirp.sync(p)
|
||||||
|
consola.info(`${p} succesfully created`)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(String(e))
|
console.error(String(e))
|
||||||
return false
|
return false
|
||||||
@@ -144,7 +145,7 @@ async function setupQuestionnaire (is_docker, db) {
|
|||||||
}
|
}
|
||||||
questions.push({
|
questions.push({
|
||||||
name: 'admin.email',
|
name: 'admin.email',
|
||||||
message: `Admin email (a first user with this username will be created)`,
|
message: 'Admin email (a first user with this username will be created, also used as sender address)',
|
||||||
default: options => {
|
default: options => {
|
||||||
const baseurl = new url.URL(options.baseurl)
|
const baseurl = new url.URL(options.baseurl)
|
||||||
return (
|
return (
|
||||||
@@ -161,24 +162,66 @@ async function setupQuestionnaire (is_docker, db) {
|
|||||||
validate: notEmpty
|
validate: notEmpty
|
||||||
})
|
})
|
||||||
|
|
||||||
|
questions.push({
|
||||||
|
name: 'smtp_type',
|
||||||
|
message: 'How should we send the emails ?',
|
||||||
|
type: 'list',
|
||||||
|
choices: ['sendmail', 'SMTP']
|
||||||
|
})
|
||||||
|
|
||||||
|
questions.push({
|
||||||
|
name: 'smtp.path',
|
||||||
|
message: 'Where sendmail binary is ?',
|
||||||
|
default: '/usr/sbin/sendmail',
|
||||||
|
when: answers => answers.smtp_type === 'sendmail',
|
||||||
|
validate: sendmail_path => sendmail_path.length > 0 && fs.existsSync(path.resolve(sendmail_path))
|
||||||
|
})
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
name: 'smtp.host',
|
name: 'smtp.host',
|
||||||
message: 'SMTP Host',
|
message: 'SMTP Host',
|
||||||
validate: notEmpty
|
default: 'localhost',
|
||||||
|
validate: notEmpty,
|
||||||
|
when: answers => answers.smtp_type !== 'sendmail'
|
||||||
|
})
|
||||||
|
|
||||||
|
questions.push({
|
||||||
|
name: 'smtp.secure',
|
||||||
|
message: 'Does SMTP server support TLS?',
|
||||||
|
when: answers => answers.smtp_type !== 'sendmail' && !['localhost', '127.0.0.1'].includes(answers.smtp.host),
|
||||||
|
default: true,
|
||||||
|
type: 'confirm'
|
||||||
|
})
|
||||||
|
|
||||||
|
questions.push({
|
||||||
|
name: 'smtp.port',
|
||||||
|
message: 'SMTP Port',
|
||||||
|
default: answers => ['localhost', '127.0.0.1'].includes(answers.smtp.host) ? 25 : (answers.smtp.secure ? 465 : 587),
|
||||||
|
when: answers => answers.smtp_type !== 'sendmail'
|
||||||
|
})
|
||||||
|
|
||||||
|
questions.push({
|
||||||
|
name: 'smtp_need_auth',
|
||||||
|
message: 'is SMTP authentication needed?',
|
||||||
|
type: 'confirm',
|
||||||
|
default: answers => !['localhost', '127.0.0.1'].includes(answers.smtp.host),
|
||||||
|
when: answers => answers.smtp_type !== 'sendmail'
|
||||||
})
|
})
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
name: 'smtp.auth.user',
|
name: 'smtp.auth.user',
|
||||||
message: 'SMTP User',
|
message: 'SMTP User',
|
||||||
validate: notEmpty,
|
validate: notEmpty,
|
||||||
default: answers => answers.admin.email
|
default: answers => answers.admin.email,
|
||||||
|
when: answers => answers.smtp_type !== 'sendmail' && answers.smtp_need_auth
|
||||||
})
|
})
|
||||||
|
|
||||||
questions.push({
|
questions.push({
|
||||||
name: 'smtp.auth.pass',
|
name: 'smtp.auth.pass',
|
||||||
message: 'SMTP Password',
|
message: 'SMTP Password',
|
||||||
type: 'password',
|
type: 'password',
|
||||||
validate: notEmpty
|
validate: notEmpty,
|
||||||
|
when: answers => answers.smtp_type !== 'sendmail' && answers.smtp_need_auth
|
||||||
})
|
})
|
||||||
|
|
||||||
const answers = await inquirer.prompt(questions)
|
const answers = await inquirer.prompt(questions)
|
||||||
@@ -243,7 +286,7 @@ If this is your first run use 'gancio setup --config <CONFIG_FILE.json>' `)
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function setup (options) {
|
async function setup (options) {
|
||||||
consola.info(`You're going to setup gancio on this machine.`)
|
consola.info('You\'re going to setup gancio on this machine.')
|
||||||
const config = await setupQuestionnaire(options.docker, options.db)
|
const config = await setupQuestionnaire(options.docker, options.db)
|
||||||
await run_migrations(config.db)
|
await run_migrations(config.db)
|
||||||
const ret = await firstrun.setup(config, options.config)
|
const ret = await firstrun.setup(config, options.config)
|
||||||
@@ -251,8 +294,8 @@ async function setup (options) {
|
|||||||
process.exit(-1)
|
process.exit(-1)
|
||||||
}
|
}
|
||||||
if (options.docker) {
|
if (options.docker) {
|
||||||
consola.info(`You can edit ./config.json to modify your configuration.`)
|
consola.info('You can edit ./config.json to modify your configuration.')
|
||||||
consola.info(`Start the server with "docker-compose up"`)
|
consola.info('Start the server with "docker-compose up"')
|
||||||
} else {
|
} else {
|
||||||
consola.info(
|
consola.info(
|
||||||
`You can edit '${options.config}' to modify your configuration. `
|
`You can edit '${options.config}' to modify your configuration. `
|
||||||
|
|||||||
@@ -16,7 +16,15 @@ module.exports = {
|
|||||||
const admin = { email: config.admin.email, password: config.admin.password }
|
const admin = { email: config.admin.email, password: config.admin.password }
|
||||||
delete config.admin
|
delete config.admin
|
||||||
|
|
||||||
config.smtp.secure = true
|
if (config.smtp_type === 'sendmail') {
|
||||||
|
config.smtp = {
|
||||||
|
sendmail: true,
|
||||||
|
newline: 'unix',
|
||||||
|
path: config.smtp.path
|
||||||
|
}
|
||||||
|
}
|
||||||
|
delete config.smtp_type
|
||||||
|
delete config.smtp_need_auth
|
||||||
config.admin_email = admin.email
|
config.admin_email = admin.email
|
||||||
config.db.logging = false
|
config.db.logging = false
|
||||||
consola.info(`Save configuration to ${config_path}`)
|
consola.info(`Save configuration to ${config_path}`)
|
||||||
|
|||||||
Reference in New Issue
Block a user