Skip to content

Commit

Permalink
Change install dir to Program Files (#209)
Browse files Browse the repository at this point in the history
* Bumping .NET version
* Using only the "Program files" folder
  • Loading branch information
amitkanfer authored Nov 17, 2023
1 parent c3d2d42 commit f8c4ece
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 77 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,8 @@ src/.idea/

# Test cmd files
src/*.cmd

# Executable Artifacts
src/*.exe
src/*.pdb
src/*.dll
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "3.1.408"
"version": "6.0.319"
}
}
2 changes: 1 addition & 1 deletion src/build/ElastiBuild.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>ElastiBuild</RootNamespace>
</PropertyGroup>

Expand Down
10 changes: 7 additions & 3 deletions src/build/Properties/launchSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,15 @@
"commandLineArgs": "build --cid 7.5 winlogbeat --cert-file C:\\staging\\cert\\stack-elastic-installers-sha.pfx --cert-pass C:\\staging\\cert\\stack-elastic-installers-sha-password.txt",
"workingDirectory": "$(SolutionDir)"
},

"Winlogbeat 8.0": {
"commandName": "Project",
"commandLineArgs": "build --cid 8.0-SNAPSHOT winlogbeat",
"commandLineArgs": "build --cid 8.11.0 winlogbeat",
"workingDirectory": "$(SolutionDir)"
},
"filebeat": {
"commandName": "Project",
"commandLineArgs": "build --cid 8.11.0 filebeat",
"workingDirectory": "$(SolutionDir)"
}
}
}
}
84 changes: 13 additions & 71 deletions src/installer/BeatPackageCompiler/BeatPackageCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using ElastiBuild.Extensions;
using Elastic.Installer;
using WixSharp;
using WixSharp.Bootstrapper;
using WixSharp.CommonTasks;

namespace Elastic.PackageCompiler.Beats
Expand Down Expand Up @@ -100,17 +101,14 @@ static void Main(string[] args)
System.IO.File.ReadAllText(
Path.Combine(opts.PackageInDir, MagicStrings.Files.LicenseTxt))));

var beatConfigPath = "[CommonAppDataFolder]" + Path.Combine(companyName, productSetName, ap.CanonicalTargetName);
var beatDataPath = Path.Combine(beatConfigPath, "data");
var beatLogsPath = Path.Combine(beatConfigPath, "logs");

var textInfo = new CultureInfo("en-US", false).TextInfo;
var serviceDisplayName = $"{companyName} {textInfo.ToTitleCase(ap.TargetName)} {ap.SemVer}";

WixSharp.File service = null;
if (pc.IsWindowsService)
{
service = new WixSharp.File(Path.Combine(opts.PackageInDir, exeName));
string installedPath = ("[INSTALLDIR]" + Path.Combine(ap.Version, ap.CanonicalTargetName));

// TODO: CNDL1150 : ServiceConfig functionality is documented in the Windows Installer SDK to
// "not [work] as expected." Consider replacing ServiceConfig with the
Expand All @@ -131,10 +129,10 @@ static void Main(string[] args)
},

Arguments =
" --path.home " + ("[INSTALLDIR]" + Path.Combine(ap.Version, ap.CanonicalTargetName)).Quote() +
" --path.config " + beatConfigPath.Quote() +
" --path.data " + beatDataPath.Quote() +
" --path.logs " + beatLogsPath.Quote() +
" --path.home " + installedPath.Quote() +
" --path.config " + installedPath.Quote() +
" --path.data " + installedPath.Quote() +
" --path.logs " + installedPath.Quote() +
" -E logging.files.redirect_stderr=true",

DelayedAutoStart = false,
Expand All @@ -150,40 +148,21 @@ static void Main(string[] args)

var packageContents = new List<WixEntity>
{
new DirFiles(Path.Combine(opts.PackageInDir, MagicStrings.Files.All), path =>
new Files(Path.Combine(opts.PackageInDir, MagicStrings.Files.All), path =>
{
var itm = path.ToLower();
bool isConfigFile = itm.EndsWith(ap.CanonicalTargetName + MagicStrings.Ext.DotYml, StringComparison.OrdinalIgnoreCase);

bool exclude =

// configuration will go into mutable location
itm.EndsWith(MagicStrings.Ext.DotYml, StringComparison.OrdinalIgnoreCase) ||

// we install/remove service ourselves
itm.EndsWith(MagicStrings.Ext.DotPs1, StringComparison.OrdinalIgnoreCase) ||

// .exe must be excluded for service configuration to work
(pc.IsWindowsService && itm.EndsWith(exeName, StringComparison.OrdinalIgnoreCase))
;
|| (isConfigFile);

// this is an "include" filter
return ! exclude;
})
};

packageContents.AddRange(
new DirectoryInfo(opts.PackageInDir)
.GetDirectories()
.Select(dir => dir.Name)
.Except(pc.MutableDirs)
.Select(dirName =>
new Dir(
dirName,
new Files(Path.Combine(
opts.PackageInDir,
dirName,
MagicStrings.Files.All)))));

packageContents.Add(pc.IsWindowsService ? service : null);

// Add a note to the final screen and a checkbox to open the directory of .example.yml file
Expand Down Expand Up @@ -229,33 +208,22 @@ static void Main(string[] args)
.GetFiles(MagicStrings.Files.AllDotYml, SearchOption.TopDirectoryOnly)
.Select(fi =>
{
var wf = new WixSharp.File(fi.FullName);

// rename main config file to hide it from MSI engine and keep customizations
if (string.Compare(
fi.Name,
ap.CanonicalTargetName + MagicStrings.Ext.DotYml,
StringComparison.OrdinalIgnoreCase) == 0)
{
var wf = new WixSharp.File(fi.FullName);
wf.Attributes.Add("Name", beatConfigExampleFileName);
wf.Id = new Id(beatConfigExampleFileId);
return wf;
}

return wf;
return null;
})
.ToList<WixEntity>();

dataContents.AddRange(
pc.MutableDirs
.Select(dirName =>
{
var dirPath = Path.Combine(opts.PackageInDir, dirName);

return Directory.Exists(dirPath)
? new Dir(dirName, new Files(Path.Combine(dirPath, MagicStrings.Files.All)))
: null;
})
.Where(dir => dir != null));
packageContents.AddRange(dataContents);

// Drop CLI shim on disk
var cliShimScriptPath = Path.Combine(
Expand All @@ -279,32 +247,6 @@ static void Main(string[] args)
new Dir(ap.CanonicalTargetName, packageContents.ToArray()),
new WixSharp.File(cliShimScriptPath))),

// Configration and logs
new Dir("[CommonAppDataFolder]",
new Dir(companyName,
new Dir(productSetName,
new Dir(ap.CanonicalTargetName, dataContents.ToArray())
{
GenericItems = new []
{
/*
This will *replace* ACL on the {beatname} directory:
Directory tree:
NT AUTHORITY\SYSTEM:(OI)(CI)F
BUILTIN\Administrators:(OI)(CI)F
BUILTIN\Users:(CI)R
Files:
NT AUTHORITY\SYSTEM:(ID)F
BUILTIN\Administrators:(ID)F
*/

new MsiLockPermissionEx(
"D:PAI(A;OICI;FA;;;SY)(A;OICI;FA;;;BA)(A;CI;0x1200a9;;;BU)",
ap.Is64Bit)
}
})))
};

// CLI Shim path
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"profiles": {
"BeatPackageCompiler.netcore": {
"commandName": "Project",
"commandLineArgs": "--package=winlogbeat-7.5.0-windows-x86_64 -v --keep-temp-files",
"commandLineArgs": "--package=winlogbeat-8.11.1-windows-x86_64 -v --keep-temp-files",
"workingDirectory": "$(SolutionDir)"
},
"Filebeat": {
"commandName": "Project",
"commandLineArgs": "--package=filebeat-8.11.0-windows-x86_64 -v --keep-temp-files",
"workingDirectory": "$(SolutionDir)"
}
}
Expand Down

0 comments on commit f8c4ece

Please sign in to comment.