-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.js
87 lines (69 loc) · 3.14 KB
/
start.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// системные модули
var fs = require('fs');
var argv = require('optimist').argv;
var read = require('read');
var async = require('async');
// задачи
var tasks = {
bashrc: require('./tasks/bashrc'),
chrome: require('./tasks/chrome'),
apt: require('./tasks/apt')
}
// загрузка конфигурации
try{
global.config = require('./config.json');
}
catch(e){
console.error('Не удалось прочитать config.json - синтаксическая ошибка:');
console.log(e);
process.exit();
}
// проверка конфигурации
if (typeof global.config.proxy_host === 'undefined' || typeof global.config.proxy_port === 'undefined') {
console.error("Ошибка: не указаны данные прокси-сервера. Укажите их в config.json");
process.exit();
}
async.series([ // предотвращаем асинхронность
function(callback){
// получаем логин и пароль от пользователя с помощью ввода
read({ prompt : 'Введите логин от edu.tatar.ru: ' }, function (err, login) {
if (typeof login === 'undefined' || login == '') {
console.error('Для работы программы необходим логин от edu.tatar.ru');
process.exit();
}
read({
prompt : 'Введите пароль от edu.tatar.ru (введенные символы не показываются):',
silent : true
}, function (err, pass) {
if (typeof pass === 'undefined' || pass == '') {
console.error('Для работы программы необходим пароль от edu.tatar.ru');
process.exit();
}
global.config.edu_login = login;
global.config.edu_pass = pass;
process.stdin.destroy();
callback();
});
});
},
function (callback) {
console.log('Конфигурация загружена, начинаем...');
var operation;
var task = '*';
if (typeof argv._[0] !== 'undefined' && (argv._[0] == 'write' || argv._[0] == 'check' || argv._[0] == 'remove')) {
operation = argv._[0];
if (typeof argv._[1] !== 'undefined')
task = argv._[1];
}
else
operation = 'write';
if (task !== '*')
console.log('задача', task, 'операция', operation, '-', tasks[task][operation]());
else{
for(var key in tasks) // пробегаемся по массиву задач и выполняем их
console.log('задача', key, 'операция', operation, '-', tasks[key][operation]());
}
console.log('Завершено. Для вступления изменений в силу перезапустите компьютер');
callback();
}
]);