refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / macos / releases.js
1 'use strict';
2
3 var oses = [
4   {
5     name: 'macOS Sierra',
6     version: '10.12.6',
7     date: '2018-09-26',
8     channel: 'beta',
9     url: 'https://support.apple.com/en-us/HT208202'
10   },
11   {
12     name: 'OS X El Capitan',
13     version: '10.11.6',
14     date: '2018-07-09',
15     lts: true,
16     channel: 'stable',
17     url: 'https://support.apple.com/en-us/HT206886'
18   },
19   {
20     name: 'OS X Yosemite',
21     version: '10.10.5',
22     date: '2017-07-19',
23     channel: 'beta',
24     url: 'https://support.apple.com/en-us/HT210717'
25   }
26 ];
27
28 var headers = {
29   Connection: 'keep-alive',
30   'Cache-Control': 'max-age=0',
31   'Upgrade-Insecure-Requests': '1',
32   'User-Agent':
33     'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36',
34   'Sec-Fetch-Dest': 'document',
35   Accept:
36     'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
37   'Sec-Fetch-Site': 'none',
38   'Sec-Fetch-Mode': 'navigate',
39   'Sec-Fetch-User': '?1',
40   'Accept-Language': 'en-US,en;q=0.9,sq;q=0.8'
41 };
42
43 module.exports = function (request) {
44   var all = { download: '', releases: [] };
45
46   return Promise.all(
47     oses.map(function (os) {
48       return request({
49         method: 'GET',
50         url: os.url,
51         headers: headers
52       }).then(function (resp) {
53         var m = resp.body.match(/(http[^>]+Install[^>]+.dmg)/);
54         var download = m && m[1];
55         ['macos', 'linux'].forEach(function (osname) {
56           all.releases.push({
57             version: os.version,
58             lts: os.lts || false,
59             channel: os.channel || 'beta',
60             date: os.date,
61             os: osname,
62             arch: 'amd64',
63             ext: 'dmg',
64             hash: '-',
65             download: download
66           });
67         });
68       });
69     })
70   ).then(function () {
71     all.releases.sort(function (a, b) {
72       if ('10.11.6' === a.version) {
73         return -1;
74       }
75       if (a.date > b.date) {
76         return 1;
77       }
78       if (a.date < b.date) {
79         return -1;
80       }
81     });
82     return all;
83   });
84 };
85
86 if (module === require.main) {
87   module.exports(require('@root/request')).then(function (all) {
88     console.info(JSON.stringify(all, null, 2));
89   });
90 }