This repository has been archived by the owner on May 17, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
start.js
98 lines (81 loc) · 2.97 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const https = require('https')
const crypto = require('crypto')
const fs = require('fs')
const config = require('./config.json')
const exec = require('child_process').execSync
const mtaVersions = {
'1.1': {
'x86': 'https://nightly.mtasa.com/multitheftauto_linux-1.1.1-rc-3544-net1BE.tar.gz'
},
'1.2': {
'x86': 'https://nightly.mtasa.com/multitheftauto_linux-1.2.0-rc-3735-net1CB.tar.gz'
},
'1.3': {
'x86': 'https://nightly.mtasa.com/multitheftauto_linux-1.3.5-rc-6761-net1CE.tar.gz'
},
'1.4': {
'x86': 'https://nightly.mtasa.com/multitheftauto_linux-1.4.1-rc-7382-net1D8.tar.gz',
'x64': 'https://nightly.mtasa.com/multitheftauto_linux_x64-1.4.1-rc-7382-net1D8.tar.gz'
},
'1.5': {
'x86': 'https://nightly.mtasa.com/?multitheftauto_linux-1.5-rc-latest',
'x64': 'https://nightly.mtasa.com/?multitheftauto_linux_x64-1.5-rc-latest'
}
}
const latestVersion = '1.5'
/*
docker build -t mtasa --build-arg DLURL=https://nightly.mtasa.com/multitheftauto_linux-1.5.5-rc-11748.tar.gz --build-arg ARCH=x86 .
*/
let getCurrentHash = (url, callback) => {
https.get(url, (res) => {
const md5sum = crypto.createHash('md5')
res.on('data', (d) => {
md5sum.update(d)
})
res.on('end', () => {
callback(md5sum.digest('hex'))
})
})
}
let compareHashes = (version, arch, hash) => {
let lastHash = {}
if (fs.existsSync('versions.json')) {
lastHash = JSON.parse(fs.readFileSync('versions.json').toString())
}
if (lastHash.length === 0 || !lastHash[version] || lastHash[version][arch] !== hash) {
if (!lastHash[version]) {
lastHash[version] = {}
}
lastHash[version][arch] = hash
fs.writeFileSync('versions.json', JSON.stringify(lastHash))
console.log('Trigger build for ' + version + ' ' + arch)
buildVersion(version, arch)
} else {
console.log(version + ' ' + arch + ' is up to date')
}
}
let buildVersion = (version, arch) => {
let name = 'mtasa_' + version + '_' + arch
exec('docker build -t ' + name + ' --build-arg DLURL=' + mtaVersions[version][arch] + ' --build-arg ARCH=' + arch + ' .')
if (arch === 'x64' || !mtaVersions[version]['x64']) {
exec('docker tag ' + name + ' megathorx/mtasa:' + version)
if (version === latestVersion) {
exec('docker tag ' + name + ' megathorx/mtasa:latest')
}
}
exec('docker tag ' + name + ' megathorx/mtasa:' + version + '_' + arch)
exec('docker push megathorx/mtasa')
exec('docker rmi ' + name)
exec('if docker images | grep "^megathorx/mtasa"; then docker rmi -f $(docker images | grep "^megathorx/mtasa" | awk \'{print $3}\'); fi')
exec('if docker images | grep "^<none>"; then docker rmi $(docker images | grep "^<none>" | awk \'{print $3}\'); fi')
console.log('build done')
}
let loop = () => {
setTimeout(loop, 1000 * 60 * 60 * 8)
for (let version in mtaVersions) {
for (let arch in mtaVersions[version]) {
getCurrentHash(mtaVersions[version][arch], (hash) => { compareHashes(version, arch, hash) })
}
}
}
loop()