見出し画像

旧版TWSNMPをChocolateyへ公開申請した時のポイントまとめ

浦和レッズ ACL優勝 おめでとう!
気分のよい朝に、一昨日から調べていたChocolateyへパッケージの公開申請をしてみました。
まずは、旧版TWSNMPです。最終版v.4.11.7をパッケージにしました。
基本は、

のページに書かれている手順です。
ポイントだけ描いておきます。

Chocolatey CLI (choco)をインストール

まずは、chocoコマンドを使えるようにします。

の中にある

にインストールのコマンドが書いてあります。

choco newコマンドでパッケージを作成

指定したパラメータは、名前、バージョン、メンテナーだけです。

choco new --name=TWSNMP --version=4.11.7 --maintaner="twsnmp"

のように作成しました。

自動生成ファイルの編集と削除

choco newコマンドをパッケージ名をtestとして実行すると

のようなファイルが自動生成されます。
必要なのは、

test.nuspec

tools/chocolateyinstall.ps1
tools/LICENSE.txt
tools/VERIFICATIION.txt

です。社内配布ならLICENSE.txtとVERIFICATIN.txtは不要です。
不要なファイルは削除してよいはずです。
_TODO.txtにも手順か細かく書いてあります。
自動生成されたnuspecやps1ファイルの中にも、コメントで説明が書いてあります。サイトや_TODO.txtの説明よりも新しくて詳しいです。
編集が必要な部分は

   <authors>__REPLACE_AUTHORS_OF_SOFTWARE_COMMA_SEPARATED__</authors>
 

のような感じで大文字でわかるようになっています。
AppleやMicrosoftのストアのWebサイトで入力するような内容です。
TWSNMPの場合は、

