@iobroker/js-controller-cli 7.0.2-alpha.0-20241026-8055a2557 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +2 -1
- package/build/cjs/index.js.map +2 -2
- package/build/cjs/lib/_Types.d.ts +0 -1
- package/build/cjs/lib/cli/cliCert.js +17 -0
- package/build/cjs/lib/cli/cliCert.js.map +1 -1
- package/build/cjs/lib/cli/cliCommand.d.ts +0 -1
- package/build/cjs/lib/cli/cliCommand.js +6 -0
- package/build/cjs/lib/cli/cliCommand.js.map +1 -1
- package/build/cjs/lib/cli/cliCompact.js +30 -1
- package/build/cjs/lib/cli/cliCompact.js.map +1 -1
- package/build/cjs/lib/cli/cliDebug.js +16 -0
- package/build/cjs/lib/cli/cliDebug.js.map +1 -1
- package/build/cjs/lib/cli/cliHost.js +35 -0
- package/build/cjs/lib/cli/cliHost.js.map +1 -1
- package/build/cjs/lib/cli/cliLogs.js +33 -3
- package/build/cjs/lib/cli/cliLogs.js.map +3 -3
- package/build/cjs/lib/cli/cliMessage.js +10 -0
- package/build/cjs/lib/cli/cliMessage.js.map +1 -1
- package/build/cjs/lib/cli/cliObjects.d.ts +0 -1
- package/build/cjs/lib/cli/cliObjects.js +85 -0
- package/build/cjs/lib/cli/cliObjects.js.map +1 -1
- package/build/cjs/lib/cli/cliPlugin.js +23 -2
- package/build/cjs/lib/cli/cliPlugin.js.map +3 -3
- package/build/cjs/lib/cli/cliProcess.js +65 -2
- package/build/cjs/lib/cli/cliProcess.js.map +1 -1
- package/build/cjs/lib/cli/cliStates.d.ts +0 -1
- package/build/cjs/lib/cli/cliStates.js +38 -0
- package/build/cjs/lib/cli/cliStates.js.map +1 -1
- package/build/cjs/lib/cli/cliTools.js.map +1 -1
- package/build/cjs/lib/cli/messages.d.ts +27 -23
- package/build/cjs/lib/cli/messages.js.map +1 -1
- package/build/cjs/lib/setup/dbConnection.js +9 -0
- package/build/cjs/lib/setup/dbConnection.js.map +1 -1
- package/build/cjs/lib/setup/formatters.js.map +1 -1
- package/build/cjs/lib/setup/multihostClient.d.ts +0 -1
- package/build/cjs/lib/setup/multihostClient.js +36 -0
- package/build/cjs/lib/setup/multihostClient.js.map +1 -1
- package/build/cjs/lib/setup/setupBackup.js +112 -2
- package/build/cjs/lib/setup/setupBackup.js.map +1 -1
- package/build/cjs/lib/setup/setupInstall.d.ts +6 -6
- package/build/cjs/lib/setup/setupInstall.js +198 -57
- package/build/cjs/lib/setup/setupInstall.js.map +4 -4
- package/build/cjs/lib/setup/setupLicense.js +9 -0
- package/build/cjs/lib/setup/setupLicense.js.map +1 -1
- package/build/cjs/lib/setup/setupList.d.ts +0 -1
- package/build/cjs/lib/setup/setupList.js +4 -0
- package/build/cjs/lib/setup/setupList.js.map +1 -1
- package/build/cjs/lib/setup/setupMultihost.d.ts +2 -5
- package/build/cjs/lib/setup/setupMultihost.js +58 -33
- package/build/cjs/lib/setup/setupMultihost.js.map +3 -3
- package/build/cjs/lib/setup/setupPacketManager.js +41 -0
- package/build/cjs/lib/setup/setupPacketManager.js.map +1 -1
- package/build/cjs/lib/setup/setupRepo.js +60 -0
- package/build/cjs/lib/setup/setupRepo.js.map +1 -1
- package/build/cjs/lib/setup/setupSetup.d.ts +0 -1
- package/build/cjs/lib/setup/setupSetup.js +79 -5
- package/build/cjs/lib/setup/setupSetup.js.map +3 -3
- package/build/cjs/lib/setup/setupUpgrade.js +34 -0
- package/build/cjs/lib/setup/setupUpgrade.js.map +1 -1
- package/build/cjs/lib/setup/setupUpload.d.ts +0 -3
- package/build/cjs/lib/setup/setupUpload.js +43 -0
- package/build/cjs/lib/setup/setupUpload.js.map +1 -1
- package/build/cjs/lib/setup/setupUsers.d.ts +0 -1
- package/build/cjs/lib/setup/setupUsers.js +109 -0
- package/build/cjs/lib/setup/setupUsers.js.map +1 -1
- package/build/cjs/lib/setup/setupVendor.js +18 -1
- package/build/cjs/lib/setup/setupVendor.js.map +1 -1
- package/build/cjs/lib/setup/setupVisDebug.js +16 -0
- package/build/cjs/lib/setup/setupVisDebug.js.map +1 -1
- package/build/cjs/lib/setup/utils.d.ts +1 -1
- package/build/cjs/lib/setup/utils.js +8 -4
- package/build/cjs/lib/setup/utils.js.map +2 -2
- package/build/cjs/lib/setup.js +17 -6
- package/build/cjs/lib/setup.js.map +3 -3
- package/build/esm/index.d.ts.map +1 -1
- package/build/esm/index.js +1 -0
- package/build/esm/index.js.map +1 -1
- package/build/esm/lib/_Types.d.ts +0 -1
- package/build/esm/lib/_Types.d.ts.map +1 -1
- package/build/esm/lib/cli/cliCommand.d.ts +0 -1
- package/build/esm/lib/cli/cliCommand.d.ts.map +1 -1
- package/build/esm/lib/cli/cliObjects.d.ts +0 -1
- package/build/esm/lib/cli/cliObjects.d.ts.map +1 -1
- package/build/esm/lib/cli/cliStates.d.ts +0 -1
- package/build/esm/lib/cli/cliStates.d.ts.map +1 -1
- package/build/esm/lib/cli/messages.d.ts +27 -23
- package/build/esm/lib/cli/messages.d.ts.map +1 -1
- package/build/esm/lib/setup/multihostClient.d.ts +0 -1
- package/build/esm/lib/setup/multihostClient.d.ts.map +1 -1
- package/build/esm/lib/setup/setupInstall.d.ts +6 -6
- package/build/esm/lib/setup/setupInstall.d.ts.map +1 -1
- package/build/esm/lib/setup/setupInstall.js +37 -70
- package/build/esm/lib/setup/setupInstall.js.map +1 -1
- package/build/esm/lib/setup/setupList.d.ts +0 -1
- package/build/esm/lib/setup/setupList.d.ts.map +1 -1
- package/build/esm/lib/setup/setupMultihost.d.ts +2 -5
- package/build/esm/lib/setup/setupMultihost.d.ts.map +1 -1
- package/build/esm/lib/setup/setupMultihost.js +12 -37
- package/build/esm/lib/setup/setupMultihost.js.map +1 -1
- package/build/esm/lib/setup/setupSetup.d.ts +0 -1
- package/build/esm/lib/setup/setupSetup.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUpload.d.ts +0 -3
- package/build/esm/lib/setup/setupUpload.d.ts.map +1 -1
- package/build/esm/lib/setup/setupUsers.d.ts +0 -1
- package/build/esm/lib/setup/setupUsers.d.ts.map +1 -1
- package/build/esm/lib/setup/utils.d.ts +1 -1
- package/build/esm/lib/setup/utils.d.ts.map +1 -1
- package/build/esm/lib/setup/utils.js +3 -3
- package/build/esm/lib/setup/utils.js.map +1 -1
- package/build/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
|
@@ -57,6 +57,7 @@ class PacketManager {
|
|
|
57
57
|
this.sudo = false;
|
|
58
58
|
this._readyPromise = this._init();
|
|
59
59
|
}
|
|
60
|
+
/** Starts the initialization process */
|
|
60
61
|
async _init() {
|
|
61
62
|
if (process.platform !== "win32") {
|
|
62
63
|
if (!this.manager) {
|
|
@@ -73,6 +74,12 @@ class PacketManager {
|
|
|
73
74
|
ready() {
|
|
74
75
|
return this._readyPromise;
|
|
75
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* Tests if the given command can be executed
|
|
79
|
+
*
|
|
80
|
+
* @param cmd The command to test
|
|
81
|
+
* @returns True if the execution was successful, false otherwise
|
|
82
|
+
*/
|
|
76
83
|
async _isCmd(cmd) {
|
|
77
84
|
try {
|
|
78
85
|
const { stderr } = await (0, import_tools.execAsync)(cmd);
|
|
@@ -118,6 +125,9 @@ class PacketManager {
|
|
|
118
125
|
return false;
|
|
119
126
|
}
|
|
120
127
|
}
|
|
128
|
+
/**
|
|
129
|
+
* Detects which package manager is installed. Throws if none can be found
|
|
130
|
+
*/
|
|
121
131
|
async _detectManager() {
|
|
122
132
|
for (const cmd of ["apt", "yum"]) {
|
|
123
133
|
if (await this._isCmd(cmd)) {
|
|
@@ -127,6 +137,9 @@ class PacketManager {
|
|
|
127
137
|
}
|
|
128
138
|
this.logger.info("No supported packet manager found");
|
|
129
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Updates the sources if apt is used
|
|
142
|
+
*/
|
|
130
143
|
async update() {
|
|
131
144
|
await this.ready();
|
|
132
145
|
if (this.manager !== "apt") {
|
|
@@ -150,6 +163,11 @@ class PacketManager {
|
|
|
150
163
|
return "";
|
|
151
164
|
}
|
|
152
165
|
}
|
|
166
|
+
/**
|
|
167
|
+
* Checks which packages are installed and returns them
|
|
168
|
+
*
|
|
169
|
+
* @param packets The packets to test
|
|
170
|
+
*/
|
|
153
171
|
async checkInstalled(packets) {
|
|
154
172
|
if (!(packets instanceof Array)) {
|
|
155
173
|
packets = [packets];
|
|
@@ -157,12 +175,20 @@ class PacketManager {
|
|
|
157
175
|
const installed = await this._listPackages();
|
|
158
176
|
return packets.filter((p) => installed.includes(p));
|
|
159
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Installs a single packet using the configured manager and returns the stdout if there was any
|
|
180
|
+
*
|
|
181
|
+
* @param packet The packet to install
|
|
182
|
+
*/
|
|
160
183
|
async _installPacket(packet) {
|
|
161
184
|
if (!this.manager) {
|
|
162
185
|
return;
|
|
163
186
|
}
|
|
164
187
|
await (0, import_tools.execAsync)(`${(this.sudo ? "sudo " : "") + this.manager} install ${packet} -y`);
|
|
165
188
|
}
|
|
189
|
+
/**
|
|
190
|
+
* List all packages for which updates are available
|
|
191
|
+
*/
|
|
166
192
|
async listUpgradeablePackages() {
|
|
167
193
|
if (!this.manager) {
|
|
168
194
|
return [];
|
|
@@ -176,6 +202,11 @@ class PacketManager {
|
|
|
176
202
|
packagesList.shift();
|
|
177
203
|
return packagesList;
|
|
178
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Installs multiple packets. The returned Promise contains the list of failed packets
|
|
207
|
+
*
|
|
208
|
+
* @param packets list of packets to install
|
|
209
|
+
*/
|
|
179
210
|
async _installPackets(packets) {
|
|
180
211
|
const failed = [];
|
|
181
212
|
if (packets?.length) {
|
|
@@ -190,6 +221,11 @@ class PacketManager {
|
|
|
190
221
|
}
|
|
191
222
|
return failed;
|
|
192
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Upgrade given OS packets to given version or newest available version
|
|
226
|
+
*
|
|
227
|
+
* @param packets the packet names and version information
|
|
228
|
+
*/
|
|
193
229
|
async upgrade(packets) {
|
|
194
230
|
await this.ready();
|
|
195
231
|
if (!this.manager) {
|
|
@@ -207,6 +243,11 @@ class PacketManager {
|
|
|
207
243
|
await (0, import_tools.execAsync)(`${(this.sudo ? "sudo " : "") + this.manager} ${upgradeCmd}`);
|
|
208
244
|
}
|
|
209
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Installs all given packets
|
|
248
|
+
*
|
|
249
|
+
* @param packets list of packets or single packet to upgrade
|
|
250
|
+
*/
|
|
210
251
|
async install(packets) {
|
|
211
252
|
packets = packets || [];
|
|
212
253
|
if (!(packets instanceof Array)) {
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/setup/setupPacketManager.ts"],
|
|
4
4
|
"sourcesContent": ["import { execAsync, type InternalLogger } from '@iobroker/js-controller-common-db/tools';\n\nenum LOG_LEVELS {\n silly = 5,\n debug = 4,\n log = 3,\n info = 2,\n warn = 1,\n error = 0,\n}\n\ninterface Logger extends InternalLogger {\n log(message: string): void;\n}\n\ntype Manager = 'apt' | 'yum' | '';\n\ninterface PacketManagerOptions {\n logLevel: LOG_LEVELS;\n manager?: Manager;\n logger?: Logger;\n}\n\nexport interface UpgradePacket {\n /** Name of the packet which should be upgraded */\n name: string;\n /** Optional version */\n version?: string;\n}\n\nexport class PacketManager {\n private manager: Manager;\n private readonly logger: Logger;\n private dpkg: boolean;\n private sudo: boolean;\n private readonly _readyPromise: Promise<void>;\n private readonly COMMANDS = {\n listUpgradeable: {\n apt: 'list --upgradeable',\n yum: 'check-update',\n },\n } as const;\n\n constructor(options: PacketManagerOptions = { logLevel: LOG_LEVELS.info }) {\n // detect apt or yum\n this.manager = options?.manager || '';\n this.logger = options?.logger || {\n silly: text => options.logLevel >= LOG_LEVELS.silly && console.log(text),\n info: text => options.logLevel >= LOG_LEVELS.info && console.log(text),\n log: text => options.logLevel >= LOG_LEVELS.log && console.log(text),\n warn: text => options.logLevel >= LOG_LEVELS.warn && console.warn(text),\n error: text => options.logLevel >= LOG_LEVELS.error && console.error(text),\n debug: text => options.logLevel >= LOG_LEVELS.debug && console.log(text),\n };\n this.dpkg = false;\n this.sudo = false;\n this._readyPromise = this._init();\n }\n\n /** Starts the initialization process */\n private async _init(): Promise<void> {\n if (process.platform !== 'win32') {\n if (!this.manager) {\n const manager = await this._detectManager();\n if (manager) {\n this.logger.debug(`Detected packet manager: ${manager}`);\n // Check if sudo is available for packet manager and store information\n this.sudo = (await this._isSudoAvailable()) && (await this._isSudoAvailableForManager());\n }\n }\n\n // Check if dpkg is available\n this.dpkg = await this._isDpkgAvailable();\n this.logger.debug(`Detected dpkg: ${this.dpkg}`);\n }\n }\n\n ready(): Promise<void> {\n return this._readyPromise;\n }\n\n /**\n * Tests if the given command can be executed\n *\n * @param cmd The command to test\n * @returns True if the execution was successful, false otherwise\n */\n private async _isCmd(cmd: string): Promise<boolean> {\n try {\n const { stderr } = await execAsync(cmd);\n return !stderr;\n } catch (e) {\n // non zero exit code, however lets check if ok\n if (e.stderr === '') {\n return true;\n }\n console.error(e.stderr || e.stdout || e);\n return false;\n }\n }\n\n private async _isDpkgAvailable(): Promise<boolean> {\n try {\n const { stdout, stderr } = await execAsync('dpkg');\n return !!((stdout && stdout.includes('dpkg --help')) || (stderr && stderr.includes('dpkg --help')));\n } catch (err) {\n // non zero exit code, however lets check if ok\n if (\n (err.stdout && err.stdout.includes('dpkg --help')) ||\n (err.stderr && err.stderr.includes('dpkg --help'))\n ) {\n return true;\n }\n this.logger.error(`Cannot detect dpkg: ${err.stderr || err.stdout || err}`);\n return false;\n }\n }\n\n private async _isSudoAvailable(): Promise<boolean> {\n try {\n const { stdout, stderr } = await execAsync('sudo');\n return !!((stdout && stdout.includes('sudo -h')) || (stderr && stderr.includes('sudo -h')));\n } catch (err) {\n // non zero exit code, however lets check if ok\n if ((err.stdout && err.stdout.includes('sudo -h')) || (err.stderr && err.stderr.includes('sudo -h'))) {\n return true;\n }\n this.logger.error(`Cannot detect sudo: ${err.stderr || err.stdout || err}`);\n return false;\n }\n }\n\n private async _isSudoAvailableForManager(): Promise<boolean> {\n try {\n await execAsync(`sudo -n ${this.manager} -v`);\n return true;\n } catch (err) {\n this.logger.error(`Cannot detect \\\\\"sudo -n ${this.manager} -v\\\\\": ${err.stderr || err.stdout || err}`);\n return false;\n }\n }\n\n /**\n * Detects which package manager is installed. Throws if none can be found\n */\n private async _detectManager(): Promise<Manager | void> {\n for (const cmd of ['apt', 'yum'] as const) {\n if (await this._isCmd(cmd)) {\n this.manager = cmd;\n return cmd;\n }\n }\n this.logger.info('No supported packet manager found');\n }\n\n /**\n * Updates the sources if apt is used\n */\n async update(): Promise<void> {\n await this.ready();\n\n if (this.manager !== 'apt') {\n // ignore\n return;\n }\n\n try {\n await execAsync(`${(this.sudo ? 'sudo ' : '') + this.manager} update`);\n } catch (e) {\n this.logger.warn(`Cannot update apt sources: ${e.message}`);\n }\n }\n\n private async _listPackages(): Promise<string> {\n if (!this.dpkg) {\n throw new Error('No dpkg detected');\n }\n\n try {\n const { stdout } = await execAsync(`${this.sudo ? 'sudo ' : ''}dpkg -l`);\n const res = Buffer.isBuffer(stdout) ? stdout.toString('utf-8') : stdout;\n return res || '';\n } catch {\n // Ignore error\n return '';\n }\n }\n\n /**\n * Checks which packages are installed and returns them\n *\n * @param packets The packets to test\n */\n async checkInstalled(packets: string[] | string): Promise<string[]> {\n if (!(packets instanceof Array)) {\n packets = [packets];\n }\n\n const installed = await this._listPackages();\n return packets.filter(p => installed.includes(p));\n }\n\n /**\n * Installs a single packet using the configured manager and returns the stdout if there was any\n *\n * @param packet The packet to install\n */\n private async _installPacket(packet: string): Promise<void> {\n if (!this.manager) {\n // ignore\n return;\n }\n\n // if it fails, let it throw and get caught by _installPackets\n await execAsync(`${(this.sudo ? 'sudo ' : '') + this.manager} install ${packet} -y`);\n }\n\n /**\n * List all packages for which updates are available\n */\n async listUpgradeablePackages(): Promise<string[]> {\n if (!this.manager) {\n return [];\n }\n\n const { stdout } = await execAsync(\n `${(this.sudo ? 'sudo ' : '') + this.manager} ${this.COMMANDS.listUpgradeable[this.manager]}`,\n );\n\n const res = Buffer.isBuffer(stdout) ? stdout.toString('utf-8') : stdout;\n\n if (!res) {\n return [];\n }\n\n const packagesList = res.split('\\n').filter(packageInfo => packageInfo.trim() !== '');\n // first line is no package, just Listing...\n packagesList.shift();\n\n return packagesList;\n }\n\n /**\n * Installs multiple packets. The returned Promise contains the list of failed packets\n *\n * @param packets list of packets to install\n */\n private async _installPackets(packets: string[]): Promise<string[]> {\n const failed: string[] = [];\n\n if (packets?.length) {\n // Install all packets\n for (const packet of packets) {\n try {\n await this._installPacket(packet);\n } catch (err) {\n failed.push(packet);\n this.logger.error(`Cannot install \"${packet}\": ${err.stderr || err.stdout || err}`);\n // Continue with the next packet\n }\n }\n }\n return failed;\n }\n\n /**\n * Upgrade given OS packets to given version or newest available version\n *\n * @param packets the packet names and version information\n */\n async upgrade(packets: UpgradePacket[]): Promise<void> {\n await this.ready();\n\n if (!this.manager) {\n return;\n }\n\n for (const packet of packets) {\n let upgradeCmd = `upgrade -y ${packet.name}`;\n\n if (packet.version) {\n if (this.manager === 'apt') {\n upgradeCmd += `=${packet.version}`;\n } else {\n upgradeCmd = `install ${packet.name}-${packet.version}`;\n }\n }\n\n await execAsync(`${(this.sudo ? 'sudo ' : '') + this.manager} ${upgradeCmd}`);\n }\n }\n\n /**\n * Installs all given packets\n *\n * @param packets list of packets or single packet to upgrade\n */\n async install(packets: string[] | string): Promise<void> {\n packets = packets || [];\n if (!(packets instanceof Array)) {\n packets = [packets];\n }\n\n await this.ready();\n\n // Filter empty packets out\n packets = packets && packets.filter(p => p && p.trim());\n\n if (!packets || !packets.length) {\n // nothing must be installed\n return;\n }\n const installed = await this.checkInstalled(packets);\n const notInstalled = packets.filter(packet => !installed.includes(packet));\n // Install all non-installed packets\n const failed = await this._installPackets(notInstalled);\n if (this.logger) {\n if (failed.length > 0) {\n this.logger.warn(\n `The following ${this.manager || 'OS'} packages could not be installed: ${failed.join(\n ', ',\n )}. Please install them manually.`,\n );\n\n if (notInstalled.length) {\n this.logger.info(\n `Installed the following ${this.manager || 'OS'} packages: ${notInstalled.join(', ')}`,\n );\n }\n\n if (installed.length) {\n this.logger.info(\n `These ${this.manager || 'OS'} packages were already installed: ${installed.join(', ')}`,\n );\n }\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;mBAA+C;AAE/C,IAAK;CAAL,SAAKA,aAAU;AACX,EAAAA,YAAAA,YAAA,
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;;;;;AAAA,mBAA+C;AAE/C,IAAK;CAAL,SAAKA,aAAU;AACX,EAAAA,YAAAA,YAAA,OAAA,IAAA,CAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,OAAA,IAAA,CAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,KAAA,IAAA,CAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,MAAA,IAAA,CAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,MAAA,IAAA,CAAA,IAAA;AACA,EAAAA,YAAAA,YAAA,OAAA,IAAA,CAAA,IAAA;AACJ,GAPK,eAAA,aAAU,CAAA,EAAA;AA4BT,MAAO,cAAa;EACd;EACS;EACT;EACA;EACS;EACA,WAAW;IACxB,iBAAiB;MACb,KAAK;MACL,KAAK;;;EAIb,YAAY,UAAgC,EAAE,UAAU,WAAW,KAAI,GAAE;AAErE,SAAK,UAAU,SAAS,WAAW;AACnC,SAAK,SAAS,SAAS,UAAU;MAC7B,OAAO,UAAQ,QAAQ,YAAY,WAAW,SAAS,QAAQ,IAAI,IAAI;MACvE,MAAM,UAAQ,QAAQ,YAAY,WAAW,QAAQ,QAAQ,IAAI,IAAI;MACrE,KAAK,UAAQ,QAAQ,YAAY,WAAW,OAAO,QAAQ,IAAI,IAAI;MACnE,MAAM,UAA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K,IAAI,CAAC,EAAE;QAEhG;MACJ;IACJ;EACJ;;",
|
|
6
6
|
"names": ["LOG_LEVELS"]
|
|
7
7
|
}
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -69,6 +73,14 @@ class Repo {
|
|
|
69
73
|
type: "config"
|
|
70
74
|
};
|
|
71
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* Update the given repository and returns new repo content
|
|
78
|
+
*
|
|
79
|
+
* @param repoName name of the repository
|
|
80
|
+
* @param force force update even if same hash
|
|
81
|
+
* @param systemConfig content of system.config object
|
|
82
|
+
* @param systemRepos content of system.repositories object
|
|
83
|
+
*/
|
|
72
84
|
async updateRepo(repoName, force, systemConfig, systemRepos) {
|
|
73
85
|
if (!repoName) {
|
|
74
86
|
const sysConfig = systemConfig || await this.objects.getObject("system.config");
|
|
@@ -144,6 +156,12 @@ class Repo {
|
|
|
144
156
|
}
|
|
145
157
|
return oldRepos.native.repositories[repoName].json;
|
|
146
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Show repo on CLI
|
|
161
|
+
*
|
|
162
|
+
* @param repoUrl url of the repository
|
|
163
|
+
* @param flags CLI flags
|
|
164
|
+
*/
|
|
147
165
|
async showRepo(repoUrl, flags) {
|
|
148
166
|
const systemConfig = await this.objects.getObject("system.config");
|
|
149
167
|
const systemRepos = await this.objects.getObject("system.repositories");
|
|
@@ -183,6 +201,12 @@ class Repo {
|
|
|
183
201
|
return this.showRepoResult(allSources, flags);
|
|
184
202
|
}
|
|
185
203
|
}
|
|
204
|
+
/**
|
|
205
|
+
* Show the repo result on CLI
|
|
206
|
+
*
|
|
207
|
+
* @param sources Repo json sources
|
|
208
|
+
* @param flags CLI flags
|
|
209
|
+
*/
|
|
186
210
|
async showRepoResult(sources, flags) {
|
|
187
211
|
const installed = import_js_controller_common.tools.getInstalledInfo();
|
|
188
212
|
const adapters = Object.keys(sources).sort();
|
|
@@ -221,6 +245,11 @@ class Repo {
|
|
|
221
245
|
console.log(text);
|
|
222
246
|
}
|
|
223
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* Update Admin info states with number of updates
|
|
250
|
+
*
|
|
251
|
+
* @param sources the repository object
|
|
252
|
+
*/
|
|
224
253
|
async updateInfo(sources) {
|
|
225
254
|
const installed = import_js_controller_common.tools.getInstalledInfo();
|
|
226
255
|
const list = [];
|
|
@@ -250,6 +279,9 @@ class Repo {
|
|
|
250
279
|
}
|
|
251
280
|
}
|
|
252
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Show current status of Repo on CLI
|
|
284
|
+
*/
|
|
253
285
|
async showRepoStatus() {
|
|
254
286
|
try {
|
|
255
287
|
const obj = await this.objects.getObject("system.repositories");
|
|
@@ -283,6 +315,12 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
283
315
|
}
|
|
284
316
|
return import_js_controller_common.EXIT_CODES.CANNOT_GET_REPO_LIST;
|
|
285
317
|
}
|
|
318
|
+
/**
|
|
319
|
+
* Add new repo
|
|
320
|
+
*
|
|
321
|
+
* @param repoName name of new repo
|
|
322
|
+
* @param repoUrl url of new repo
|
|
323
|
+
*/
|
|
286
324
|
async add(repoName, repoUrl) {
|
|
287
325
|
const sysRepoObj = await this.objects.getObjectAsync("system.repositories");
|
|
288
326
|
const obj = sysRepoObj || this.defaultSystemRepo;
|
|
@@ -298,6 +336,11 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
298
336
|
await this.objects.setObjectAsync("system.repositories", obj);
|
|
299
337
|
}
|
|
300
338
|
}
|
|
339
|
+
/**
|
|
340
|
+
* Remove repository from sources
|
|
341
|
+
*
|
|
342
|
+
* @param repoName name of repository to remove
|
|
343
|
+
*/
|
|
301
344
|
async del(repoName) {
|
|
302
345
|
const obj = await this.objects.getObjectAsync("system.config");
|
|
303
346
|
if (obj?.common.activeRepo && typeof obj.common.activeRepo === "string" && obj.common.activeRepo === repoName || obj?.common.activeRepo && Array.isArray(obj.common.activeRepo) && obj.common.activeRepo.includes(repoName)) {
|
|
@@ -316,6 +359,11 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
316
359
|
}
|
|
317
360
|
}
|
|
318
361
|
}
|
|
362
|
+
/**
|
|
363
|
+
* Set specific repo as active one
|
|
364
|
+
*
|
|
365
|
+
* @param repoName name of the respository to activate
|
|
366
|
+
*/
|
|
319
367
|
async setActive(repoName) {
|
|
320
368
|
const sysRepoObj = await this.objects.getObjectAsync("system.repositories");
|
|
321
369
|
const obj = sysRepoObj || this.defaultSystemRepo;
|
|
@@ -334,6 +382,11 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
334
382
|
}
|
|
335
383
|
}
|
|
336
384
|
}
|
|
385
|
+
/**
|
|
386
|
+
* Set given repo as inactive
|
|
387
|
+
*
|
|
388
|
+
* @param repoName name of the repository
|
|
389
|
+
*/
|
|
337
390
|
async setInactive(repoName) {
|
|
338
391
|
const confObj = await this.objects.getObjectAsync("system.config");
|
|
339
392
|
if (typeof confObj?.common.activeRepo === "string") {
|
|
@@ -347,6 +400,13 @@ Active repo(s): ${activeRepo.join(", ")}`);
|
|
|
347
400
|
await this.objects.setObjectAsync("system.config", confObj);
|
|
348
401
|
}
|
|
349
402
|
}
|
|
403
|
+
/**
|
|
404
|
+
* Renames existing repository if old name and link matches, renaming will not be performed if an repo with the new name already exists
|
|
405
|
+
*
|
|
406
|
+
* @param oldName - name of the current repository
|
|
407
|
+
* @param newName - target name
|
|
408
|
+
* @param repoUrl - hyperlink of the repository
|
|
409
|
+
*/
|
|
350
410
|
async rename(oldName, newName, repoUrl) {
|
|
351
411
|
let repoObj;
|
|
352
412
|
let sysConfigObj;
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/setup/setupRepo.ts"],
|
|
4
4
|
"sourcesContent": ["import { tools, EXIT_CODES } from '@iobroker/js-controller-common';\nimport axios from 'axios';\nimport fs from 'fs-extra';\nimport type { Client as ObjectsRedisClient } from '@iobroker/db-objects-redis';\nimport type { Client as StatesRedisClient } from '@iobroker/db-states-redis';\nimport { isVersionIgnored } from '@/lib/setup/utils.js';\nimport path from 'node:path';\n\nexport interface CLIRepoOptions {\n objects: ObjectsRedisClient;\n states: StatesRedisClient;\n}\n\nexport interface RepoFlags {\n /** Also list not installed adapters */\n a?: boolean;\n all?: boolean;\n /** Only list updatable adapters */\n u?: boolean;\n updatable?: boolean;\n /** Force update even if hash hasn't changed */\n f?: boolean;\n force?: boolean;\n}\n\nexport class Repo {\n private readonly defaultSystemRepo: ioBroker.RepositoryObject;\n private readonly objects: ObjectsRedisClient;\n private readonly states: StatesRedisClient;\n private readonly controllerVersion: string;\n\n constructor(options: CLIRepoOptions) {\n if (!options?.objects) {\n throw new Error('Invalid arguments: objects is missing');\n }\n if (!options?.states) {\n throw new Error('Invalid arguments: states is missing');\n }\n\n const ioPackage = fs.readJSONSync(path.join(tools.getControllerDir(), 'io-package.json'));\n this.controllerVersion = ioPackage.common.version;\n\n this.objects = options.objects;\n this.states = options.states;\n\n this.defaultSystemRepo = {\n common: {\n name: 'System repositories',\n dontDelete: true,\n },\n native: {\n repositories: {\n stable: {\n link: 'http://download.iobroker.net/sources-dist.json',\n json: null,\n },\n beta: {\n link: 'http://download.iobroker.net/sources-dist-latest.json',\n json: null,\n },\n },\n },\n _id: 'system.repositories',\n type: 'config',\n };\n }\n\n /**\n * Update the given repository and returns new repo content\n *\n * @param repoName name of the repository\n * @param force force update even if same hash\n * @param systemConfig content of system.config object\n * @param systemRepos content of system.repositories object\n */\n private async updateRepo(\n repoName: string,\n force: boolean | undefined,\n systemConfig?: ioBroker.OtherObject,\n systemRepos?: ioBroker.RepositoryObject,\n ): Promise<null | ioBroker.RepositoryJson> {\n if (!repoName) {\n const sysConfig = systemConfig || (await this.objects.getObject('system.config'));\n repoName = sysConfig!.common.activeRepo;\n }\n\n const oldRepos = systemRepos || (await this.objects.getObject('system.repositories'));\n if (!oldRepos?.native.repositories?.[repoName]) {\n console.log(`Error: repository \"${repoName}\" not found in the \"system.repositories`);\n return null;\n }\n\n const urlOrPath = oldRepos.native.repositories[repoName].link;\n const hashUrl = urlOrPath.replace(/\\.json$/, '-hash.json');\n let hash;\n\n if (\n !force &&\n oldRepos.native.repositories[repoName].hash &&\n oldRepos.native.repositories[repoName].json &&\n (urlOrPath.startsWith('http://') || urlOrPath.startsWith('https://'))\n ) {\n try {\n hash = await axios({ url: hashUrl, timeout: 10_000 });\n } catch (e) {\n console.error(`Cannot download repository hash file from \"${hashUrl}\": ${e.message}`);\n }\n if (hash?.data && oldRepos.native.repositories[repoName].hash === hash.data.hash) {\n return oldRepos.native.repositories[repoName].json;\n }\n }\n\n let data;\n\n if (urlOrPath.startsWith('http://') || urlOrPath.startsWith('https://')) {\n if (!hash) {\n try {\n hash = await axios({ url: hashUrl, timeout: 10000 });\n } catch (e) {\n console.error(`Cannot download repository hash file from \"${hashUrl}\": ${e.message}`);\n }\n }\n\n const agent = `${tools.appName}, RND: CLI, Node:${process.version}, V:${this.controllerVersion}`;\n try {\n data = await axios({\n url: urlOrPath,\n timeout: 10_000,\n headers: { 'User-Agent': agent },\n });\n if (data.data) {\n data = data.data;\n } else {\n data = null;\n }\n } catch (e) {\n console.error(`Cannot download repository file from \"${urlOrPath}\": ${e.message}`);\n data = null;\n }\n } else {\n if (fs.existsSync(urlOrPath)) {\n try {\n data = JSON.parse(fs.readFileSync(urlOrPath).toString('utf8'));\n } catch (err) {\n console.error(`Error: Cannot read or parse file \"${urlOrPath}\": ${err.message}`);\n }\n } else {\n console.error(`Error: Cannot find file \"${urlOrPath}\"`);\n }\n }\n\n let changed;\n if (data) {\n oldRepos.native.repositories[repoName].json = data;\n changed = true;\n }\n if (hash?.data) {\n oldRepos.native.repositories[repoName].hash = hash.data.hash;\n changed = true;\n }\n if (changed) {\n oldRepos.from = `system.host.${tools.getHostName()}.cli`;\n oldRepos.ts = Date.now();\n await this.objects.setObject('system.repositories', oldRepos);\n }\n\n return oldRepos.native.repositories[repoName].json;\n }\n\n /**\n * Show repo on CLI\n *\n * @param repoUrl url of the repository\n * @param flags CLI flags\n */\n async showRepo(repoUrl: string | string[], flags: RepoFlags): Promise<void> {\n // Get the repositories\n const systemConfig = await this.objects.getObject('system.config');\n const systemRepos = await this.objects.getObject('system.repositories');\n if (!systemConfig) {\n console.error('Error: Object \"system.config\" not found');\n } else if (!systemRepos) {\n console.error('Error: Object \"system.repositories\" not found');\n } else if (!systemRepos.native || !systemRepos.native.repositories) {\n console.error('Error: no repositories found in the \"system.config');\n } else {\n repoUrl = repoUrl || systemConfig.common.activeRepo;\n\n if (!Array.isArray(repoUrl)) {\n repoUrl = [repoUrl];\n }\n\n console.log(`Used ${repoUrl.length > 1 ? 'repositories' : 'repository'}: ${repoUrl.join(', ')}`);\n\n const allSources = {};\n\n for (const url of repoUrl) {\n const repo = systemRepos.native.repositories[url];\n // If known repository\n if (repo) {\n if (typeof repo === 'string') {\n systemRepos.native.repositories[url] = {\n link: repo,\n json: null,\n hash: '',\n };\n }\n\n const sources = await this.updateRepo(url, flags.force || flags.f, systemConfig, systemRepos);\n sources && Object.assign(allSources, sources);\n } else {\n console.error(\n `Error: unknown repository is active - \"${url}\". Known: ${Object.keys(\n systemRepos.native.repositories,\n ).join(', ')}`,\n );\n }\n }\n\n try {\n // update variables of every admin instance\n await this.updateInfo(allSources);\n } catch {\n // not important if fails\n }\n\n return this.showRepoResult(allSources, flags);\n }\n }\n\n /**\n * Show the repo result on CLI\n *\n * @param sources Repo json sources\n * @param flags CLI flags\n */\n private async showRepoResult(sources: Record<string, any>, flags: RepoFlags): Promise<void> {\n const installed = tools.getInstalledInfo();\n const adapters = Object.keys(sources).sort();\n\n for (const name of adapters) {\n let updatable = false;\n let text = sources[name].controller ? 'Controller ' : 'Adapter ';\n text += `\"${name}\"`;\n text = text.padEnd(11 + 15);\n\n if (sources[name].version) {\n text += `: ${sources[name].version}`;\n }\n text = text.padEnd(11 + 15 + 11);\n\n if (!(flags.all || flags.a) && !installed[name]) {\n continue;\n }\n\n if (installed[name]?.version) {\n text += `, installed ${installed[name].version}`;\n try {\n // tools.upToDate can throw if version is invalid\n if (\n sources[name].version !== installed[name].version &&\n sources[name].version &&\n !tools.upToDate(sources[name].version, installed[name].version)\n ) {\n updatable = true;\n text = text.padEnd(11 + 15 + 11 + 18);\n const isIgnored = await isVersionIgnored({\n adapterName: name,\n objects: this.objects,\n version: sources[name].version,\n });\n\n text += isIgnored ? ' [Ignored]' : ' [Updatable]';\n }\n } catch (e) {\n console.error(`Cannot determine update info of \"${name}\": ${e.message}`);\n }\n }\n if ((flags.updatable || flags.u) && !updatable) {\n continue;\n }\n console.log(text);\n }\n }\n\n /**\n * Update Admin info states with number of updates\n *\n * @param sources the repository object\n */\n private async updateInfo(sources: Record<string, any>): Promise<void> {\n const installed = tools.getInstalledInfo();\n const list: string[] = [];\n\n for (const name of Object.keys(sources)) {\n if (installed[name] && installed[name].version && sources[name].version) {\n try {\n // tools.upToDate can throw if version is invalid\n if (\n sources[name].version !== installed[name].version &&\n !tools.upToDate(sources[name].version, installed[name].version)\n ) {\n // remove first part of the name\n const n = name.indexOf('.');\n list.push(n === -1 ? name : name.substring(n + 1));\n }\n } catch (e) {\n console.error(`Cannot determine update info of \"${name}\": ${e.message}`);\n }\n }\n }\n\n const objs = await this.objects.getObjectViewAsync('system', 'instance', {\n startkey: 'system.adapter.admin',\n endkey: 'system.adapter.admin\\u9999',\n });\n\n if (objs?.rows?.length) {\n const listStr = list.join(', ');\n for (const row of objs.rows) {\n if (row?.value?.type === 'instance') {\n await this.states.setState(`${row.id}.info.updatesNumber`, { val: list.length, ack: true });\n await this.states.setState(`${row.id}.info.updatesList`, { val: listStr, ack: true });\n }\n }\n }\n }\n\n /**\n * Show current status of Repo on CLI\n */\n async showRepoStatus(): Promise<number> {\n try {\n const obj = await this.objects.getObject('system.repositories');\n const objCfg = await this.objects.getObject('system.config');\n\n if (!obj) {\n console.error('List is empty');\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n } else if (obj.native.repositories) {\n console.table(\n Object.entries(obj.native.repositories).map(([key, value]) => {\n return {\n name: key,\n url: value.link,\n 'auto upgrade': objCfg?.common.adapterAutoUpgrade?.repositories[key] ?? false,\n };\n }),\n );\n\n if (objCfg?.common) {\n let activeRepo = objCfg.common.activeRepo;\n if (typeof activeRepo === 'string') {\n activeRepo = [activeRepo];\n }\n console.log(`\\nActive repo(s): ${activeRepo.join(', ')}`);\n console.log(`Upgrade policy: ${objCfg.common.adapterAutoUpgrade?.defaultPolicy ?? 'none'}`);\n }\n } else {\n console.error('List is empty');\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n }\n } catch (err) {\n console.error(`Cannot get list: ${err}`);\n }\n return EXIT_CODES.CANNOT_GET_REPO_LIST;\n }\n\n /**\n * Add new repo\n *\n * @param repoName name of new repo\n * @param repoUrl url of new repo\n */\n async add(repoName: string, repoUrl: string): Promise<void> {\n const sysRepoObj = await this.objects.getObjectAsync('system.repositories');\n const obj = sysRepoObj || this.defaultSystemRepo;\n\n if (obj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" yet exists: ${obj.native.repositories[repoName].link}`);\n } else {\n obj.native.repositories[repoName] = {\n link: repoUrl,\n json: null,\n };\n obj.from = `system.host.${tools.getHostName()}.cli`;\n obj.ts = Date.now();\n await this.objects.setObjectAsync('system.repositories', obj);\n }\n }\n\n /**\n * Remove repository from sources\n *\n * @param repoName name of repository to remove\n */\n async del(repoName: string): Promise<void> {\n const obj = await this.objects.getObjectAsync('system.config');\n if (\n (obj?.common.activeRepo &&\n typeof obj.common.activeRepo === 'string' &&\n obj.common.activeRepo === repoName) ||\n (obj?.common.activeRepo && Array.isArray(obj.common.activeRepo) && obj.common.activeRepo.includes(repoName))\n ) {\n throw new Error(`Cannot delete active repository: ${repoName}`);\n } else {\n const repoObj = await this.objects.getObjectAsync('system.repositories');\n if (repoObj) {\n if (!repoObj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" not found.`);\n } else {\n delete repoObj.native.repositories[repoName];\n repoObj.from = `system.host.${tools.getHostName()}.cli`;\n repoObj.ts = Date.now();\n await this.objects.setObject('system.repositories', repoObj);\n }\n }\n }\n }\n\n /**\n * Set specific repo as active one\n *\n * @param repoName name of the respository to activate\n */\n async setActive(repoName: string): Promise<void> {\n const sysRepoObj = await this.objects.getObjectAsync('system.repositories');\n const obj = sysRepoObj || this.defaultSystemRepo;\n\n if (!obj.native.repositories[repoName]) {\n throw new Error(`Repository \"${repoName}\" not found.`);\n } else {\n const confObj = await this.objects.getObjectAsync('system.config');\n if (typeof confObj?.common.activeRepo === 'string') {\n confObj.common.activeRepo = [confObj.common.activeRepo];\n }\n\n if (confObj && !confObj.common.activeRepo.includes(repoName)) {\n confObj.common.activeRepo.push(repoName);\n confObj.from = `system.host.${tools.getHostName()}.cli`;\n confObj.ts = Date.now();\n await this.objects.setObjectAsync('system.config', confObj);\n }\n }\n }\n\n /**\n * Set given repo as inactive\n *\n * @param repoName name of the repository\n */\n async setInactive(repoName: string): Promise<void> {\n const confObj = (await this.objects.getObjectAsync('system.config'))!;\n if (typeof confObj?.common.activeRepo === 'string') {\n confObj.common.activeRepo = [confObj.common.activeRepo];\n }\n\n const pos = confObj.common.activeRepo.indexOf(repoName);\n if (pos !== -1) {\n confObj.common.activeRepo.splice(pos, 1);\n confObj.from = `system.host.${tools.getHostName()}.cli`;\n confObj.ts = Date.now();\n await this.objects.setObjectAsync('system.config', confObj);\n }\n }\n\n /**\n * Renames existing repository if old name and link matches, renaming will not be performed if an repo with the new name already exists\n *\n * @param oldName - name of the current repository\n * @param newName - target name\n * @param repoUrl - hyperlink of the repository\n */\n async rename(oldName: string, newName: string, repoUrl: string): Promise<void> {\n let repoObj;\n let sysConfigObj;\n try {\n sysConfigObj = await this.objects.getObjectAsync('system.config');\n repoObj = await this.objects.getObjectAsync('system.repositories');\n } catch (err) {\n throw new Error(`Could not rename repository \"${oldName}\" to \"${newName}\": ${err.message}`);\n }\n\n if (repoObj && repoObj.native && repoObj.native.repositories) {\n if (\n repoObj.native.repositories[oldName] &&\n repoObj.native.repositories[oldName].link === repoUrl &&\n !repoObj.native.repositories[newName]\n ) {\n repoObj.native.repositories[newName] = repoObj.native.repositories[oldName];\n delete repoObj.native.repositories[oldName];\n\n try {\n await this.objects.setObjectAsync('system.repositories', repoObj);\n console.log(`Renamed repository \"${oldName} to \"${newName}\"`);\n } catch (err) {\n throw new Error(`Could not rename repository \"${oldName}\" to \"${newName}\": ${err.message}`);\n }\n\n // if we changed the name of the activeRepo, we should set newName as active repo\n if (\n sysConfigObj &&\n sysConfigObj.common &&\n ((typeof sysConfigObj.common.activeRepo === 'string' &&\n sysConfigObj.common.activeRepo === oldName) ||\n (Array.isArray(sysConfigObj.common.activeRepo) &&\n sysConfigObj.common.activeRepo.includes(oldName)))\n ) {\n if (typeof sysConfigObj.common.activeRepo === 'string') {\n sysConfigObj.common.activeRepo = [sysConfigObj.common.activeRepo];\n }\n const pos = sysConfigObj.common.activeRepo.indexOf(oldName);\n sysConfigObj.common.activeRepo.splice(pos, 1, newName);\n\n try {\n await this.objects.setObjectAsync('system.config', sysConfigObj);\n } catch (err) {\n throw new Error(`Could not set \"${newName}\" as active repository: ${err.message}`);\n }\n }\n }\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;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AAI,OAAO,EAAE;QAC9F;AAGA,YACI,gBACA,aAAa,WACX,OAAO,aAAa,OAAO,eAAe,YACxC,aAAa,OAAO,eAAe,WAClC,MAAM,QAAQ,aAAa,OAAO,UAAU,KACzC,aAAa,OAAO,WAAW,SAAS,OAAO,IACzD;AACE,cAAI,OAAO,aAAa,OAAO,eAAe,UAAU;AACpD,yBAAa,OAAO,aAAa,CAAC,aAAa,OAAO,UAAU;UACpE;AACA,gBAAM,MAAM,aAAa,OAAO,WAAW,QAAQ,OAAO;AAC1D,uBAAa,OAAO,WAAW,OAAO,KAAK,GAAG,OAAO;AAErD,cAAI;AACA,kBAAM,KAAK,QAAQ,eAAe,iBAAiB,YAAY;UACnE,SAAS,KAAK;AACV,kBAAM,IAAI,MAAM,kBAAkB,OAAO,2BAA2B,IAAI,OAAO,EAAE;UACrF;QACJ;MACJ;IACJ;EACJ;;",
|
|
6
6
|
"names": ["fs", "path", "axios"]
|
|
7
7
|
}
|
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
* MIT License
|
|
7
7
|
*
|
|
8
8
|
*/
|
|
9
|
-
/// <reference types="@iobroker/types-dev" />
|
|
10
9
|
import type { CleanDatabaseHandler, IoPackage, ProcessExitCallback, RestartController } from '../../lib/_Types.js';
|
|
11
10
|
import { EXIT_CODES } from '@iobroker/js-controller-common';
|
|
12
11
|
export interface CLISetupOptions {
|
|
@@ -18,6 +18,10 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
18
|
return to;
|
|
19
19
|
};
|
|
20
20
|
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
21
25
|
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
22
26
|
mod
|
|
23
27
|
));
|
|
@@ -27,6 +31,7 @@ __export(setupSetup_exports, {
|
|
|
27
31
|
Setup: () => Setup
|
|
28
32
|
});
|
|
29
33
|
module.exports = __toCommonJS(setupSetup_exports);
|
|
34
|
+
var __import_meta_url = typeof document === "undefined" ? new (require("url".replace("", ""))).URL("file:" + __filename).href : document.currentScript && document.currentScript.src || new URL("main.js", document.baseURI).href;
|
|
30
35
|
var import_fs_extra = __toESM(require("fs-extra"), 1);
|
|
31
36
|
var import_node_path = __toESM(require("node:path"), 1);
|
|
32
37
|
var import_js_controller_common = require("@iobroker/js-controller-common");
|
|
@@ -43,17 +48,19 @@ var import_constants = require("@iobroker/js-controller-common-db/constants");
|
|
|
43
48
|
var import_setupUpload = require("../../lib/setup/setupUpload.js");
|
|
44
49
|
var import_node_module = require("node:module");
|
|
45
50
|
var url = __toESM(require("node:url"), 1);
|
|
46
|
-
const
|
|
47
|
-
const
|
|
48
|
-
const require2 = (0, import_node_module.createRequire)(import_meta.url || `file://${__filename}`);
|
|
51
|
+
const thisDir = url.fileURLToPath(new URL(".", __import_meta_url || `file://${__filename}`));
|
|
52
|
+
const require2 = (0, import_node_module.createRequire)(__import_meta_url || `file://${__filename}`);
|
|
49
53
|
const COLOR_RED = "\x1B[31m";
|
|
50
54
|
const COLOR_YELLOW = "\x1B[33m";
|
|
51
55
|
const COLOR_RESET = "\x1B[0m";
|
|
52
56
|
const COLOR_GREEN = "\x1B[32m";
|
|
53
57
|
const CONTROLLER_DIR = import_js_controller_common.tools.getControllerDir();
|
|
54
58
|
class Setup {
|
|
59
|
+
/** Object IDs which are not allowed to exist but could be generated due to errors in the past */
|
|
55
60
|
KNOWN_GARBAGE_OBJECT_IDS = ["null", "undefined"];
|
|
61
|
+
/** Adapter core version supported by this js-controller */
|
|
56
62
|
SUPPORTED_ADAPTER_CORE_VERSION = "^3.2.1";
|
|
63
|
+
/** Default name for redis sentinels */
|
|
57
64
|
DEFAULT_SENTINEL_NAME = "mymaster";
|
|
58
65
|
processExit;
|
|
59
66
|
states;
|
|
@@ -132,6 +139,12 @@ class Setup {
|
|
|
132
139
|
console.error(COLOR_RESET);
|
|
133
140
|
}
|
|
134
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Called after io-package objects are created (hence object view functionalities are now available)
|
|
144
|
+
*
|
|
145
|
+
* @param systemConfig the system config object
|
|
146
|
+
* @param callback callback function
|
|
147
|
+
*/
|
|
135
148
|
async setupReady(systemConfig, callback) {
|
|
136
149
|
if (!callback) {
|
|
137
150
|
console.log(`database setup done. You can add adapters and start ${import_js_controller_common.tools.appName} now`);
|
|
@@ -231,6 +244,11 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
231
244
|
return this.setupReady(configObj, callback);
|
|
232
245
|
}
|
|
233
246
|
}
|
|
247
|
+
/**
|
|
248
|
+
* Fix the config object if existing
|
|
249
|
+
*
|
|
250
|
+
* @param configObj the current system.config object
|
|
251
|
+
*/
|
|
234
252
|
async fixConfig(configObj) {
|
|
235
253
|
let configFixed = false;
|
|
236
254
|
if (!configObj) {
|
|
@@ -261,6 +279,12 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
261
279
|
}
|
|
262
280
|
return configFixed;
|
|
263
281
|
}
|
|
282
|
+
/**
|
|
283
|
+
* Creates objects and does object related cleanup
|
|
284
|
+
*
|
|
285
|
+
* @param callback callback function
|
|
286
|
+
* @param checkCertificateOnly if only certificate check is desired
|
|
287
|
+
*/
|
|
264
288
|
async setupObjects(callback, checkCertificateOnly) {
|
|
265
289
|
const { states: _states, objects: _objects } = await (0, import_dbConnection.dbConnectAsync)(false, this.params);
|
|
266
290
|
this.objects = _objects;
|
|
@@ -318,6 +342,12 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
318
342
|
this.dbSetup(iopkg, false, callback);
|
|
319
343
|
}
|
|
320
344
|
}
|
|
345
|
+
/**
|
|
346
|
+
* Asks the user if he wants to migrate objects if it makes sense and performs migration according to input
|
|
347
|
+
*
|
|
348
|
+
* @param newConfig - updated config
|
|
349
|
+
* @param oldConfig - previous config
|
|
350
|
+
*/
|
|
321
351
|
async migrateObjects(newConfig, oldConfig) {
|
|
322
352
|
const oldStatesHasServer = await (0, import_js_controller_common2.statesDbHasServer)(oldConfig.states.type);
|
|
323
353
|
const oldObjectsHasServer = await (0, import_js_controller_common2.statesDbHasServer)(oldConfig.objects.type);
|
|
@@ -764,6 +794,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
764
794
|
const exitCode = await this.migrateObjects(config, originalConfig);
|
|
765
795
|
return exitCode;
|
|
766
796
|
}
|
|
797
|
+
/**
|
|
798
|
+
* Checks if single host setup and if so migrates and activates Redis Sets Usage
|
|
799
|
+
*/
|
|
767
800
|
async _maybeMigrateSets() {
|
|
768
801
|
if (!this.objects) {
|
|
769
802
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -780,6 +813,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
780
813
|
console.warn(`Could not migrate objects to corresponding sets: ${e.message}`);
|
|
781
814
|
}
|
|
782
815
|
}
|
|
816
|
+
/**
|
|
817
|
+
* Ensure that host object exists
|
|
818
|
+
*/
|
|
783
819
|
async _ensureHostObject() {
|
|
784
820
|
if (!this.objects) {
|
|
785
821
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -792,6 +828,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
792
828
|
console.log(`Created host object "${id}"`);
|
|
793
829
|
}
|
|
794
830
|
}
|
|
831
|
+
/**
|
|
832
|
+
* Add adapter-core in supported version in the overrides field of the root package.json and call install there to apply it
|
|
833
|
+
*/
|
|
795
834
|
async addAdapterCoreRequirement() {
|
|
796
835
|
if (import_js_controller_common.tools.isDevInstallation()) {
|
|
797
836
|
return;
|
|
@@ -807,6 +846,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
807
846
|
await import_fs_extra.default.writeFile(packPath, JSON.stringify(packJson));
|
|
808
847
|
console.log(`Successfully specified supported "@iobroker/adapter-core" version as "${this.SUPPORTED_ADAPTER_CORE_VERSION}"`);
|
|
809
848
|
}
|
|
849
|
+
/**
|
|
850
|
+
* Create the adapters object per host if not yet existing
|
|
851
|
+
*/
|
|
810
852
|
async _ensureAdaptersPerHostObject() {
|
|
811
853
|
if (!this.objects) {
|
|
812
854
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -867,6 +909,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
867
909
|
await setupUpload.upgradeAdapterObjects(name);
|
|
868
910
|
}
|
|
869
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Replace the `controller.js` file in the root directory to work with ESM
|
|
914
|
+
*/
|
|
870
915
|
async _fixWindowsControllerJs() {
|
|
871
916
|
const content = `import('./node_modules/iobroker.js-controller/controller.js');`;
|
|
872
917
|
const filePath = import_node_path.default.join(import_js_controller_common.tools.getRootDir(), "controller.js");
|
|
@@ -876,6 +921,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
876
921
|
console.error(`Could not fix "${filePath}": ${e.message}`);
|
|
877
922
|
}
|
|
878
923
|
}
|
|
924
|
+
/**
|
|
925
|
+
* Perform multiple cleanup operations, to clean up inconsistent states due to past bugs or edge case errors
|
|
926
|
+
*/
|
|
879
927
|
async _cleanupInstallation() {
|
|
880
928
|
console.log("Clean up binary states ...");
|
|
881
929
|
try {
|
|
@@ -908,6 +956,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
908
956
|
console.error(`Cannot clean up objects and states with forbidden IDs: ${e.message}`);
|
|
909
957
|
}
|
|
910
958
|
}
|
|
959
|
+
/**
|
|
960
|
+
* Cleanup adapter objects from already removed adapters, which are still there due to errors or past bugs
|
|
961
|
+
*/
|
|
911
962
|
async _cleanupLeftoverAdapters() {
|
|
912
963
|
if (!this.objects) {
|
|
913
964
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -940,6 +991,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
940
991
|
}
|
|
941
992
|
}
|
|
942
993
|
}
|
|
994
|
+
/**
|
|
995
|
+
* Cleanup all states and objects which contain forbidden chars in their id
|
|
996
|
+
*/
|
|
943
997
|
async _cleanupForbiddenIds() {
|
|
944
998
|
if (!this.objects) {
|
|
945
999
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -966,6 +1020,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
966
1020
|
}
|
|
967
1021
|
}
|
|
968
1022
|
}
|
|
1023
|
+
/**
|
|
1024
|
+
* Cleanup objects which are known to be created on accident in the past by adapters or controller
|
|
1025
|
+
*/
|
|
969
1026
|
async _cleanupGarbageObjects() {
|
|
970
1027
|
if (!this.objects) {
|
|
971
1028
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -978,6 +1035,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
978
1035
|
}
|
|
979
1036
|
}
|
|
980
1037
|
}
|
|
1038
|
+
/**
|
|
1039
|
+
* Removes all binary state related objects and states
|
|
1040
|
+
*/
|
|
981
1041
|
async _cleanupBinaryStates() {
|
|
982
1042
|
if (!this.objects) {
|
|
983
1043
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -1011,6 +1071,9 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
1011
1071
|
}
|
|
1012
1072
|
}
|
|
1013
1073
|
}
|
|
1074
|
+
/**
|
|
1075
|
+
* Removes non-existing users from groups
|
|
1076
|
+
*/
|
|
1014
1077
|
async _cleanupInvalidGroupAssignments() {
|
|
1015
1078
|
if (!this.objects) {
|
|
1016
1079
|
throw new Error("Objects not set up, call setupObjects first");
|
|
@@ -1039,6 +1102,11 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
1039
1102
|
}
|
|
1040
1103
|
}
|
|
1041
1104
|
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Setup the installation with config file, host object, scripts etc
|
|
1107
|
+
*
|
|
1108
|
+
* @param options setup options
|
|
1109
|
+
*/
|
|
1042
1110
|
setup(options) {
|
|
1043
1111
|
const { ignoreIfExist, useRedis, callback } = options;
|
|
1044
1112
|
let config;
|
|
@@ -1065,10 +1133,16 @@ Please DO NOT copy files manually into ioBroker storage directories!`);
|
|
|
1065
1133
|
require('${import_node_path.default.normalize(`${thisDir}/..`)}/setup').execute();`;
|
|
1066
1134
|
try {
|
|
1067
1135
|
if (import_fs_extra.default.existsSync(import_node_path.default.join(CONTROLLER_DIR, "killall.sh"))) {
|
|
1068
|
-
import_fs_extra.default.writeFileSync(import_node_path.default.join(CONTROLLER_DIR, "..", "..", "killall.sh"), import_fs_extra.default.readFileSync(import_node_path.default.join(CONTROLLER_DIR, "killall.sh")), {
|
|
1136
|
+
import_fs_extra.default.writeFileSync(import_node_path.default.join(CONTROLLER_DIR, "..", "..", "killall.sh"), import_fs_extra.default.readFileSync(import_node_path.default.join(CONTROLLER_DIR, "killall.sh")), {
|
|
1137
|
+
mode: 492
|
|
1138
|
+
/* 0754 */
|
|
1139
|
+
});
|
|
1069
1140
|
}
|
|
1070
1141
|
if (import_fs_extra.default.existsSync(import_node_path.default.join(CONTROLLER_DIR, "reinstall.sh"))) {
|
|
1071
|
-
import_fs_extra.default.writeFileSync(import_node_path.default.join(CONTROLLER_DIR, "..", "..", "reinstall.sh"), import_fs_extra.default.readFileSync(import_node_path.default.join(CONTROLLER_DIR, "reinstall.sh")), {
|
|
1142
|
+
import_fs_extra.default.writeFileSync(import_node_path.default.join(CONTROLLER_DIR, "..", "..", "reinstall.sh"), import_fs_extra.default.readFileSync(import_node_path.default.join(CONTROLLER_DIR, "reinstall.sh")), {
|
|
1143
|
+
mode: 492
|
|
1144
|
+
/* 0754 */
|
|
1145
|
+
});
|
|
1072
1146
|
}
|
|
1073
1147
|
if (!import_fs_extra.default.existsSync(import_node_path.default.join(CONTROLLER_DIR, "..", "..", `${import_js_controller_common.tools.appName.substring(0, 3)}`))) {
|
|
1074
1148
|
import_fs_extra.default.writeFileSync(import_node_path.default.join(CONTROLLER_DIR, "..", "..", `${import_js_controller_common.tools.appName.substring(0, 3)}`), startFile, {
|