2019-03-12 22:07:57 +00:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright 2019 Balena Ltd.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
2019-04-25 17:39:16 +00:00
|
|
|
|
2018-11-05 08:18:18 +00:00
|
|
|
declare module 'balena-device-init' {
|
2024-12-16 14:11:57 +00:00
|
|
|
import type { DeviceTypeJson } from 'balena-sdk';
|
2017-12-20 21:46:01 +00:00
|
|
|
|
|
|
|
interface OperationState {
|
2018-01-09 15:05:24 +00:00
|
|
|
operation:
|
|
|
|
| CopyOperation
|
|
|
|
| ReplaceOperation
|
|
|
|
| RunScriptOperation
|
|
|
|
| BurnOperation;
|
2017-12-20 21:46:01 +00:00
|
|
|
percentage: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface Operation {
|
|
|
|
command: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface CopyOperation extends Operation {
|
|
|
|
command: 'copy';
|
|
|
|
from: { path: string };
|
|
|
|
to: { path: string };
|
|
|
|
}
|
|
|
|
|
|
|
|
interface ReplaceOperation extends Operation {
|
|
|
|
command: 'replace';
|
|
|
|
copy: string;
|
|
|
|
replace: string;
|
|
|
|
file: {
|
|
|
|
path: string;
|
2018-01-04 14:07:55 +00:00
|
|
|
};
|
2017-12-20 21:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
interface RunScriptOperation extends Operation {
|
|
|
|
command: 'run-script';
|
|
|
|
script: string;
|
|
|
|
arguments?: string[];
|
|
|
|
}
|
|
|
|
|
|
|
|
interface BurnOperation extends Operation {
|
|
|
|
command: 'burn';
|
|
|
|
image?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface BurnProgress {
|
|
|
|
type: 'write' | 'check';
|
|
|
|
percentage: number;
|
|
|
|
transferred: number;
|
|
|
|
length: number;
|
|
|
|
remaining: number;
|
|
|
|
eta: number;
|
|
|
|
runtime: number;
|
|
|
|
delta: number;
|
|
|
|
speed: number;
|
|
|
|
}
|
|
|
|
|
|
|
|
interface InitializeEmitter {
|
2019-03-12 22:07:57 +00:00
|
|
|
on(event: 'stdout' | 'stderr', callback: (msg: string) => void): void;
|
2017-12-20 21:46:01 +00:00
|
|
|
on(event: 'state', callback: (state: OperationState) => void): void;
|
|
|
|
on(event: 'burn', callback: (state: BurnProgress) => void): void;
|
2019-10-13 23:52:43 +00:00
|
|
|
on(event: 'end', callback: () => void): void;
|
|
|
|
on(event: 'error', callback: (error: Error) => void): void;
|
2017-12-20 21:46:01 +00:00
|
|
|
}
|
|
|
|
|
2024-09-18 15:07:33 +00:00
|
|
|
// As of writing this, these are Bluebird promises, but we are typing then
|
|
|
|
// as normal Promises so that we do not rely on Bluebird specific methods,
|
|
|
|
// so that the CLI will not require any change once the package drops Bluebird.
|
|
|
|
|
2018-11-05 08:18:18 +00:00
|
|
|
export function configure(
|
|
|
|
image: string,
|
2024-12-16 14:11:57 +00:00
|
|
|
manifest: DeviceTypeJson.DeviceType,
|
2023-10-27 14:57:07 +00:00
|
|
|
config: object,
|
|
|
|
options?: object,
|
2024-09-18 15:07:33 +00:00
|
|
|
): Promise<InitializeEmitter>;
|
2018-11-05 08:18:18 +00:00
|
|
|
|
2018-01-09 15:05:24 +00:00
|
|
|
export function initialize(
|
|
|
|
image: string,
|
2024-12-16 14:11:57 +00:00
|
|
|
manifest: DeviceTypeJson.DeviceType,
|
2023-10-27 14:57:07 +00:00
|
|
|
config: object,
|
2024-09-18 15:07:33 +00:00
|
|
|
): Promise<InitializeEmitter>;
|
2018-11-05 08:18:18 +00:00
|
|
|
|
|
|
|
export function getImageOsVersion(
|
|
|
|
image: string,
|
2024-12-16 14:11:57 +00:00
|
|
|
manifest: DeviceTypeJson.DeviceType,
|
2024-09-18 15:07:33 +00:00
|
|
|
): Promise<string | null>;
|
2018-11-05 08:18:18 +00:00
|
|
|
|
2020-07-31 14:35:20 +00:00
|
|
|
export function getImageManifest(
|
|
|
|
image: string,
|
2024-12-16 14:11:57 +00:00
|
|
|
): Promise<DeviceTypeJson.DeviceType | null>;
|
2017-12-20 21:46:01 +00:00
|
|
|
}
|