-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(install): Initialize work on manifest helpers #3587
Conversation
Is this for some codes that might be widely used in manifests? |
Hm, I don't know if we should use global variables. 🤔 I was thinking about adding helper functions like: Create-NewTextFile -Path "$dir\blah.ini" -Value "blah" -Encoding utf-8 -
Create-NewTextFile -Path "$dir\blah.ini" -Value { @('[global]', '[Software\grepWin\History]') -join "`r`n" } -Encoding utf-8 -
Create-NewTextFile -Path "$dir\blah.conf" -ScriptBlock { easyrsa init-pki }
Create-NewDirectory -Value "$persist_dir\blah" Each function will report if the file exists or was created. Maybe most of the Something like this: "files": [
{
"name": "blah.ini",
"path": "$dir",
"content": "$null",
"encoding": "utf-8",
"lineending": "crlf"
}
],
"directories": [
{
"name": "blah",
"path": "$persist_dir"
}
] |
Manifest declaration is not really handy as it is completely unergonomic. Instead of oneliner For global i will see what I can do about this. |
Is there ever a reason to create files (in |
Proposed persisted schema solution in #3212 does not cover every use case. New scheme cover only Static and deterministic content. When you need to setup something complex you need to use use persist check manually. As example ditto and execution of it's executable to create db. |
@r15ch13 Tried with environemnt variables as they are only strings all the time and then prevent leakage of them again. |
I see what you mean. I was thinking the ditto.db could be created with New-Item somehow Though now I wonder if it might not be be a good idea to have that whole function as some persistence field. Something along the lines of You think this would be too jarring for some applications? |
No. Keeping it within properties will make things worse. There is no reason to ditch one line powershell code and distribute it into complex and misleading properties. As lots of configurations files exists and needs to be edited manually (HoneyView) or copied (cmder) This generic function will keep manifests code clean and easy to write / maintain instead of thinking about complex properties structure with mutually exclusive properties to deal with. #3212 Will take care of empty / simply / static / files creations and other will be handled using helpers. Easy, maintainable, no need to look for reference. |
I see your point, but I was actually referring to replacing 11 lines of Powershell with one manifest property. And instead of a new property itself, it could even be relegated to a new value for Like:
In the end, it's probably not a good trade-off to base/normalise a whole feature around some edge cases, and I too am not that sure "run ditto.exe" is all that intuitive. Thought it worth discussing anyway. |
Best possible solution is to get varibles from session state. It will require to manually register all needed variables explicitly, but it is not using global, object could be saved as well, not leaking anything to upper scope and it is safe. |
Lots of jar executables are needed to be runned form start See classyshark for example
How about vbs instead of bat for Java shortcut wrapper? There will be a black popup when run bat. |
@linsui Show me code Added some additonal checks for requirements. Module usage was depricated due to context problem (TLDR; It was not possible to use core functions in Manifest for testing{
"version": "1.0",
"url": "https://github.com/sharkdp/bat/releases/download/v0.12.1/bat-v0.12.1-x86_64-pc-windows-msvc.zip",
"pre_install": [
" # Nested file with two lines",
"Test-Persistence 'bin\\nested\\file' -Content 'new', 'line'",
" # File4 should be empty",
"Test-Persistence 'file1', 'file2', 'file3', 'file4' -Content 'new', 'new2', 'new3'",
" # Empty",
"'file5', 'file6', 'file7', 'file8' | Test-Persistence",
" # One file with 2 lines",
"'file9' | Test-Persistence -Content 'alfa', 'new'",
"Test-Persistence 'alfa.json' -Execution { Write-Host 'This file will not exists' }",
"Assert-Administrator",
"Assert-WindowsVersion '10'",
"Assert-DotNetFramework '4.5'"
],
"uninstaller": {
"script": [
"Assert-Administrator",
"Write-Host 'After assert'"
]
}
} |
Here is a example. I don't know how to make it work for cli, but it works well for gui. So I use vbs in shortcuts and bat in bin. example"pre_install": [
"Expand-7zipArchive \"$dir\\$fname\" -Switches 'icons\\xxhdpi\\icon.png'",
"Set-Content \"$dir\\RunXDM.bat\" 'start javaw -Xmx1024m -jar %~dp0\\xdman.jar %*' -Encoding ASCII",
"Set-Content \"$dir\\RunXDM.vbs\" \"CreateObject(`\"WScript.Shell`\").Run `\"javaw -Xmx1024m -jar xdman.jar`\",0\" -Encoding ASCII",
"$stream = [System.IO.File]::OpenWrite(\"$dir\\icon.ico\")",
"$bitmap = [System.Drawing.Image]::FromFile(\"$dir\\icons\\xxhdpi\\icon.png\")",
"([System.Drawing.Icon]::FromHandle($bitmap.GetHicon())).Save($stream)"
],
"bin": "RunXDM.bat",
"shortcuts": [
[
"RunXDM.vbs",
"Xtreme Download Manager",
"",
"icon.ico"
]
],
Why force is needed here? |
I cleanuped some more WIP helpers and kept only basic ones. I will add more of them in other PR. As basic this is enough @linsui VBS has not way how to cleanly pass parameters in universal way. Parameter handling have to be done manually, which is completely non future proof. |
Generic function for dealing with persitence checks as starter for widely used repeated codes.
Manifest for testing
Persistence check
Ditto manifest:
Java shortcut wrapper
Classyshark:
Remove files from
$dir
Import-module is hapenning in main scoop and also in install.ps1 to keep install.ps1 working as standalone module without need to import install.ps1 with all references. (So if you want to import it in external script you can just do. '...\install.ps1'
insteadgci '...\lib' | % { . $_.Fullname }
-$global:
variables are mandatory for function scoped variables to be available in modules.