-
Notifications
You must be signed in to change notification settings - Fork 6
/
apt.js
64 lines (53 loc) · 1.69 KB
/
apt.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
'use strict';
const core = require('@actions/core')
const { execSync, grpSt, grpEnd, getInput } = require('./common')
// group start time
let msSt
export const run = async () => {
try {
// clean input
let apt = getInput('apt-get')
if (apt !== '') {
// fix for server timeout issues
/* msSt = grpSt('apt-get server fix')
* apt += ' _update_'
* execSync(`sudo sed -i 's/azure\\.//' /etc/apt/sources.list`)
* grpEnd(msSt)
*/
const opts = '-o Acquire::Retries=3'
let needUpdate = true
let needUpgrade = true
// if (/\b_update_\b/.test(apt)) {
msSt = grpSt('apt-get update')
execSync(`sudo apt-get ${opts} -qy update`)
grpEnd(msSt)
apt = apt.replace(/\b_update_\b/gi, '').trim()
needUpdate = false
// }
if (/\b_dist-upgrade_\b/.test(apt)) {
msSt = grpSt('apt-get dist-upgrade')
if (needUpdate) { execSync('sudo apt-get -qy update') }
execSync(`sudo apt-get ${opts} -qy dist-upgrade`)
grpEnd(msSt)
needUpgrade = false
apt = apt.replace(/\b_dist-upgrade_\b/gi, '').trim()
}
if (/\b_upgrade_\b/.test(apt)) {
if (needUpgrade) {
msSt = grpSt('apt-get upgrade')
if (needUpdate) { execSync(`sudo apt-get ${opts} -qy update`) }
execSync(`sudo apt-get ${opts} -qy upgrade`)
grpEnd(msSt)
}
apt = apt.replace(/\b_upgrade_\b/gi, '').trim()
}
if (apt !== '') {
msSt = grpSt(`apt-get ${apt}`)
execSync(`sudo apt-get ${opts} -qy --no-install-recommends install ${apt}`)
grpEnd(msSt)
}
}
} catch (error) {
core.setFailed(error.message)
}
}