Skip to content

Commit

Permalink
revert checks (#1579)
Browse files Browse the repository at this point in the history
revert the ui version checks for a less harsh release
  • Loading branch information
bwp91 authored Oct 7, 2023
1 parent 310f2c9 commit 7b61be3
Show file tree
Hide file tree
Showing 16 changed files with 472 additions and 318 deletions.
332 changes: 163 additions & 169 deletions package-lock.json

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,17 @@
"@fastify/helmet": "11.1.1",
"@fastify/multipart": "8.0.0",
"@fastify/static": "6.11.2",
"@fastify/swagger": "8.10.1",
"@fastify/swagger": "8.11.0",
"@homebridge/node-pty-prebuilt-multiarch": "0.10.1-pre.6",
"@nestjs/axios": "3.0.0",
"@nestjs/common": "10.2.6",
"@nestjs/core": "10.2.6",
"@nestjs/common": "10.2.7",
"@nestjs/core": "10.2.7",
"@nestjs/jwt": "10.1.1",
"@nestjs/passport": "10.0.2",
"@nestjs/platform-fastify": "10.2.6",
"@nestjs/platform-socket.io": "10.2.6",
"@nestjs/swagger": "7.1.12",
"@nestjs/websockets": "10.2.6",
"@nestjs/platform-fastify": "10.2.7",
"@nestjs/platform-socket.io": "10.2.7",
"@nestjs/swagger": "7.1.13",
"@nestjs/websockets": "10.2.7",
"@oznu/hap-client": "1.9.0",
"axios": "1.5.1",
"class-transformer": "0.5.1",
Expand All @@ -83,23 +83,23 @@
"reflect-metadata": "0.1.13",
"rxjs": "7.8.1",
"semver": "7.5.4",
"systeminformation": "5.21.9",
"systeminformation": "5.21.11",
"tail": "2.2.6",
"tar": "6.2.0",
"tcp-port-used": "1.0.2",
"unzipper": "0.10.14"
},
"devDependencies": {
"@nestjs/testing": "^10.2.6",
"@nestjs/testing": "^10.2.7",
"@types/fs-extra": "^9.0.13",
"@types/jest": "^29.5.5",
"@types/node": "^18.18.1",
"@types/node-schedule": "^2.1.1",
"@types/semver": "7.5.3",
"@types/tar": "^6.1.6",
"@types/unzipper": "^0.10.7",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"babel-jest": "^29.7.0",
"bash-color": "^0.0.4",
"buffer-shims": "^1.0.0",
Expand Down
25 changes: 19 additions & 6 deletions src/bin/hb-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -426,9 +426,20 @@ export class HomebridgeServiceHelper {
return;
}

// allow the --strict-plugin-resolution flag on Homebridge v1.4.1 or later only (check removed in UI 5.0)
if (!this.homebridgeOpts.includes('--strict-plugin-resolution')) {
this.homebridgeOpts.push('--strict-plugin-resolution');
// allow the --strict-plugin-resolution flag on Homebridge v1.4.1 or later only
if (
this.homebridgePackage &&
process.env.UIX_STRICT_PLUGIN_RESOLUTION === '1' &&
semver.gte(this.homebridgePackage.version, '1.4.1-beta.1')
) {
if (!this.homebridgeOpts.includes('--strict-plugin-resolution')) {
this.homebridgeOpts.push('--strict-plugin-resolution');
}
} else if (process.env.UIX_STRICT_PLUGIN_RESOLUTION === '1') {
const strictPluginIndex = this.homebridgeOpts.indexOf('--strict-plugin-resolution');
if (strictPluginIndex > -1) {
this.homebridgeOpts.splice(strictPluginIndex, 1);
}
}

if (this.homebridgeOpts.length) {
Expand Down Expand Up @@ -1081,9 +1092,11 @@ export class HomebridgeServiceHelper {
this.homebridgeOpts.push('-D');
}

// check if keep orphans should be enabled, only for Homebridge v1.0.2 and later (check removed in UI 5.0)
if (homebridgeStartupOptions.keepOrphans && !this.homebridgeOpts.includes('-K')) {
this.homebridgeOpts.push('-K');
// check if keep orphans should be enabled, only for Homebridge v1.0.2 and later
if (this.homebridgePackage && semver.gte(this.homebridgePackage.version, '1.0.2')) {
if (homebridgeStartupOptions.keepOrphans && !this.homebridgeOpts.includes('-K')) {
this.homebridgeOpts.push('-K');
}
}

// insecure mode is enabled by default, allow it to be removed if set to false
Expand Down
3 changes: 3 additions & 0 deletions src/core/config/config.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as os from 'os';
import * as path from 'path';
import * as fs from 'fs-extra';
import * as crypto from 'crypto';
import * as semver from 'semver';
import * as _ from 'lodash';

export interface HomebridgeConfig {
Expand Down Expand Up @@ -64,6 +65,7 @@ export class ConfigService {

// docker settings
public startupScript = path.resolve(this.storagePath, 'startup.sh');
public dockerOfflineUpdate = this.runningInDocker && semver.satisfies(process.env.CONFIG_UI_VERSION, '>=4.6.2 <=4.44.1', { includePrerelease: true });

// package.json
public package = fs.readJsonSync(path.resolve(process.env.UIX_BASE_PATH, 'package.json'));
Expand Down Expand Up @@ -208,6 +210,7 @@ export class ConfigService {
runningInFreeBSD: this.runningInFreeBSD,
runningOnRaspberryPi: this.runningOnRaspberryPi,
canShutdownRestartHost: this.canShutdownRestartHost,
dockerOfflineUpdate: this.dockerOfflineUpdate,
serviceMode: this.serviceMode,
temperatureUnits: this.ui.tempUnits || 'c',
lang: this.ui.lang === 'auto' ? null : this.ui.lang,
Expand Down
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import * as path from 'path';
import * as child_process from 'child_process';
import * as commander from 'commander';
import * as semver from 'semver';

let homebridge;

Expand Down Expand Up @@ -34,10 +35,17 @@ class HomebridgeConfigUi {
.option('-T, --no-timestamp', '', () => process.env.UIX_LOG_NO_TIMESTAMPS = '1')
.parse(process.argv);

if (!semver.satisfies(process.version, '>=10.17.0')) {
const msg = `Node.js v10.17.0 higher is required. You may experience issues running this plugin running on ${process.version}.`;
log.error(msg);
log.warn(msg);
}

if (process.env.UIX_SERVICE_MODE === '1' && process.connected) {
this.log('Running in Service Mode');
return;
} else if (config.standalone || process.env.UIX_SERVICE_MODE === '1') {
} else if (config.standalone || process.env.UIX_SERVICE_MODE === '1' ||
(process.env.HOMEBRIDGE_CONFIG_UI === '1' && semver.satisfies(process.env.CONFIG_UI_VERSION, '>=3.5.5', { includePrerelease: true }))) {
this.log.warn('*********** Homebridge Standalone Mode Is Depreciated **********');
this.log.warn('* Please swap to "service mode" using the hb-service command. *');
this.log.warn('* See https://homebridge.io/w/JUvQr for instructions on how to migrate. *');
Expand Down
16 changes: 12 additions & 4 deletions src/modules/child-bridges/child-bridges.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import * as semver from 'semver';

import { Logger } from '../../core/logger/logger.service';
import { ConfigService } from '../../core/config/config.service';
Expand Down Expand Up @@ -30,10 +31,10 @@ export class ChildBridgesService {
}

/**
* Socket Handler - Per Client
* Start watching for child bridge status events
* @param client
*/
* Socket Handler - Per Client
* Start watching for child bridge status events
* @param client
*/
public async watchChildBridgeStatus(client) {
const listener = (data) => {
client.emit('child-bridge-status-update', data);
Expand All @@ -59,6 +60,13 @@ export class ChildBridgesService {
* @returns
*/
public stopStartRestartChildBridge(event: 'startChildBridge' | 'stopChildBridge' | 'restartChildBridge', deviceId: string) {
if (['startChildBridge', 'stopChildBridge'].includes(event)) {
if (!semver.satisfies(this.configService.homebridgeVersion, '>=1.5.0-beta.2', { includePrerelease: true })) {
this.logger.error('The stop child bridge requires Homebridge v1.5.0 or later');
throw new BadRequestException('This command is only available for Homebridge v1.5.0 or later');
}
}

if (!this.configService.serviceMode) {
this.logger.error('The restart child bridge command is only available in service mode');
throw new BadRequestException('This command is only available in service mode');
Expand Down
39 changes: 37 additions & 2 deletions src/modules/plugins/plugins.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,12 @@ export class PluginsService {
throw new Error(`Cannot uninstall ${pluginAction.name} from ${this.configService.name}.`);
}

// legacy support for offline docker updates
if (pluginAction.name === this.configService.name && this.configService.dockerOfflineUpdate && pluginAction.version === 'latest') {
await this.updateSelfOffline(client);
return true;
}

// convert 'latest' into a real version
if (action === 'install' && pluginAction.version === 'latest') {
pluginAction.version = await this.getNpmModuleLatestVersion(pluginAction.name);
Expand Down Expand Up @@ -472,6 +478,20 @@ export class PluginsService {

const homebridgeVersion = semver.parse(homebridge.installedVersion);

// patch for homebridge 1.2.x to allow updates to newer versions of 1.2.x without 1.2.x being set to "latest"
if (
homebridgeVersion.major === 1 &&
homebridgeVersion.minor === 2 &&
semver.gt(homebridge.installedVersion, homebridge.latestVersion)
) {
const versions = await this.getAvailablePluginVersions('homebridge');
if (versions.tags['release-1.2.x'] && semver.gt(versions.tags['release-1.2.x'], homebridge.installedVersion)) {
homebridge.updateAvailable = true;
homebridge.latestVersion = versions.tags['release-1.2.x'];
}
}
// end patch

// show beta updates if the user is currently running a beta release
if (
homebridgeVersion.prerelease[0] === 'beta' &&
Expand Down Expand Up @@ -518,6 +538,22 @@ export class PluginsService {
installOptions.push('-g');
}

// 1.2.x -> 1.3.0 upgrade set ciao as bridge advertiser
if (homebridge.installedVersion && homebridgeUpdateAction.version) {
const installedVersion = semver.parse(homebridge.installedVersion);
const targetVersion = semver.parse(homebridgeUpdateAction.version);
if (installedVersion.minor === 2 && targetVersion.minor > 2) {
try {
const config: HomebridgeConfig = await fs.readJson(this.configService.configPath);
config.bridge.advertiser = 'ciao';
await fs.writeJsonSync(this.configService.configPath, config);
} catch (e) {
this.logger.warn('Could not update config.json', e.message);
}
}
}
// end 1.2.x -> 1.3.0 upgrade

await this.runNpmCommand(
[...this.npm, 'install', ...installOptions, `${homebridge.name}@${homebridgeUpdateAction.version}`],
installPath,
Expand Down Expand Up @@ -548,7 +584,7 @@ export class PluginsService {
const npm = await this.parsePackageJson(pjson, npmPkg.path) as HomebridgePlugin & { showUpdateWarning?: boolean };

// show the update warning if the installed version is below the minimum recommended
npm.showUpdateWarning = semver.lt(npm.installedVersion, '9.8.1');
npm.showUpdateWarning = semver.lt(npm.installedVersion, '6.4.1');

this.npmPackage = npm;
return npm;
Expand Down Expand Up @@ -1380,5 +1416,4 @@ export class PluginsService {
}, 60000);
}
}

}
7 changes: 3 additions & 4 deletions src/modules/status/status.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,8 @@ export class StatusService {

client.emit('homebridge-status', await this.getHomebridgeStats());

// ipc status events are only available in Homebridge 1.3.3 or later (check removed in UI 5.0) - and when running in service mode
if (this.configService.serviceMode) {
// ipc status events are only available in Homebridge 1.3.3 or later - and when running in service mode
if (this.configService.serviceMode && this.configService.homebridgeVersion && semver.gt(this.configService.homebridgeVersion, '1.3.3-beta.5')) {
homebridgeStatusChangeSub = this.homebridgeStatusChange.subscribe(async (status) => {
client.emit('homebridge-status', await this.getHomebridgeStats());
});
Expand Down Expand Up @@ -332,7 +332,7 @@ export class StatusService {
* Check if homebridge is running on the local system
*/
public async checkHomebridgeStatus() {
if (this.configService.serviceMode) {
if (this.configService.serviceMode && this.configService.homebridgeVersion && semver.gt(this.configService.homebridgeVersion, '1.3.3-beta.5')) {
return this.homebridgeStatus;
}

Expand All @@ -359,7 +359,6 @@ export class StatusService {
}

const defaultInterfaceName = await si.networkInterfaceDefault();

// These ts-ignore should be able to be removed in the next major release of 'systeminformation' (v6)
// See https://github.com/sebhildebrandt/systeminformation/issues/775#issuecomment-1741836906
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
Expand Down
64 changes: 64 additions & 0 deletions test/e2e/plugins.gateway.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,70 @@ describe('PluginsGateway (e2e)', () => {
expect(client.emit).toHaveBeenCalledWith('stdout', expect.stringContaining('Operation succeeded!'));
});

it('ON /plugins/homebridge-update (1.2.x -> 1.3.x)', async () => {
// mock get homebridge package
pluginsService.getHomebridgePackage = async () => {
return {
name: 'homebridge',
private: false,
publicPackage: true,
installPath: pluginsPath,
latestVersion: '1.3.0',
installedVersion: '1.2.5'
};
};

jest.spyOn(nodePtyService, 'spawn')
.mockImplementation(() => {
const term = new EventEmitter();
setTimeout(() => {
term.emit('exit', 0);
}, 10);
return term;
});

const writeJsonMock = jest.spyOn(fs, 'writeJsonSync');

try {
await pluginsGateway.homebridgeUpdate(client, { version: 'latest' });
} catch (e) { }

// the save config method should have been called
expect(writeJsonMock).toHaveBeenCalled();
});

it('ON /plugins/homebridge-update (1.1.x -> 1.3.x)', async () => {
// mock get homebridge package
pluginsService.getHomebridgePackage = async () => {
return {
name: 'homebridge',
private: false,
publicPackage: true,
installPath: pluginsPath,
latestVersion: '1.3.0',
installedVersion: '1.1.7'
};
};

jest.spyOn(nodePtyService, 'spawn')
.mockImplementation(() => {
const term = new EventEmitter();
setTimeout(() => {
term.emit('exit', 0);
}, 10);
return term;
});

const writeJsonMock = jest.spyOn(fs, 'writeJsonSync');

try {
await pluginsGateway.homebridgeUpdate(client, { version: 'latest' });
} catch (e) { }

// the save config method should not have been called
expect(writeJsonMock).not.toHaveBeenCalled();
});

afterAll(async () => {
await app.close();
});
Expand Down
Loading

0 comments on commit 7b61be3

Please sign in to comment.