forked from ankane/setup-sqlserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
122 lines (108 loc) · 4.58 KB
/
index.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
const execSync = require('child_process').execSync;
const fs = require('fs');
const os = require('os');
const path = require('path');
const process = require('process');
const spawnSync = require('child_process').spawnSync;
function run(command) {
console.log(command);
execSync(command, {stdio: 'inherit'});
}
function addToPath(newPath) {
fs.appendFileSync(process.env.GITHUB_PATH, `${newPath}\n`);
}
function isMac() {
return process.platform == 'darwin';
}
function isWindows() {
return process.platform == 'win32';
}
function waitForReady() {
console.log("Waiting for server to be ready");
for (let i = 0; i < 30; i++) {
let ret = spawnSync('/opt/mssql-tools/bin/sqlcmd', ['-U', 'SA', '-P', 'YourStrong!Passw0rd', '-Q', 'SELECT @@VERSION']);
if (ret.status === 0) {
break;
}
spawnSync('sleep', ['1']);
}
}
function useTmpDir() {
const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'sqlserver-'));
process.chdir(tmpDir);
return tmpDir;
}
const acceptEula = process.env['INPUT_ACCEPT-EULA'];
if (acceptEula !== 'true') {
throw `The SQL Server End-User License Agreement (EULA) must be accepted before SQL Server can start`;
}
const defaultVersion = '2022';
const sqlserverVersion = parseInt(process.env['INPUT_SQLSERVER-VERSION'] || defaultVersion);
if (![2022, 2019].includes(sqlserverVersion)) {
throw `SQL Server version not supported: ${sqlserverVersion}`;
}
const overrideOsVersion = process.env['INPUT_OS-VERSION'] || '';
let osVersion;
if (overrideOsVersion) {
osVersion = overrideOsVersion.trim();
} else {
osVersion = execSync("awk -F= '/^VERSION_ID/ { gsub(/\\\"/,\\\"\\\", $2); print $2 }' /etc/os-release").toString().trim();
}
if (isMac()) {
throw `Mac not supported`;
} else if (isWindows()) {
let url;
if (sqlserverVersion == 2022) {
url = 'https://download.microsoft.com/download/c/c/9/cc9c6797-383c-4b24-8920-dc057c1de9d3/SQL2022-SSEI-Dev.exe';
} else if (sqlserverVersion == 2019) {
// https://go.microsoft.com/fwlink/?linkid=866662
url = 'https://download.microsoft.com/download/d/a/2/da259851-b941-459d-989c-54a18a5d44dd/SQL2019-SSEI-Dev.exe';
} else {
throw `SQL Server version not supported on Windows: ${sqlserverVersion}`;
}
// install
const tmpDir = useTmpDir();
run(`curl -Ls -o SQL${sqlserverVersion}-SSEI-Dev.exe ${url}`);
run(`SQL${sqlserverVersion}-SSEI-Dev.exe /Action=Download /MediaPath="${tmpDir}" /MediaType=CAB /Quiet`);
run(`SQLServer${sqlserverVersion}-DEV-x64-ENU.exe /X:${tmpDir}\\Media /QS`);
const params = [
`/IACCEPTSQLSERVERLICENSETERMS`,
`/ACTION="install"`,
`/FEATURES=SQL,Tools`,
`/INSTANCENAME=MSSQLSERVER`,
`/SQLSVCACCOUNT="NT AUTHORITY\\SYSTEM"`,
`/SQLSYSADMINACCOUNTS="BUILTIN\\ADMINISTRATORS"`,
`/SAPWD="YourStrong!Passw0rd"`,
`/SECURITYMODE=SQL`,
`/ERRORREPORTING=0`
];
// for debugging
// params.push(`/INDICATEPROGRESS`);
run(`${tmpDir}\\Media\\setup.exe /Q ${params.join(' ')}`);
addToPath(`C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn`);
} else {
// install
run(`wget -qO- https://packages.microsoft.com/keys/microsoft.asc | sudo apt-key add -`);
run(`wget -qO- https://packages.microsoft.com/config/ubuntu/${osVersion}/mssql-server-${sqlserverVersion}.list | sudo tee /etc/apt/sources.list.d/mssql-server-${sqlserverVersion}.list`);
// Override "prod" repo so mssql-tools is available for this Ubuntu version
run(`wget -qO- https://packages.microsoft.com/config/ubuntu/${osVersion}/prod.list | sudo tee /etc/apt/sources.list.d/prod.list`);
// If using Jammy packages on a newer distro, add Ubuntu 22.04 (jammy) main & universe for dependencies
if (osVersion === '22.04') {
run(`echo "deb http://archive.ubuntu.com/ubuntu jammy main universe" \
| sudo tee /etc/apt/sources.list.d/ubuntu-jammy.list`);
}
// need to update all due to dependencies
// run(`sudo apt-get update -o Dir::Etc::sourcelist="sources.list.d/mssql-server-${sqlserverVersion}.list" -o Dir::Etc::sourceparts="-" -o APT::Get::List-Cleanup="0"`);
// Update package lists
run(`sudo apt-get update`);
// Install missing OpenLDAP 2.5 library on newer distros
if (osVersion === '22.04') {
// Install the correct OpenLDAP 2.5 library package from Jammy
run(`sudo DEBIAN_FRONTEND=noninteractive apt-get install -y libldap-2.5-0`);
}
// Install SQL Server core and tools
run(`sudo DEBIAN_FRONTEND=noninteractive apt-get install -y mssql-server mssql-tools`);
run(`sudo MSSQL_SA_PASSWORD='YourStrong!Passw0rd' MSSQL_PID=developer /opt/mssql/bin/mssql-conf -n setup accept-eula`);
waitForReady();
addToPath(`/opt/mssql-tools/bin`);
}