跳轉到內容

TWW HPMS 移植到其他作業系統

來自 Wikibooks,開放世界開放書籍

將 TWW HPMS 移植到其他作業系統

[編輯 | 編輯原始碼]

將 TWW HPMS 工具移植到其他作業系統時需要完成兩項任務。

  • 移植 TWW HPMS 工具本身
  • 移植包源。
  • 用於自動執行 TWW 工具移植的 Makefile。

Linksys NSLU2

[編輯 | 編輯原始碼]
  • 一個用於為 nslu2 構建 TWW 工具的 Makefile。
  • 編譯 sbtuils 工具以生成 sb
  • 使用 sb 編譯和構建 pb 和 pkgutils
  • 移植 sbtools

{}

  • 移植 pbtools
  • 移植 pkgutils

做完功課後,以下是一些關於 Mac OS X 上軟體打包的優秀文件。

包管理系統正在變得更好,但仍然缺乏 PMS 應該具有的基本功能。例如,您無法使用命令列工具列出當前安裝的包。您無法使用命令刪除包或自動處理包依賴關係。

/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker 在 10.3.8 中得到了改進。我們現在可以使用命令列建立 .pkg。請注意,在 -p 或 -f 選項之後提供絕對路徑。

以下是一個用於在 Mac OSX 的本地 PMS 格式中建立 TWW CPAM 工具的部分 Makefile。

<snip>
# A simple layout for .pkg format
#Test.pkg
#    Contents
#        Archive.bom
#        Archive.pax.gz
#        Info.plist
#        PkgInfo
#        Resources
#            Description.plist
#            postflight      -1-
#            postinstall     -2-
#            postupgrade     -3-
#            preflight       -4-
#            preinstall      -5-
#            preupgrade      -6-

PKGMK=/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
SB_PKG_DIR=/opt/TWWfsw/sbutils124
SB_PKGNAME=sbutils-1.2.4
PB_PKGNAME=pbutils-1.1.12
PKGUTILS_PKGNAME=pkgutils-1.5.19
SB_PKG_HOME=/opt/build/sbutils-1.2.4
PB_PKG_HOME=${SB_PKG_HOME}
PKGUTILS_PKG_HOME=${SB_PKG_HOME}
SB_PKG_STG=${SB_PKG_HOME}/sbutils-stage
PB_PKG_STG=${SB_PKG_HOME}/pbutils-stage
PKGUTILS_PKG_STG=${SB_PKG_HOME}/pkgutils-stage
PB_INSTALL_PREFIX=/opt/TWWfsw/pbutils11
PKGUTILS_INSTALL_PREFIX=/opt/TWWfsw/pkgutils15
sb-pkg: sb-pkg-prep sb-pkg-pkgmk
sb-pkg-clean:
        rm -rf ${SB_PKG_HOME}/${SB_PKGNAME} ${SB_PKG_STG}
sb-pkg-prep:
        rm -rf $(SB_PKG_STG)
        mkdir -p $(SB_PKG_STG)/Contents/Resources
        touch $(SB_PKG_STG)/Contents/Resources/postflight
        touch $(SB_PKG_STG)/Contents/Resources/postinstall
        touch $(SB_PKG_STG)/Contents/Resources/postupgrade
        touch $(SB_PKG_STG)/Contents/Resources/preflight
        touch $(SB_PKG_STG)/Contents/Resources/preinstall
        touch $(SB_PKG_STG)/Contents/Resources/preupgrade
sb-pkg-pkgmk:
        $(PKGMK) -build -p ${SB_PKG_HOME}/${SB_PKGNAME}.pkg -f $(SB_INSTALL_PREFIX) -i ${SB_PKG_HOME}/src/macosx/Info.p\list.sb -d ${SB_PKG_HOME}/src/macosx/Description.plist.sb

sb-pkg-pkgmk-clean:
        rm -rf ${SB_PKG_HOME}/${SB_PKGNAME}
sb-pkg-install:
        /usr/sbin/installer -pkg sbutils-1.2.4-1.pkg  -target /
<snip>
  • 移植 sbtools

