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