Chocolateyのパッケージを作成します



ChocolateyはWindows用のパッケージマネージャーであり、プログラムのインストールと時間の節約を大幅に簡素化します。 彼らはすでにハブでこの奇跡について書いており、そのためのパッケージの書き方さえ示しましたが、もっと手作業がありましたが、この問題を少し簡単にする方法を示したいと思います。

降りる


chocolateyがインストールされていない場合、これを修正します。

@powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%systemdrive%\chocolatey\bin 

もう一度コンソールを閉じて開き、変数のデータを更新します。

Chocolateyがインストールされました。今、私たちに役立つパッケージをインストールします

 cinst warmup cinst git cinst nuget.commandline 

もう一度コンソールを閉じて開き、変数のデータを更新します。

chocolateyがインストールされたフォルダーに移動し、テンプレートを使用してリポジトリを複製し、テンプレートに移動します。

 cd %ChocolateyInstall% git clone https://github.com/chocolatey/chocolateytemplates.git cd chocolateytemplates\_templates 

少し標準的な設定を編集しましょう



これで、パッケージを作成するテンプレートをアクティブ化できます(基本的に、目的のテンプレートを含むディレクトリへのリンクが作成されます)。 これを行うには、 %ChocolateyInstall%\chocolateytemplates\_templatesコマンド%ChocolateyInstall%\chocolateytemplates\_templates実行します( adminからのみ実行します):

 warmup addTemplateFolder chocolatey "%CD%\chocolatey" 

ウェブサイトchocolatey.orgにアクセスし、登録し、プロフィールにアクセスして、クリックします
「プライバシーのため、キーは非表示になっています。クリックして表示してください。」 3つのコマンドが表示されます。最初のコマンドのみを実行します。APIキーをインストールします。

これで準備は完了です。パッケージの大量リリースに進むことができます。


公式ドキュメントでは、すべての新しいパッケージに小文字の名前を付け、単語を「-」記号で区切るか、単にスペースを省略することを推奨しています。 また、最初は、目的のプログラムで検索パッケージを使用することをお勧めします。存在しない場合のみ、独自に実行します。

ソースを保存するには、次の構造を使用します。

パッケージ
   |-ワークレイブ
     |-src
       |-ツール
       |-workrave.nuspec
       |-... ..
     |-ビルド
   |-パッケージ-2

packagesディレクトリに移動して実行します:

 warmup chocolatey workrave 

表示されるworkraveフォルダーでsrcを作成し、 workraveのコンテンツをworkrave

ファイルworkrave.nuspec開きます。 これは通常のxmlで、パッケージの説明が含まれています。 タグの名前はそれ自体を物語っています。title-chocolatey.orgのパッケージのリストに表示されるプログラムの名前。 authorパッケージに入れたプログラムの作成者....

最も興味深いのはtools\chocolateyInstall.ps1ファイルです

コードする
 #NOTE: Please remove any commented lines to tidy up prior to releasing the package, including this one $packageName = 'workrave' # arbitrary name for the package, used in messages $installerType = 'EXE_MSI_OR_MSU' #only one of these: exe, msi, msu $url = 'URL_HERE' # download url $url64 = 'URL_x64_HERE' # 64bit URL here or remove - if installer decides, then use $url $silentArgs = 'SILENT_ARGS_HERE' # "/s /S /q /Q /quiet /silent /SILENT /VERYSILENT" # try any of these to get the silent installer #msi is always /quiet $validExitCodes = @(0) #please insert other valid exit codes here, exit codes for ms http://msdn.microsoft.com/en-us/library/aa368542(VS.85).aspx # main helpers - these have error handling tucked into them already # installer, will assert administrative rights # if removing $url64, please remove from here Install-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" "$url64" -validExitCodes $validExitCodes # download and unpack a zip file # if removing $url64, please remove from here Install-ChocolateyZipPackage "$packageName" "$url" "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" "$url64" #try { #error handling is only necessary if you need to do anything in addition to/instead of the main helpers # other helpers - using any of these means you want to uncomment the error handling up top and at bottom. # downloader that the main helpers use to download items # if removing $url64, please remove from here #Get-ChocolateyWebFile "$packageName" 'DOWNLOAD_TO_FILE_FULL_PATH' "$url" "$url64" # installer, will assert administrative rights - used by Install-ChocolateyPackage #Install-ChocolateyInstallPackage "$packageName" "$installerType" "$silentArgs" '_FULLFILEPATH_' -validExitCodes $validExitCodes # unzips a file to the specified location - auto overwrites existing content #Get-ChocolateyUnzip "FULL_LOCATION_TO_ZIP.zip" "$(Split-Path -parent $MyInvocation.MyCommand.Definition)" # Runs processes asserting UAC, will assert administrative rights - used by Install-ChocolateyInstallPackage #Start-ChocolateyProcessAsAdmin 'STATEMENTS_TO_RUN' 'Optional_Application_If_Not_PowerShell' -validExitCodes $validExitCodes # add specific folders to the path - any executables found in the chocolatey package folder will already be on the path. This is used in addition to that or for cases when a native installer doesn't add things to the path. #Install-ChocolateyPath 'LOCATION_TO_ADD_TO_PATH' 'User_OR_Machine' # Machine will assert administrative rights # add specific files as shortcuts to the desktop #$target = Join-Path $MyInvocation.MyCommand.Definition "$($packageName).exe" #Install-ChocolateyDesktopLink $target #------- ADDITIONAL SETUP -------# # make sure to uncomment the error handling if you have additional setup to do #$processor = Get-WmiObject Win32_Processor #$is64bit = $processor.AddressWidth -eq 64 # the following is all part of error handling #Write-ChocolateySuccess "$packageName" #} catch { #Write-ChocolateyFailure "$packageName" "$($_.Exception.Message)" #throw #} 


3つのブロックがあります。



テストパッケージでは、このフォームにコードを追加します

後のコード
 #NOTE: Please remove any commented lines to tidy up prior to releasing the package, including this one $packageName = 'workrave' # arbitrary name for the package, used in messages $installerType = 'exe' #only one of these: exe, msi, msu $url = 'http://softlayer-ams.dl.sourceforge.net/project/workrave/workrave/1.10.1/workrave-win32-v1.10.1-installer.exe' # download url $silentArgs = '/verysilent /norestart' # "/s /S /q /Q /quiet /silent /SILENT /VERYSILENT" # try any of these to get the silent installer #msi is always /quiet $validExitCodes = @(0) #please insert other valid exit codes here, exit codes for ms http://msdn.microsoft.com/en-us/library/aa368542(VS.85).aspx # main helpers - these have error handling tucked into them already # installer, will assert administrative rights # if removing $url64, please remove from here Install-ChocolateyPackage "$packageName" "$installerType" "$silentArgs" "$url" -validExitCodes $validExitCodes # download and unpack a zip file 


Workraveはサイレントインストールに/verysilent /norestartスイッチを使用します。 パブリックインストーラーで最も一般的なキーのリストは、 $silentArgs変数の説明に記載されています。 これも確認できます: unattended.sourceforge.net/installers.php

これで、パッケージを収集してテストし、chocolatey.orgにアップロードできます。 このプロセスを容易にするために、4つの単純な.batファイルを作成しました。コードをコピーして貼り付けるのではなく、 githubからダウンロードできます。



つまり パッケージをビルドするには、最初の3つの.batファイルを順番に実行するか、4番目の.batファイルを実行します。

以上です。



LANのエラーについて書いてください。

Source: https://habr.com/ru/post/J223373/


All Articles