<?xml version="1.0" encoding="utf-8"?>
<!-- Read this before creating packages: https://docs.chocolatey.org/en-us/create/create-packages -->
<!-- It is especially important to read the above link to understand additional requirements when publishing packages to the community feed aka dot org (https://community.chocolatey.org/packages). -->

<!-- Test your packages in a test environment: https://github.com/chocolatey/chocolatey-test-environment -->

<!--
This is a nuspec. It mostly adheres to https://docs.nuget.org/create/Nuspec-Reference. Chocolatey uses a special version of NuGet.Core that allows us to do more than was initially possible. As such there are certain things to be aware of:

* the package xmlns schema url may cause issues with nuget.exe
* Any of the following elements can ONLY be used by choco tools - projectSourceUrl, docsUrl, mailingListUrl, bugTrackerUrl, packageSourceUrl, provides, conflicts, replaces
* nuget.exe can still install packages with those elements but they are ignored. Any authoring tools or commands will error on those elements
-->

<package xmlns="http://schemas.microsoft.com/packaging/2015/06/nuspec.xsd">
  <metadata>
    <id>twsnmp</id>
    <version>4.11.7</version>
    <title>TWSNMP (Install)</title>
    <authors>Twise Labo Inc.(Masayuki Yamai)</authors>
    <projectUrl>https://lhx98.linkclub.jp/twise.co.jp/</projectUrl>
    <tags>twsnmp snmp</tags>
    <summary>SNMP Manager for Windows Desktop</summary>
    <description>

- Display Network Map
- SNMP/PING polling
- MIB browser
- Traffic management
- Port management

    </description>
  
  </metadata>
  <files>
    <file src="tools\**" target="tools" />
  </files>
</package>

chocolateyinstall.ps1は

$url        = '' # download url, HTTPS preferred
$url64      = '' # 64bit URL here (HTTPS preferred) or remove - if installer contains both (very rare), use $url

$packageArgs = @{
  packageName   = $env:ChocolateyPackageName
  unzipLocation = $toolsDir
  fileType      = 'EXE_MSI_OR_MSU' #only one of these: exe, msi, msu
  url           = $url
  url64bit      = $url64
  #file         = $fileLocation

  softwareName  = 'test*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique

  # Checksums are now required as of 0.10.0.
  # To determine checksums, you can get that from the original site if provided.
  # You can also use checksum.exe (choco install checksum) and use it
  # e.g. checksum -t sha256 -f path\to\file
  checksum      = ''
  checksumType  = 'sha256' #default is md5, can also be sha1, sha256 or sha512
  checksum64    = ''
  checksumType64= 'sha256' #default is checksumType

  # MSI
  silentArgs    = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`"" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0
  validExitCodes= @(0, 3010, 1641)
  # OTHERS
  # Uncomment matching EXE type (sorted by most to least common)
  #silentArgs   = '/S'           # NSIS
  #silentArgs   = '/VERYSILENT /SUPPRESSMSGBOXES /NORESTART /SP-' # Inno Setup
  #silentArgs   = '/s'           # InstallShield
  #silentArgs   = '/s /v"/qn"'   # InstallShield with MSI
  #silentArgs   = '/s'           # Wise InstallMaster
  #silentArgs   = '-s'           # Squirrel
  #silentArgs   = '-q'           # Install4j
  #silentArgs   = '-s'           # Ghost
  # Note that some installers, in addition to the silentArgs above, may also need assistance of AHK to achieve silence.
  #silentArgs   = ''             # none; make silent with input macro script like AutoHotKey (AHK)
                                 #       https://community.chocolatey.org/packages/autohotkey.portable
  #validExitCodes= @(0) #please insert other valid exit codes here
}

Install-ChocolateyPackage @packageArgs # https://docs.chocolatey.org/en-us/create/functions/install-chocolateypackage

のようにコメントで説明付きなので、それに従ってTWSNMPの場合は、

$packageName   = $env:ChocolateyPackageName
$installerType = 'msi'
$url = 'https://lhx98.linkclub.jp/twise.co.jp/download/TWSNMPV4.msi'
$silentArgs = '/quiet'
$validExitCodes = @(0,3010)

Install-ChocolateyPackage $packageName $installerType $silentArgs $url  -validExitCodes $validExitCodes

$ErrorActionPreference = 'Stop' # stop on all errors
$toolsDir   = "$(Split-Path -parent $MyInvocation.MyCommand.Definition)"
$url        = 'https://lhx98.linkclub.jp/twise.co.jp/download/TWSNMPV4.msi' # download url, HTTPS preferred

$packageArgs = @{
  packageName   = $env:ChocolateyPackageName
  unzipLocation = $toolsDir
  fileType      = 'msi' #only one of these: exe, msi, msu
  url           = $url

  softwareName  = 'TWSNMP*' #part or all of the Display Name as you see it in Programs and Features. It should be enough to be unique

  checksum      = '072D59508F7FFA4BC8639FCC8720395978B78E1AF650A229D0697990F2174DBB'
  checksumType  = 'sha256' #default is md5, can also be sha1, sha256 or sha512
 
  # MSI
  silentArgs    = "/qn /norestart /l*v `"$($env:TEMP)\$($packageName).$($env:chocolateyPackageVersion).MsiInstall.log`"" # ALLUSERS=1 DISABLEDESKTOPSHORTCUT=1 ADDDESKTOPICON=0 ADDSTARTMENU=0
  validExitCodes= @(0, 3010, 1641)
 }

Install-ChocolateyPackage @packageArgs

にしました。
checksumの値は、chocoコマンドでchecksumをインストールして

choco install checksum
checksum -t sha256 .\TWSNMPV4.msi

 で取得しました。

ライセンスや検証の説明は、コメントに従って書き換えました。

choco packコマンドでパッケージ作成

ファイルの編集が終わったら

choco pack

でパッケージが出来上がります。

choco installコマンドでテスト

できたパッケージを

choco install twsnmp --source .

でインストールのテストができます。アンインストールは、

choco uninstall twsnmp

です。便利です。

アカウントの作成とAPIキーの取得

公開するためには、APIキーが必要です。
APIキーを取得するためにはアカウントも必要で

から作成します。
ログインして右上のユーザー名の中にあるAccountのメニューをクリックするとAPI Keyの画面が表示されます。

<Show API Key> ボタンをクリックすれば、APIキーをコピーできます。

APIキーの設定とPUSH

取得したAPIキーを設定してPUSHします。

choco apikey --api-key <API_KEY> -source https://push.chocolatey.org/
choco push twsnmp.4.11.7.nupkg --source https://push.chocolatey.org/

PUSHしてすぐは、チェックがペンディングになっていますが、
時間がたてば、チェックが進みます。

この後、どうなるかは、明日のお楽しみ。


明日に続く


開発のための諸経費(機材、Appleの開発者、サーバー運用)に利用します。 ソフトウェアのマニュアルをnoteの記事で提供しています。 サポートによりnoteの運営にも貢献できるのでよろしくお願います。