package.sh 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. #!/bin/sh
  2. # $Id$
  3. # Copyright 2004-2005 Nick Mathewson.
  4. # Copyright 2005-2007 Andrew Lewman
  5. # Copyright 2008 The Tor Project
  6. # See LICENSE in Tor distribution for licensing information.
  7. # This script builds a Macintosh OS X metapackage containing 2 packages:
  8. # - One for Tor.
  9. # - One for Startup scripts for Tor.
  10. #
  11. # This script expects to be run from the toplevel makefile, with VERSION
  12. # set to the latest Tor version, and Tor already built.
  13. #
  14. # Read the documentation located in tor/doc/tor-osx-dmg-creation.txt on
  15. # how to build Tor for OSX
  16. ###
  17. # Helpful info on OS X packaging:
  18. # http://developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/index.html
  19. # man packagemaker
  20. # Make sure VERSION is set, so we don't name the package
  21. # "Tor--$OS-$ARCH-Bundle.dmg"
  22. if [ "XX$VERSION" = 'XX' ]; then
  23. echo "VERSION not set."
  24. exit 1
  25. fi
  26. ## Determine OSX Version
  27. # map version to name
  28. if [ -x /usr/bin/sw_vers ]; then
  29. # This is poor, yet functional. We don't care about the 3rd number in
  30. # the OS version
  31. OSVER=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 | cut -d"." -f1,2`
  32. case "$OSVER" in
  33. "10.6") OS="snowleopard" ARCH="universal";;
  34. "10.5") OS="leopard" ARCH="universal";;
  35. "10.4") OS="tiger" ARCH="universal";;
  36. "10.3") OS="panther" ARCH="ppc";;
  37. "10.2") OS="jaguar" ARCH="ppc";;
  38. "10.1") OS="puma" ARCH="ppc";;
  39. "10.0") OS="cheetah" ARCH="ppc";;
  40. *) OS="unknown";;
  41. esac
  42. else
  43. OS="unknown"
  44. fi
  45. # Where will we put our temporary files?
  46. BUILD_DIR=/tmp/tor-osx-$$
  47. # Path to PackageMaker app.
  48. PACKAGEMAKER=/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
  49. umask 022
  50. echo I might ask you for your password now, so you can sudo.
  51. sudo rm -rf $BUILD_DIR
  52. mkdir $BUILD_DIR || exit 1
  53. for subdir in tor_packageroot tor_resources \
  54. torstartup_packageroot \
  55. torbundle_resources \
  56. output; do
  57. mkdir $BUILD_DIR/$subdir
  58. done
  59. ### Make Tor package.
  60. make install DESTDIR=$BUILD_DIR/tor_packageroot
  61. cp contrib/osx/ReadMe.rtf $BUILD_DIR/tor_resources
  62. chmod 755 contrib/osx/TorPostflight
  63. cp contrib/osx/TorPostflight $BUILD_DIR/tor_resources/postflight
  64. cp contrib/osx/addsysuser $BUILD_DIR/tor_resources/addsysuser
  65. cp contrib/osx/Tor_Uninstaller.applescript $BUILD_DIR/tor_resources/Tor_Uninstaller.applescript
  66. cp contrib/osx/uninstall_tor_bundle.sh $BUILD_DIR/tor_resources/uninstall_tor_bundle.sh
  67. cp contrib/osx/package_list.txt $BUILD_DIR/tor_resources/package_list.txt
  68. cp contrib/osx/tor_logo.gif $BUILD_DIR/tor_resources/background.gif
  69. cp src/config/geoip $BUILD_DIR/tor_resources/geoip
  70. cat <<EOF > $BUILD_DIR/tor_resources/Welcome.txt
  71. Tor: an anonymous Internet communication system
  72. Tor is a system for using the internet anonymously, and allowing
  73. others to do so.
  74. EOF
  75. ### Assemble documentation
  76. DOC=$BUILD_DIR/tor_resources/documents
  77. mkdir $DOC
  78. mkdir $DOC/howto
  79. cp AUTHORS $DOC/AUTHORS.txt
  80. groff doc/tor.1.in -T ps -m man | pstopdf -i -o $DOC/tor-reference.pdf
  81. groff doc/tor-resolve.1 -T ps -m man | pstopdf -i -o $DOC/tor-resolve.pdf
  82. mkdir $DOC/Advanced
  83. cp doc/spec/tor-spec.txt \
  84. doc/spec/rend-spec.txt \
  85. doc/spec/control-spec.txt \
  86. doc/spec/socks-extensions.txt \
  87. doc/spec/version-spec.txt \
  88. doc/spec/address-spec.txt \
  89. doc/spec/path-spec.txt \
  90. $DOC/Advanced
  91. cp doc/HACKING $DOC/Advanced/HACKING.txt
  92. cp ChangeLog $DOC/Advanced/ChangeLog.txt
  93. find $BUILD_DIR/tor_packageroot -print0 |sudo xargs -0 chown root:wheel
  94. $PACKAGEMAKER -build \
  95. -p $BUILD_DIR/output/Tor.pkg \
  96. -f $BUILD_DIR/tor_packageroot \
  97. -r $BUILD_DIR/tor_resources \
  98. -i contrib/osx/TorInfo.plist \
  99. -d contrib/osx/TorDesc.plist
  100. ### Make Startup Script package
  101. mkdir -p $BUILD_DIR/torstartup_packageroot/Library/StartupItems/Tor
  102. cp contrib/osx/Tor contrib/osx/StartupParameters.plist \
  103. $BUILD_DIR/torstartup_packageroot/Library/StartupItems/Tor
  104. find $BUILD_DIR/torstartup_packageroot -print0 | sudo xargs -0 chown root:wheel
  105. $PACKAGEMAKER -build \
  106. -p $BUILD_DIR/output/torstartup.pkg \
  107. -f $BUILD_DIR/torstartup_packageroot \
  108. -i contrib/osx/TorStartupInfo.plist \
  109. -d contrib/osx/TorStartupDesc.plist
  110. ### Assemble the metapackage. Packagemaker won't buld metapackages from
  111. # the command line, so we need to do it by hand.
  112. MPKG=$BUILD_DIR/output/Tor-$VERSION-$OS-$ARCH-Bundle.mpkg
  113. mkdir -p "$MPKG/Contents/Resources"
  114. echo -n "pmkrpkg1" > "$MPKG/Contents/PkgInfo"
  115. cp contrib/osx/ReadMe.rtf "$MPKG/Contents/Resources"
  116. cp contrib/osx/TorBundleInfo.plist "$MPKG/Contents/Info.plist"
  117. cp contrib/osx/TorBundleWelcome.rtf "$MPKG/Contents/Resources/Welcome.rtf"
  118. cp contrib/osx/TorBundleDesc.plist "$MPKG/Contents/Resources/Description.plist"
  119. cp contrib/osx/tor_logo.gif "$MPKG/Contents/Resources/background.gif"
  120. # Move all the subpackages into place.
  121. mkdir $BUILD_DIR/output/.contained_packages
  122. mv $BUILD_DIR/output/*.pkg $BUILD_DIR/OUTPUT/.contained_packages
  123. ( cd $BUILD_DIR/output/.contained_packages )
  124. ### Copy readmes and licenses into toplevel.
  125. cp contrib/osx/ReadMe.rtf $BUILD_DIR/output/Tor\ ReadMe.rtf
  126. cp LICENSE $BUILD_DIR/output/Tor\ License.txt
  127. ### Package it all into a DMG
  128. find $BUILD_DIR/output -print0 | sudo xargs -0 chown root:wheel
  129. mv $BUILD_DIR/output "$BUILD_DIR/Tor-$VERSION-$OS-$ARCH-Bundle"
  130. rm -f "Tor-$VERSION-$OS-$ARCH-Bundle.dmg"
  131. USER="`whoami`"
  132. sudo hdiutil create -format UDZO -srcfolder "$BUILD_DIR/Tor-$VERSION-$OS-$ARCH-Bundle" "Tor-$VERSION-$OS-$ARCH-Bundle.dmg"
  133. sudo chown "$USER" "Tor-$VERSION-$OS-$ARCH-Bundle.dmg"
  134. sudo rm -rf $BUILD_DIR