2020-08-15 21:49:15 +03:00
const VERSION = "1.5"
2019-11-16 15:11:38 +03:00
function Component ( )
{
generateTr ( ) ;
}
function generateTr ( ) {
2020-08-15 22:05:26 +03:00
component . setValue ( "DisplayName" , qsTr ( "CQtDeployer " + VERSION + " Alpha" ) ) ;
component . setValue ( "Description" , qsTr ( "This package contains CQtDeployer version " + VERSION + " Do not use this version because it is unstable and may lead to unwanted bugs or consequences. Use this version exclusively for testing new functionality." ) ) ;
2019-11-16 15:11:38 +03:00
}
Component . prototype . createOperations = function ( )
{
// // call default implementation to actually install README.txt!
component . createOperations ( ) ;
systemIntegration ( ) ;
}
2020-03-20 12:40:38 +03:00
function stripPath ( path , separator ) {
const array = path . split ( separator ) ;
let newPath = [ ] ;
array . forEach ( function ( item ) {
if ( ! newPath . includes ( item ) ) {
newPath . push ( item ) ;
}
} ) ;
return newPath . join ( separator ) ;
}
function stripWinPath ( path ) {
return stripPath ( path , ';' ) ;
}
function stripUnixPath ( path ) {
return stripPath ( path , ':' ) ;
}
2020-05-06 13:35:13 +03:00
function extractFileName ( path ) {
const fullName = path . substring ( path . lastIndexOf ( '/' ) + 1 ) ;
const index = fullName . lastIndexOf ( '.' ) ;
if ( index >= 0 ) {
return fullName . substring ( 0 , index )
}
return fullName ;
}
2020-05-06 14:43:23 +03:00
function generateShortCutCmd ( cmd , icon ) {
2020-05-06 13:35:13 +03:00
if ( systemInfo . kernelType === "winnt" ) {
console . log ( "create icons!!! on Windows" ) ;
component . addOperation ( "CreateShortcut" ,
"@TargetDir@/" + cmd ,
"@DesktopDir@/" + extractFileName ( cmd ) + ".lnk" ) ;
}
if ( systemInfo . kernelType === "linux" ) {
console . log ( "create icons!!! on LINUX" ) ;
const name = extractFileName ( cmd ) ;
component . addOperation ( "CreateDesktopEntry" ,
"@HomeDir@/.local/share/applications/" + name + ".desktop" ,
" Version = @ Version @ \ n
Type = Application \ n
Terminal = true \ n
Exec = @ TargetDir @ / " + cmd + " . sh \ n
Name = " + name + " \ n
2020-05-06 14:43:23 +03:00
Icon = @ TargetDir @ / " + icon + " \ n
2020-05-06 13:35:13 +03:00
Name [ en _US ] = " + name ) ;
console . log ( "create icons!!! on LINUX done" ) ;
}
}
2019-11-16 15:11:38 +03:00
function systemIntegration ( ) {
targetDir = installer . value ( "TargetDir" , "" ) ;
homeDir = installer . value ( "HomeDir" , "" ) ;
console . log ( "install component" )
console . log ( "targetDir " + targetDir )
console . log ( "hometDir " + homeDir )
if ( systemInfo . kernelType === "winnt" ) {
2020-03-17 19:38:09 +03:00
component . addOperation ( 'EnvironmentVariable' ,
[
"cqtdeployer" ,
2021-05-03 17:07:05 +03:00
targetDir + "\\" + VERSION + "\\cqtdeployer.bat"
2020-03-17 19:38:09 +03:00
]
)
2020-03-19 21:43:43 +03:00
component . addOperation ( 'EnvironmentVariable' ,
2020-03-17 19:38:09 +03:00
[
2020-03-19 21:43:43 +03:00
"cqtDir" ,
2021-05-03 17:07:05 +03:00
targetDir + "\\" + VERSION + "\\"
2020-03-17 19:38:09 +03:00
]
)
2020-03-10 15:56:23 +03:00
2020-03-20 12:40:38 +03:00
let PATH = installer . environmentVariable ( "PATH" ) ;
2020-03-20 19:38:04 +03:00
const cqtDir = installer . environmentVariable ( "cqtDir" ) ;
2020-03-20 12:40:38 +03:00
console . log ( "path befor strip : " + PATH ) ;
2020-03-19 21:43:43 +03:00
2020-03-20 19:38:04 +03:00
if ( ! PATH . includes ( cqtDir ) || ! cqtDir . length ) {
2020-03-20 12:40:38 +03:00
PATH = stripWinPath ( PATH ) ;
console . log ( "path after strip : " + PATH ) ;
2020-03-19 21:43:43 +03:00
2020-03-20 18:06:27 +03:00
component . addOperation ( 'Execute' , [ "SETX" , "PATH" , PATH + ";%cqtDir%" ] )
2020-03-20 12:40:38 +03:00
}
2020-03-19 21:43:43 +03:00
2019-11-16 15:11:38 +03:00
} else {
if ( ! installer . fileExists ( homeDir + "/.local/bin" ) ) {
2019-12-10 12:08:54 +03:00
component . addOperation ( 'Execute' , [ "mkdir" , "-p" , homeDir + "/.local/bin" ] )
2019-11-16 15:11:38 +03:00
QMessageBox [ "warning" ] ( qsTr ( "install in system" ) , qsTr ( "Installer" ) ,
qsTr ( "The \"~/local/bin\" folder was not initialized, you may need to reboot to work correctly!" ) ,
QMessageBox . Ok ) ;
2020-03-13 20:09:17 +03:00
const ansver = installer . execute ( 'cat' , [ homeDir + "/.profile" ] ) ;
2020-03-14 19:29:10 +03:00
let result ;
2019-12-10 12:08:54 +03:00
if ( ansver . length >= 2 ) {
result = ansver [ 0 ] ;
}
if ( ! result . includes ( "/.local/bin" ) ) {
2020-03-13 20:09:17 +03:00
const script = '\n# set PATH so it includes users private bin if it exists (generated by cqtdeployer installer) \n' +
2019-12-10 12:08:54 +03:00
'if [ -d "$HOME/.local/bin" ] ; then \n' +
' PATH="$HOME/.local/bin:$PATH" \n' +
'fi \n' ;
component . addOperation ( 'AppendFile' , [ homeDir + "/.profile" , script ] )
}
2019-11-16 15:11:38 +03:00
}
component . addOperation ( 'Execute' , [ "ln" , "-sf" , targetDir + "/" + VERSION + "/cqtdeployer.sh" ,
homeDir + "/.local/bin/cqtdeployer" ] ,
"UNDOEXECUTE" , [ "rm" , "-f" , homeDir + "/.local/bin/cqtdeployer" ] )
2020-03-10 10:10:24 +03:00
component . addOperation ( 'Execute' , [ "ln" , "-sf" , targetDir + "/" + VERSION + "/cqt.sh" ,
homeDir + "/.local/bin/cqt" ] ,
"UNDOEXECUTE" , [ "rm" , "-f" , homeDir + "/.local/bin/cqt" ] )
2020-03-10 15:45:49 +03:00
component . addOperation ( 'Execute' , [ "ln" , "-sf" , targetDir + "/" + VERSION + "/cqt.sh" ,
homeDir + "/.local/bin/cqtdeployer.cqt" ] ,
"UNDOEXECUTE" , [ "rm" , "-f" , homeDir + "/.local/bin/cqtdeployer.cqt" ] )
2020-05-06 14:43:23 +03:00
generateShortCutCmd ( VERSION + "/cqtdeployer" , VERSION + "/icon.png" ) ;
2020-05-06 13:35:13 +03:00
2019-11-16 15:11:38 +03:00
}
}