163 lines
5.3 KiB
JavaScript
Raw Normal View History

2020-03-12 18:09:06 +03:00
const VERSION = "1.4"
2019-11-16 15:11:38 +03:00
function Component()
{
generateTr();
2020-01-22 10:23:17 +03:00
component.addDependency("QIF");
2019-11-16 15:11:38 +03:00
}
function generateTr() {
component.setValue("DisplayName", qsTr("CQtDeployer " + VERSION));
component.setValue("Description", qsTr("This package contains CQtDeployer version " + VERSION));
}
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;
}
function generateShortCutCmd(cmd) {
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
Icon=@TargetDir@/$LOCAL_ICON\n
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",
2020-03-19 21:43:43 +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",
"\"" + targetDir + "\\" + VERSION + "\\\""
2020-03-17 19:38:09 +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"] )
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:22:26 +03:00
generateShortCutCmd(VERSION + "/cqtdeployer");
2020-05-06 13:35:13 +03:00
2019-11-16 15:11:38 +03:00
}
}