sbutils-1.2.4 在 Mac OS X 10.3.8 上編譯成功。我們也可以使用 packagemaker 將 sbutils-1.2.4 生成到 Mac OS X 的原生包格式。以下快速筆記需要稍後記錄。

conchi:~/tww-tools/sbutils-1.2.4 tjyang$ sudo make sb-pkg
rm -rf /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage
mkdir -p /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/postflight 
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/postinstall
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/postupgrade
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/preflight
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/preinstall
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/preupgrade
cp -rp /opt/TWWfsw/sbutils124/* /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage
^Cmake: *** [sb-pkg-prep] Interrupt

conchi:~/tww-tools/sbutils-1.2.4 tjyang$ sudo make sb-pkg
rm -rf /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage
mkdir -p /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/postflight 
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/postinstall
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/postupgrade
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/preflight
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/preinstall
touch /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Resources/preupgrade
/usr/bin/mkbom -s  /opt/TWWfsw/sbutils124 /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Archive.bom
(pax -w -x cpio /opt/TWWfsw/sbutils124 |gzip - > /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents/Archive.pax.gz)
/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker -build -p /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-1.2.4-1.pkg   -f /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-stage/Contents -i //Users/tjyang/tww-tools/sbutils-1.2.4/Info.plist -d //Users/tjyang/tww-tools/sbutils-1.2.4/Description.plist
2005-02-27 23:29:24.664 PackageMaker[19034] ** building a package at /Users/tjyang/tww-tools/sbutils-1.2.4/sbutils-1.2.4-1.pkg **
2005-02-27 23:29:32.961 PackageMaker[19034] done (0)
conchi:~/tww-tools/sbutils-1.2.4 tjyang$ ls -lrt
total 216
-rwx------   1 tjyang  tjyang  42318 23 Feb 15:04 systype
-rw-r--r--   1 tjyang  tjyang   1069 27 Feb 15:49 cipo.error.txt
drwx------  43 tjyang  tjyang   1462 27 Feb 15:59 src
-rwxr-xr-x   1 tjyang  tjyang   7796 27 Feb 22:23 genpkg.sh
-rw-r--r--   1 tjyang  tjyang    459 27 Feb 23:13 Description.plist
-rw-r--r--   1 tjyang  tjyang   1050 27 Feb 23:17 Info.plist
-rwx------   1 tjyang  tjyang  44915 27 Feb 23:28 Makefile
drwxr-xr-x   3 root    tjyang    102 27 Feb 23:28 sbutils-stage
drwxr-xr-x   3 root    tjyang    102 27 Feb 23:29 sbutils-1.2.4-1.pkg
conchi:~/tww-tools/sbutils-1.2.4 tjyang$ ls sbutils-1.2.4-1.pkg/
Contents
conchi:~/tww-tools/sbutils-1.2.4 tjyang$ ls sbutils-1.2.4-1.pkg/Contents/
Archive.bom     Archive.pax.gz  Info.plist      PkgInfo         Resources
conchi:~/tww-tools/sbutils-1.2.4 tjyang$ ls -l sbutils-1.2.4-1.pkg/Contents/
total 32312
-r--r--r--  1 root  tjyang     35525 27 Feb 23:29 Archive.bom
-r--r--r--  1 root  tjyang  16496572 27 Feb 23:29 Archive.pax.gz
-r--r--r--  1 root  tjyang      1050 27 Feb 23:29 Info.plist
-r--r--r--  1 root  tjyang         8 27 Feb 23:29 PkgInfo
drwxr-xr-x  7 root  tjyang       238 27 Feb 23:29 Resources
conchi:~/tww-tools/sbutils-1.2.4 tjyang$ ls -l sbutils-1.2.4-1.pkg/Contents/Resources/
total 40
-r--r--r--  1 root  tjyang  459 27 Feb 23:29 Description.plist
lrwxr-xr-x  1 root  tjyang   14 27 Feb 23:29 sbutils-1.2.4-1.bom -> ../Archive.bom
-r--r--r--  1 root  tjyang  275 27 Feb 23:29 sbutils-1.2.4-1.info
lrwxr-xr-x  1 root  tjyang   17 27 Feb 23:29 sbutils-1.2.4-1.pax.gz -> ../Archive.pax.gz
-r--r--r--  1 root  tjyang   46 27 Feb 23:29 sbutils-1.2.4-1.sizes
conchi:~/tww-tools/sbutils-1.2.4 tjyang$ vi  sbutils-1.2.4-1.pkg/Contents/Resources/sbutils-1.2.4-1.info 
conchi:~/tww-tools/sbutils-1.2.4 tjyang$

Microsoft Windows

[編輯 | 編輯原始碼]

將 TWW HPMS 工具移植到 Win32 平臺的第一個問題是使用哪個包建立軟體以及基於哪個 Unix 基礎軟體。

  • Unix 基礎軟體
    • cygwin 的 sbutils 包源筆記。
  "aux" need to be renamed to "auxx". 
  perl -pi -e 's!\/aux\/!/aux!' Makfile
  http://cygwin.com/setup.html is the place to understand cygwin package format.
    • mingw
    • SFU
  • 包建立工具
    • MakeMSI(參見 http://users.cyberone.com.au/dbareis/makemsi.htm)自動構建(或更新)MSI 檔案(或任何其他型別的 Windows Installer 資料庫)。它使用類似 XML 的指令碼語言,可以透過資源管理器或命令列呼叫。它還構建 MSI 文件,包括檔案(MD5 檢查安裝的檔案是否與預期等)和產品驗證按鈕。它包含一個非常強大的預處理器。
    對話方塊可以建立,並且可以輕鬆格式化,無需使用對話方塊編輯器。有許多針對不同用途和使用者技能的“框架”。可以整合自定義操作程式碼,並且具有一些 ADSI/COMPLUS/排程和其他支援。以下是一個小型示例指令碼(一個檔案,一個快捷方式,一個小型基於 VBScript 的自定義操作)。
;--- Load MAKEMSI (via wrapper which configures MAKEMSI to work how I like it) ---
#include "DENNIS.MMH"

;--- Create INSTALLDIR (we wish to install file(s) here) ---
<$DirectoryTree Key="INSTALLDIR" Dir="[ProgramFilesFolder]\TryMe" CHANGE="\" PrimaryFolder="Y">

;--- Add "TRY.MM" and shortcut to same component (file must be keypath) ---
<$Component "TryMe" Create="Y" Directory_="INSTALLDIR">   ;;In this case GUID autogenerated (at least 1st time)
    ;--- Add the files to the "TryMe" component -----------------------------
    <$File SOURCE="TryMeWithAdvShortCut.MM" KeyPath="Y">

    ;--- Add the shortcut (advertise the "complete" feature) ----------------
    #(
        ;--- Advertised shortcut in "Start->programs" -----------------------
        <$Shortcut
                   Dir="ProgramMenuFolder"
               Feature="\"                        ;;root feature is my "complete" one
                 Title="Open TryMeWithAdvShortCut.MM (via default association)"
           Description=^Simply opens "TryMeWithAdvShortCut.MM" in associated handler (probably notepad)!^
                  Icon="@.\TryMe.ico"
               WorkDir="INSTALLDIR"
        >
    #)
<$/Component>

;--- Display a message during a non-silent install (logs if silent) ---------
#data "PopupCaData"
   ;--- Some data we'd like to pass to the CA -------------------------------
   "InstallationDirectory" "[INSTALLDIR]"
   "SystemFolder" "[SystemFolder]"
#data
<$VbsCa Binary="Popup.vbs" DATA=^PopupCaData^>
   <$VbsCaEntry "HiThere">
       ;--- If the VBSCRIPT "MsgBox" or similar function was used this would prevent a silent install ---
       #(
            CaMsgBox "I",
                     "Hi this is a message from '<?InputFile>'! This was displayed via a VBSCRIPT MSI custom action." &
                     vbCRLF & vbCRLF &
                     "Note that I have enlarged this message box so that when an error occurs you will see the whole text! " &
                     "This and most tweeking MAKEMSI does to the user interface is optional (most performed by ""UISAMPLE.MMH"")." &
                     vbCRLF & vbCRLF &
                     "The installation directory is """ & VbsCaCadGet("InstallationDirectory") & """. " &
                     "The system directory is """       & VbsCaCadGet("SystemFolder")          & """."
       #)
   <$/VbsCaEntry>
<$/VbsCa>
<$VbsCaSetup Binary="Popup.vbs" Entry="HiThere" Seq="StartServices-" CONDITION=^<$CONDITION_INSTALL_ONLY>^ DATA=^PopupCaData^>

  1. 使用 Wix 工具集生成 Unix 包的挑戰是 GUID。幸運的是,mallow.exe 來解救。它可以掃描 src 目錄併為每個元件(目錄或檔案)生成 GUID。
  2. 我們需要弄清楚如何使 pb 生成 wxs xml 檔案,並在 mallow 的幫助下與 candle 和 light 通訊以生成 msi 包。
  1. 以下是一個小型批處理檔案,用於說明建立 msi 包、安裝和刪除此包。

candle 和 light 是一對類似於 redhat 中的 rpmbuild、Max OS X 中的 packagemaker 或 solaris 中的 pkgmk 的命令列包建立工具。

F:\src\wix\tutorial\Sample1>cat batch11.bat
del Sample11.msi
candle -nologo Sample11.wxs
light -nologo Sample11.wixobj
msiexec /i Sample11.msi /l* Sample11.log
rem msiexec /x Sample11.msi /qb
F:\src\wix\tutorial\Sample1>
  1. wix 包源在以下文字中顯示,以下是一些待辦事項。
    1. 將 pbuitils 的 .pb xml 檔案轉換為 wix 的 wxs XML。
    2. 弄清楚 msiexec 如何在沒有實際 .msi 包的情況下使用包 ID 刪除包。
F:\src\wix\tutorial\Sample1>cat Sample11.wxs
<?xml version='1.0' encoding='windows-1252'?>
<Wix xmlns='http://schemas.microsoft.com/wix/2003/01/wi'>
  <Product Name='Foobar 1.0' Id='DB501C18-86C7-4D14-AEC0-86416A69ABDE'
    Language='1028' Codepage='1252'
    Version='1.0.0.0' Manufacturer='Acme Ltd.'>

    <Package Id='7EF38C48-95C1-4015-A361-3806ADA74AAC' Keywords='Installer'
      Description="Acme's Foobar 1.0 Installer"
      Comments='Foobar is a registered trademark of Acme Ltd.' Manufacturer='Acm
e Ltd.'
      InstallerVersion='100' Languages='1028' Compressed='yes' SummaryCodepage='
1252' />

    <Media Id='1' Cabinet='Sample.cab' EmbedCab='yes'
      DiskPrompt="Acme's Foobar 1.0 Installation CD-ROM" />

    <Directory Id='TARGETDIR' Name='SourceDir'>
      <Directory Id='ProgramFilesFolder' Name='PFiles'>
        <Directory Id='Acme' Name='Acme'>
          <Directory Id='INSTALLDIR' Name='Foobar10' LongName='Foobar 1.0'>

            <Component Id='MainExecutable' Guid='DCEECAA4-83F1-4F22-985B-FDB3C8ABD471'>
              <File Id='FoobarEXE' Name='Foobar10.exe' LongName='FoobarAppl10.exe' DiskId='1'
                src='FoobarAppl10.exe' Vital='yes' />
              <Shortcut Id="startmenuFoobar10" Directory="ProgramMenuDir" Name="Foobar10"
                LongName="Foobar 1.0" Target="Complete" WorkingDirectory='INSTALLDIR'
                Icon="Foobar10.exe" IconIndex="0" />
              <Shortcut Id="desktopFoobar10" Directory="DesktopFolder" Name="Foobar10"
                LongName="Foobar 1.0" Target="Complete" WorkingDirectory='INSTALLDIR'
                Icon="Foobar10.exe" IconIndex="0" />
              <File Id='HelperDLL' Name='Helper.dll' DiskId='1' src='Helper.dll' Vital='yes' />
            </Component>

            <Component Id='Manual' Guid='CE36F399-574D-4A9A-A266-5B5EC2C022A4'>
              <File Id='Manual' Name='Manual.pdf' DiskId='1' src='Manual.pdf' />

              <Shortcut Id="startmenuManual" Directory="ProgramMenuDir" Name="Manual"
                LongName="Instruction Manual" Target="Documentation" />
            </Component>

          </Directory>
        </Directory>
      </Directory>

      <Directory Id="ProgramMenuFolder" Name="PMenu" LongName="Programs">
        <Directory Id="ProgramMenuDir" Name='Foobar10' LongName="Foobar 1.0" />
      </Directory>

      <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>

    <Feature Id='Complete' Level='1'>
      <ComponentRef Id='MainExecutable' />
      <ComponentRef Id='Manual' />
    </Feature>

  </Product>
</Wix>

F:\src\wix\tutorial\Sample1>
  • WiX 和 MS 安裝程式的參考資料。
 http://www.tramontana.co.hu/wix/
 http://www.ryanlowe.ca/blog/archives/001167_learning_wix_part_one.php
 http://blogs.msdn.com/robmen/
  • 移植 sbtools
  • 移植 pbtools
  • 移植 pkgutils
  • 移植 sbtools
  • 移植 pbtools
  • 移植 pkgutils
  • 移植 sbtools
  • 移植 pbtools
  • 移植 pkgutils

包管理流程

[編輯 | 編輯原始碼]

軟體工程流程包括透過軟體開發人員設計和實現軟體以生成原始碼。然後需要構建、打包和管理原始碼。我們可以將此流程分為三個步驟。

  • 軟體構建流程 (SB),SB 可以分為以下流程,這些流程在構建機器上執行
    • 原始碼解包
    • 原始碼修補
    • 原始碼配置
    • 構建原始碼以生成二進位制檔案和文件
    • 二進位制檔案測試
    • 二進位制檔案安裝
    • 二進位制檔案解除安裝
  • 包構建 (PB) 流程非常直接
    • 準備配置指令碼
    • 準備初始化指令碼以啟動/停止應用程式服務
    • 呼叫本地 PMS 將二進位制檔案、文件和指令碼打包到本地 PMS 格式中。
  • 包管理 (PKGUTIL) 流程
    • 上傳和管理包在包倉庫伺服器上。
    • 安裝
    • 刪除
    • 升級/修補
    • 包依賴關係自動安裝。

TWW HPMS 簡介

[編輯 | 編輯原始碼]

TWW 公司有三個工具與包管理流程相匹配。

  • 軟體構建
    • sbutils
[root] ls -l /opt/TWWfsw/sbutils12/bin/
total 164
-rwxr-xr-x   1 root     root       38551 Dec  1 15:17 gen-sb-db
-rwxr-xr-x   1 root     root       44418 Dec  1 15:17 sb
[root]
  • 包構建
    • pbutils
[root] ls -l /opt/TWWfsw/pbutils11/bin/
total 186
-rwxr-xr-x   1 root     root       29975 Apr 30  2004 gen-pb-db
-rwxr-xr-x   1 root     root       29169 Apr 30  2004 gen-pkg-db
-rwxr-xr-x   1 root     root       34023 Apr 30  2004 pb
[root]

  • 包管理
    • pkgutils
[root] ls -l /opt/TWWfsw/pkgutils15/bin/
total 542
-rwxr-xr-x   1 root     root       32434 Jan 25  2004 chk-pkg-updates
-rwxr-xr-x   1 root     root       18751 Jan 25  2004 pkg-config
-rwxr-xr-x   1 root     root       48281 Jan 25  2004 pkg-info
-rwxr-xr-x   1 root     root       70570 Jan 25  2004 pkg-inst
-rwxr-xr-x   1 root     other      68887 May 18  2003 pkg-inst~
-rwxr-xr-x   1 root     root       35692 Jan 25  2004 pkg-rm
[root]
  • 如何獲取 TWW 工具?

TWW 公司

[編輯 | 編輯原始碼]

所有 TWW 工具及其支援包的原始碼均符合 GPL 協議。它們在他們的 FTP 站點 ftp://support.thewrittenword.com 上免費提供。但他們的支援勞動和二進位制包並不免費。我們很高興 TWW 公司找到了一種方法來進行開源工作,並且仍然可以從中謀生。如果您的工作場所需要此類服務,請支援 TWW 公司 ( http://shopping.netsuite.com/tww )。

華夏公益教科書