r11521@catbus: nickm | 2007-01-26 01:07:55 -0500
[tor.git] / contrib / osx / package.sh
blob1dee597ac194e87f6f12bdf281e87e2736f77479
1 #!/bin/sh
2 # $Id$
3 # Copyright 2004-2005 Nick Mathewson.
4 # See LICENSE in Tor distribution for licensing information.
6 # This script builds a Macintosh OS X metapackage containing 4 packages:
7 # - One for Tor.
8 # - One for Privoxy.
9 # - One for a tor-specific privoxy configuration script.
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 # Where have we put the zip file containing Privoxy? Edit this if your
20 # privoxy lives somewhere else.
21 PRIVOXY_PKG_ZIP=~/tmp/privoxyosx_setup_3.0.6.zip
23 ###
24 # Helpful info on OS X packaging:
25 # http://developer.apple.com/documentation/DeveloperTools/Conceptual/SoftwareDistribution/index.html
26 # man packagemaker
28 # Make sure VERSION is set, so we don't name the package
29 # "Tor--$OS-$ARCH-Bundle.dmg"
30 if [ "XX$VERSION" = 'XX' ]; then
31 echo "VERSION not set."
32 exit 1
35 ## Determine OSX Version
36 # map version to name
37 if [ -x /usr/bin/sw_vers ]; then
38 # This is poor, yet functional. We don't care about the 3rd number in
39 # the OS version
40 OSVER=`/usr/bin/sw_vers | grep ProductVersion | cut -f2 | cut -d"." -f1,2`
41 case "$OSVER" in
42 "10.5") OS="leopard" ARCH="universal";;
43 "10.4") OS="tiger" ARCH="universal";;
44 "10.3") OS="panther" ARCH="ppc";;
45 "10.2") OS="jaguar" ARCH="ppc";;
46 "10.1") OS="puma" ARCH="ppc";;
47 "10.0") OS="cheetah" ARCH="ppc";;
48 *) OS="unknown";;
49 esac
50 else
51 OS="unknown"
54 # Where will we put our temporary files?
55 BUILD_DIR=/tmp/tor-osx-$$
56 # Path to PackageMaker app.
57 PACKAGEMAKER=/Developer/Applications/Utilities/PackageMaker.app/Contents/MacOS/PackageMaker
59 umask 022
61 echo I might ask you for your password now, so you can sudo.
63 sudo rm -rf $BUILD_DIR
64 mkdir $BUILD_DIR || exit 1
65 for subdir in tor_packageroot tor_resources \
66 torstartup_packageroot \
67 privoxyconf_packageroot \
68 torbundle_resources \
69 output; do
70 mkdir $BUILD_DIR/$subdir
71 done
73 ### Make Tor package.
74 make install DESTDIR=$BUILD_DIR/tor_packageroot
75 #mv $BUILD_DIR/tor_packageroot/Library/Tor/torrc.sample $BUILD_DIR/tor_packageroot/Library/Tor/torrc
76 cp contrib/osx/ReadMe.rtf $BUILD_DIR/tor_resources
77 #cp contrib/osx/License.rtf $BUILD_DIR/tor_resources
78 chmod 755 contrib/osx/TorPostflight
79 cp contrib/osx/TorPostflight $BUILD_DIR/tor_resources/postflight
80 cp contrib/osx/addsysuser $BUILD_DIR/tor_resources/addsysuser
81 cp contrib/osx/Tor_Uninstaller.applescript $BUILD_DIR/tor_resources/Tor_Uninstaller.applescript
82 cp contrib/osx/uninstall_tor_bundle.sh $BUILD_DIR/tor_resources/uninstall_tor_bundle.sh
83 cp contrib/osx/package_list.txt $BUILD_DIR/tor_resources/package_list.txt
84 cp contrib/osx/tor_logo.gif $BUILD_DIR/tor_resources/background.gif
85 cat <<EOF > $BUILD_DIR/tor_resources/Welcome.txt
86 Tor: an anonymous Internet communication system
88 Tor is a system for using the internet anonymously, and allowing
89 others to do so.
90 EOF
92 ### Assemble documentation
94 DOC=$BUILD_DIR/tor_resources/documents
95 mkdir $DOC
96 mkdir $DOC/howto
97 #cp doc/website/stylesheet.css doc/website/tor-doc-osx.html.* $DOC/howto
98 #cp doc/website/tor-doc-server.html.* $DOC/howto
99 #cp doc/website/tor-hidden-service.html.* $DOC/howto
100 #cp doc/website/tor-switchproxy.html.* $DOC/howto
101 #mkdir $DOC/img
102 #cp doc/img/screenshot-osx* $DOC/img
103 cp AUTHORS $DOC/AUTHORS.txt
104 groff doc/tor.1.in -T ps -m man | pstopdf -i -o $DOC/tor-reference.pdf
105 groff doc/tor-resolve.1 -T ps -m man | pstopdf -i -o $DOC/tor-resolve.pdf
106 mkdir $DOC/Advanced
107 cp doc/tor-spec.txt doc/rend-spec.txt doc/control-spec.txt doc/socks-extensions.txt doc/version-spec.txt $DOC/Advanced
108 cp doc/HACKING $DOC/Advanced/HACKING.txt
109 cp ChangeLog $DOC/Advanced/ChangeLog.txt
111 find $BUILD_DIR/tor_packageroot -print0 |sudo xargs -0 chown root:wheel
113 $PACKAGEMAKER -build \
114 -p $BUILD_DIR/output/Tor.pkg \
115 -f $BUILD_DIR/tor_packageroot \
116 -r $BUILD_DIR/tor_resources \
117 -i contrib/osx/TorInfo.plist \
118 -d contrib/osx/TorDesc.plist
120 ### Put privoxy configuration package in place.
121 mkdir -p $BUILD_DIR/privoxyconf_packageroot/Library/Privoxy
122 cp contrib/osx/privoxy.config $BUILD_DIR/privoxyconf_packageroot/Library/Privoxy/config
124 find $BUILD_DIR/privoxyconf_packageroot -print0 |sudo xargs -0 chown root:wheel
126 $PACKAGEMAKER -build \
127 -p $BUILD_DIR/output/privoxyconf.pkg \
128 -f $BUILD_DIR/privoxyconf_packageroot \
129 -i contrib/osx/PrivoxyConfInfo.plist \
130 -d contrib/osx/PrivoxyConfDesc.plist
132 ### Make Startup Script package
134 mkdir -p $BUILD_DIR/torstartup_packageroot/Library/StartupItems/Tor
135 cp contrib/osx/Tor contrib/osx/StartupParameters.plist \
136 $BUILD_DIR/torstartup_packageroot/Library/StartupItems/Tor
138 find $BUILD_DIR/torstartup_packageroot -print0 | sudo xargs -0 chown root:wheel
139 $PACKAGEMAKER -build \
140 -p $BUILD_DIR/output/torstartup.pkg \
141 -f $BUILD_DIR/torstartup_packageroot \
142 -i contrib/osx/TorStartupInfo.plist \
143 -d contrib/osx/TorStartupDesc.plist
145 ### Assemble the metapackage. Packagemaker won't buld metapackages from
146 # the command line, so we need to do it by hand.
148 MPKG=$BUILD_DIR/output/Tor-$VERSION-$OS-$ARCH-Bundle.mpkg
149 mkdir -p "$MPKG/Contents/Resources"
150 echo -n "pmkrpkg1" > "$MPKG/Contents/PkgInfo"
151 cp contrib/osx/ReadMe.rtf "$MPKG/Contents/Resources"
152 #cp contrib/osx/License.rtf "$MPKG/Contents/Resources"
153 cp contrib/osx/TorBundleInfo.plist "$MPKG/Contents/Info.plist"
154 cp contrib/osx/TorBundleWelcome.rtf "$MPKG/Contents/Resources/Welcome.rtf"
155 cp contrib/osx/TorBundleDesc.plist "$MPKG/Contents/Resources/Description.plist"
156 cp contrib/osx/tor_logo.gif "$MPKG/Contents/Resources/background.gif"
158 # Move all the subpackages into place. unzip Privoxy.pkg into place,
159 # and fix its file permissions so we can rm -rf it later.
160 mkdir $BUILD_DIR/output/.contained_packages
161 mv $BUILD_DIR/output/*.pkg $BUILD_DIR/OUTPUT/.contained_packages
162 ( cd $BUILD_DIR/output/.contained_packages && unzip $PRIVOXY_PKG_ZIP && find Privoxy.pkg -type d -print0 | xargs -0 chmod u+w )
164 ### Copy readmes and licenses into toplevel.
165 PRIVOXY_RESDIR=$BUILD_DIR/output/.contained_packages/Privoxy.pkg/Contents/Resources
166 cp $PRIVOXY_RESDIR/License.html $BUILD_DIR/output/Privoxy\ License.html
167 cp $PRIVOXY_RESDIR/ReadMe.txt $BUILD_DIR/output/Privoxy\ ReadMe.txt
168 cp contrib/osx/ReadMe.rtf $BUILD_DIR/output/Tor\ ReadMe.rtf
169 cp LICENSE $BUILD_DIR/output/Tor\ License.txt
171 ### Package it all into a DMG
173 find $BUILD_DIR/output -print0 | sudo xargs -0 chown root:wheel
175 mv $BUILD_DIR/output "$BUILD_DIR/Tor-$VERSION-$OS-$ARCH-Bundle"
176 rm -f "Tor-$VERSION-$OS-$ARCH-Bundle.dmg"
177 USER="`whoami`"
178 sudo hdiutil create -format UDZO -srcfolder "$BUILD_DIR/Tor-$VERSION-$OS-$ARCH-Bundle" "Tor-$VERSION-$OS-$ARCH-Bundle.dmg"
179 sudo chown "$USER" "Tor-$VERSION-$OS-$ARCH-Bundle.dmg"
181 sudo rm -rf $BUILD_DIR