]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/initializers/installer.js
3 const async
= require('async')
4 const config
= require('config')
5 const mkdirp
= require('mkdirp')
6 const path
= require('path')
8 const checker
= require('./checker')
9 const logger
= require('../helpers/logger')
10 const peertubeCrypto
= require('../helpers/peertubeCrypto')
11 const Users
= require('../models/users')
14 installApplication: installApplication
17 function installApplication (callback
) {
18 // Creates directories
19 createDirectoriesIfNotExist(function (err
) {
20 if (err
) return callback(err
)
22 // ----------- Create the certificates if they don't already exist -----------
23 peertubeCrypto
.createCertsIfNotExist(function (err
) {
24 if (err
) return callback(err
)
26 createOAuthClientIfNotExist(function (err
) {
27 if (err
) return callback(err
)
29 createOAuthUserIfNotExist(callback
)
35 // ---------------------------------------------------------------------------
37 module
.exports
= installer
39 // ---------------------------------------------------------------------------
41 function createDirectoriesIfNotExist (callback
) {
42 const storages
= config
.get('storage')
44 async
.each(Object
.keys(storages
), function (key
, callbackEach
) {
45 const dir
= storages
[key
]
46 mkdirp(path
.join(__dirname
, '..', '..', dir
), callbackEach
)
50 function createOAuthClientIfNotExist (callback
) {
51 checker
.clientsExist(function (err
, exist
) {
52 if (err
) return callback(err
)
54 // Nothing to do, clients already exist
55 if (exist
=== true) return callback(null)
57 logger
.info('Creating a default OAuth Client.')
59 // TODO: generate password
60 const password
= 'megustalabanana'
61 Users
.createClient(password
, [ 'password' ], function (err
, id
) {
62 if (err
) return callback(err
)
64 logger
.info('Client id: ' + id
)
65 logger
.info('Client password: ' + password
)
72 function createOAuthUserIfNotExist (callback
) {
73 checker
.usersExist(function (err
, exist
) {
74 if (err
) return callback(err
)
76 // Nothing to do, users already exist
77 if (exist
=== true) return callback(null)
79 logger
.info('Creating the administrator.')
81 // TODO: generate password
82 const username
= 'admin'
83 const password
= 'nomegustalabanana'
85 Users
.createUser(username
, password
, function (err
) {
86 if (err
) return callback(err
)
88 logger
.info('Username: ' + username
)
89 logger
.info('User password: ' + password
)