|
| 1 | +/*----------------------------------------------------------------------------------------------- |
| 2 | + * Copyright (c) Red Hat, Inc. All rights reserved. |
| 3 | + * Licensed under the MIT License. See LICENSE file in the project root for license information. |
| 4 | + *-----------------------------------------------------------------------------------------------*/ |
| 5 | + |
| 6 | +import { DownloadUtil } from './download'; |
| 7 | +import { Archive } from '../src/util/archive'; |
| 8 | + |
| 9 | +import hasha = require('hasha'); |
| 10 | +import mkdirp = require('mkdirp'); |
| 11 | +import path = require('path'); |
| 12 | +import fs = require('fs-extra'); |
| 13 | +import configData = require('../src/tools.json'); |
| 14 | + |
| 15 | +async function verifyTools(): Promise<void> { |
| 16 | + for (const key in configData) { |
| 17 | + for (const OS in configData[key].platform) { |
| 18 | + const targetFolder = path.resolve('.', 'out', 'tools', OS); |
| 19 | + console.info(`Download tools to '${targetFolder}'`); |
| 20 | + await downloadFileAndCreateSha256( |
| 21 | + targetFolder, |
| 22 | + configData[key].platform[OS].dlFileName, |
| 23 | + configData[key].platform[OS].url, |
| 24 | + configData[key].platform[OS].sha256sum, |
| 25 | + configData[key].platform[OS].cmdFileName, |
| 26 | + configData[key].platform[OS].filePrefix); |
| 27 | + } |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +async function downloadFileAndCreateSha256(targetFolder: string, fileName: string, reqURL: string, sha256sum: string, cmdFileName: string, filePrefix?: string) { |
| 32 | + mkdirp.sync(targetFolder); |
| 33 | + const currentFile = path.join(targetFolder, fileName); |
| 34 | + console.log(`${currentFile} download started from ${reqURL}`); |
| 35 | + await DownloadUtil.downloadFile(reqURL, currentFile, (current) => console.log(`${current }%`)); |
| 36 | + const currentSHA256 = await hasha.fromFile(currentFile, {algorithm: 'sha256'}); |
| 37 | + if (currentSHA256 === sha256sum) { |
| 38 | + console.log( `[INFO] ${currentFile} is downloaded and sha256 is correct`); |
| 39 | + } else { |
| 40 | + throw Error(`${currentFile} is downloaded and sha256 is not correct`); |
| 41 | + } |
| 42 | + await Archive.extract(currentFile, targetFolder, cmdFileName, filePrefix); |
| 43 | + fs.removeSync(currentFile); |
| 44 | +} |
| 45 | + |
| 46 | +verifyTools(); |
0 commit comments