1- import { execFileSync , execSync } from 'node:child_process' ;
2- import { chownSync , existsSync , mkdirSync , unlinkSync , writeFileSync } from 'node:fs' ;
3- import { UserInfo , userInfo } from 'node:os' ;
1+ import { execFileSync } from 'node:child_process' ;
2+ import { existsSync , unlinkSync , writeFileSync } from 'node:fs' ;
43import { resolve } from 'node:path' ;
54import process from 'node:process' ;
65
@@ -9,29 +8,24 @@ import { PlatformCommands } from './platform.js';
98export class MacPlatform extends PlatformCommands {
109 #plist = '/Library/LaunchDaemons/com.matterbridge.plist' ;
1110
12- install ( ) : void {
11+ install ( args : string [ ] ) : void {
1312 this . checkRoot ( ) ;
14- const matterbridgePath = this . checkMatterbridgeInstalled ( ) ;
15- const userInfo = this . #getUserInfo( ) ;
16-
17- // Create Matterbridge Plugin and Storage directories
18- const matterbridgePluginPath = resolve ( userInfo . homedir , 'Matterbridge' ) ;
19- this . #mkdirPath( matterbridgePluginPath , userInfo ) ;
20-
21- const matterbridgeStoragePath = resolve ( userInfo . homedir , '.matterbridge' ) ;
22- this . #mkdirPath( matterbridgeStoragePath , userInfo ) ;
13+ const matterbridgeBinPath = this . checkMatterbridgeInstalled ( ) ;
14+ const matterbridgeStoragePath = this . mkdirMatterbridgePaths ( ) ;
15+ const userInfo = this . getUserInfo ( ) ;
2316
2417 // Check NPM global modules path permissions and change if necessary
25- const npmGlobalModulesPath = execSync ( 'eval echo "$(npm prefix -g --silent)/lib/node_modules"' ) . toString ( ) . trim ( ) ;
18+ const npmGlobalPrefix = execFileSync ( 'npm' , [ 'prefix' , '-g' , '--silent' ] ) . toString ( ) . trim ( ) ;
19+ const npmGlobalModulesPath = resolve ( npmGlobalPrefix , 'lib' , 'node_modules' ) ;
2620 try {
27- execSync ( `eval test -w " ${ npmGlobalModulesPath } "` , {
21+ execFileSync ( ' test' , [ '-w' , npmGlobalModulesPath ] , {
2822 uid : userInfo . uid ,
2923 gid : userInfo . gid
3024 } ) ;
3125 }
3226 catch {
3327 try {
34- execSync ( ` chown -R ${ userInfo . uid } :${ userInfo . gid } " ${ npmGlobalModulesPath } "` ) ;
28+ execFileSync ( ' chown' , [ '-R' , ` ${ userInfo . uid } :${ userInfo . gid } ` , npmGlobalModulesPath ] ) ;
3529 }
3630 catch {
3731 console . error ( 'User not able to write to the NPM Global Modules Path!' ) ;
@@ -50,8 +44,8 @@ export class MacPlatform extends PlatformCommands {
5044 ` <string>com.matterbridge</string>` ,
5145 ' <key>ProgramArguments</key>' ,
5246 ' <array>' ,
53- ` <string>${ matterbridgePath } </string>` ,
54- ` <string>-service </string>` ,
47+ ` <string>${ matterbridgeBinPath } </string>` ,
48+ ... args . map ( arg => ` <string>${ arg } </string>` ) ,
5549 ' </array>' ,
5650 ' <key>KeepAlive</key>' ,
5751 ' <true/>' ,
@@ -77,7 +71,7 @@ export class MacPlatform extends PlatformCommands {
7771 writeFileSync ( this . #plist, plistFileContents ) ;
7872 console . info ( 'Matterbridge Service Installed!' ) ;
7973 this . start ( ) ;
80- this . postinstall ( ) ;
74+ this . postinstall ( args ) ;
8175 }
8276
8377 uninstall ( ) : void {
@@ -129,30 +123,11 @@ export class MacPlatform extends PlatformCommands {
129123 }
130124
131125 tail ( ) : void {
132- const matterbridgeStoragePath = resolve ( this . # getUserInfo( ) . homedir , '.matterbridge' ) ;
126+ const matterbridgeStoragePath = resolve ( this . getUserInfo ( ) . homedir , '.matterbridge' ) ;
133127 execFileSync ( 'tail' , [ '-f' , '-n' , '32' , `${ matterbridgeStoragePath } /matterbridge.log` ] , { stdio : 'inherit' } ) ;
134128 }
135129
136130 #checkServiceInstalled( ) : void {
137131 super . checkServiceInstalled ( this . #plist) ;
138132 }
139-
140- #getUserInfo( ) : UserInfo < string > {
141- if ( process . env . SUDO_USER && process . env . SUDO_UID && process . env . SUDO_GID ) {
142- return {
143- username : process . env . SUDO_USER ,
144- uid : Number . parseInt ( process . env . SUDO_UID ) ,
145- gid : Number . parseInt ( process . env . SUDO_GID ) ,
146- shell : null ,
147- homedir : execSync ( `eval echo ~"${ process . env . SUDO_USER } "` ) . toString ( ) . trim ( )
148- } ;
149- }
150-
151- return userInfo ( ) ;
152- }
153-
154- #mkdirPath( path : string , userInfo : UserInfo < string > ) : void {
155- mkdirSync ( path , { recursive : true } ) ;
156- chownSync ( path , userInfo . uid , userInfo . gid ) ;
157- }
158133}
0 commit comments