tor.spec.in 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. ## NOTE: tor.spec is autogenerated from tor.spec.in . Edit the latter,
  2. ## not the former.
  3. ## Things that need to be edited frequently
  4. #
  5. # This should be incremented whenever the spec file changes, but
  6. # can drop back to zero at a new Tor version
  7. %define specver 0
  8. ## Things users may want to change
  9. #
  10. # User (and group) name under which the Tor daemon runs.
  11. %define toruser @TORUSER@
  12. %define torgroup @TORGROUP@
  13. ## Target a specific arch and OS
  14. #
  15. # default is i386 linux
  16. ## Override any system rpm macros
  17. #
  18. ## Version song and dance
  19. #
  20. # This should be the Tor version number, as it appears on the tarball,
  21. # including any "pre<x>" or "rc<y>" suffix. This gets massaged to
  22. # create the RPM version number, in a way that depends on the Tor
  23. # numbering scheme.
  24. %define native_version @VERSION@
  25. %define version %(echo %{native_version} | sed -e 's/-/./g')
  26. ## Define output filename
  27. #
  28. # This creates filenames based upon the value of target_cpu defined above
  29. ## Release and OS identification song and dance
  30. #
  31. # This identifies the lineage of the spec file. This file is the
  32. # standard one that comes with Tor; various distributions may
  33. # have their own ideas about the right ways to do things.
  34. %define pkgspec tor
  35. # This spec is intended to build and install on multiple distributions
  36. # (someday). Detect the distribution we're building on.
  37. %define is_rh %(test -e /etc/redhat-release && echo 1 || echo 0)
  38. %define is_fc %(test -e /etc/fedora-release && echo 1 || echo 0)
  39. %define is_mdk %(test -e /etc/mandrake-release && echo 1 || echo 0)
  40. %define is_suse %(test -e /etc/SuSE-release && echo 1 || echo 0)
  41. %define is_rfl %(test -e /etc/redflag-release && echo 1 || echo 0)
  42. %if %{is_fc}
  43. %define ostag %(sed -e 's/^.*release /fc/' -e 's/ .*$//' -e 's/\\./_/g' < /etc/fedora-release)
  44. %else
  45. %if %{is_rh}
  46. %define ostag %(sed -e 's/^.*release /rh/' -e 's/ .*$//' -e 's/\\./_/g' < /etc/redhat-release)
  47. %endif
  48. %endif
  49. # These are probably wrong... just placeholders should we actually
  50. # end up supporting these distributions
  51. %if %{is_mdk}
  52. %define ostag mdk
  53. %endif
  54. %if %{is_suse}
  55. %define ostag suse%(grep openSUSE /etc/SuSE-release | awk '{print $2}' | sed -e 's/\\./_/')
  56. %endif
  57. %if %{is_rfl}
  58. %define ostag %(sed -e 's/^.*Desktop /redflag/' -e 's/ .*$//' -e 's/\\./_/g' < /etc/redflag-release)
  59. %endif
  60. # Using the build date ensures that every build really does get
  61. # a different release number. We use this trick for CVS versions.
  62. # For release versions, we don't want or need it.
  63. %define is_dev_version %(echo %{native_version} | grep 'dev' > /dev/null && echo 1 || echo 0)
  64. %if %{is_dev_version}
  65. %define blddate %(date -u +"%Y%m%d%H%M")
  66. %define release %{pkgspec}.%{specver}.%{ostag}.%{blddate}
  67. %else
  68. %define release %{pkgspec}.%{specver}.%{ostag}
  69. %endif
  70. ## General-purpose macros
  71. #
  72. # Some systems don't have some macros. If a macro doesn't seem
  73. # to exist on your system, add it here...
  74. %if %{!?__make:1}%{?__make:0}
  75. %define __make make
  76. %endif
  77. %if %{!?make:1}%{?make:0}
  78. %define make %{__make}
  79. %endif
  80. %if %{!?_localstatedir:1}%{?_localstatedir:0}
  81. %define _localstatedir @LOCALSTATEDIR@
  82. %endif
  83. ## Package information
  84. #
  85. Name: tor
  86. Version: %{version}
  87. Release: %{release}
  88. Summary: Anonymizing overlay network for TCP (The onion router)
  89. URL: https://www.torproject.org/
  90. Group: System Environment/Daemons
  91. License: 3-clause BSD
  92. Vendor: The Tor Project (https://torproject.org)
  93. Packager: Andrew Lewman <andrew@torproject.org>
  94. %if %{is_suse}
  95. Requires: openssl >= 0.9.7
  96. BuildRequires: openssl-devel >= 0.9.7, rpm >= 4.0, zlib-devel
  97. %else
  98. Requires: openssl >= 0.9.7
  99. BuildRequires: openssl-devel >= 0.9.7
  100. %endif
  101. %if %{is_fc}
  102. BuildRequires: rpm-build >= 4.0
  103. %endif
  104. Requires(pre): /usr/bin/id, /bin/date, /bin/sh
  105. Requires(pre): %{_sbindir}/useradd, %{_sbindir}/groupadd
  106. Source0: https://www.torproject.org/dist/%{name}-%{native_version}.tar.gz
  107. BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root
  108. %description
  109. Tor is a connection-based low-latency anonymous communication system.
  110. This package provides the "tor" program, which serves as both a client and
  111. a relay node. Scripts will automatically create a "%{toruser}" user and
  112. a "%{torgroup}" group, and set tor up to run as a daemon when the system
  113. is rebooted.
  114. Applications connect to the local Tor proxy using the SOCKS
  115. protocol. The tor client chooses a path through a set of relays, in
  116. which each relay knows its predecessor and successor, but no
  117. others. Traffic flowing down the circuit is unwrapped by a symmetric
  118. key at each relay, which reveals the downstream relay.
  119. Warnings: Tor does no protocol cleaning. That means there is a danger
  120. that application protocols and associated programs can be induced to
  121. reveal information about the initiator. Tor depends on Privoxy or
  122. similar protocol cleaners to solve this problem. This is alpha code,
  123. and is even more likely than released code to have anonymity-spoiling
  124. bugs. The present network is small -- this further reduces the
  125. strength of the anonymity provided. Tor is not presently suitable
  126. for high-stakes anonymity.
  127. %prep
  128. %setup -q -n %{name}-%{native_version}
  129. %build
  130. %if %{is_suse}
  131. %configure --with-tor-user=%{toruser} --with-tor-group=%{torgroup}
  132. %else
  133. %configure --with-tor-user=%{toruser} --with-tor-group=%{torgroup}
  134. %endif
  135. %make
  136. %install
  137. %makeinstall
  138. # Install init script and control script
  139. %__mkdir_p ${RPM_BUILD_ROOT}%{_initrddir}
  140. %if %{is_suse}
  141. %__install -p -m 755 contrib/suse/tor.sh ${RPM_BUILD_ROOT}%{_initrddir}/%{name}
  142. %else
  143. %__install -p -m 755 contrib/tor.sh ${RPM_BUILD_ROOT}%{_initrddir}/%{name}
  144. %endif
  145. %__install -p -m 755 contrib/torctl ${RPM_BUILD_ROOT}%{_bindir}
  146. # Set up config file; "sample" file implements a basic user node.
  147. %__install -p -m 644 ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/torrc.sample ${RPM_BUILD_ROOT}%{_sysconfdir}/%{name}/torrc
  148. # Install the logrotate control file.
  149. %__mkdir_p -m 755 ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d
  150. %__install -p -m 644 contrib/tor.logrotate ${RPM_BUILD_ROOT}%{_sysconfdir}/logrotate.d/%{name}
  151. # Directories that don't have any preinstalled files
  152. %__mkdir_p -m 700 ${RPM_BUILD_ROOT}%{_localstatedir}/lib/%{name}
  153. %__mkdir_p -m 755 ${RPM_BUILD_ROOT}%{_localstatedir}/run/%{name}
  154. %__mkdir_p -m 755 ${RPM_BUILD_ROOT}%{_localstatedir}/log/%{name}
  155. %__mkdir_p -m 700 ${RPM_BUILD_ROOT}%{_localstatedir}/tmp/%{name}
  156. %clean
  157. [ "${RPM_BUILD_ROOT}" != "/" ] && rm -rf ${RPM_BUILD_ROOT}
  158. # These scripts are probably wrong for Mandrake or SuSE. They're certainly
  159. # wrong for Debian, but what are you doing using RPM on Debian?
  160. %pre
  161. # If tor is already installed and running (whether installed by RPM
  162. # or not), then kill it, but remember that it was running.
  163. %__rm -f /%{_localstatedir}/tmp/${name}-was-running-%{version}-%{release}
  164. if [ -f %{_initrddir}/%{name} ] && /sbin/service %{name} status ; then
  165. /sbin/service %{name} stop
  166. touch /%{_localstatedir}/tmp/${name}-was-running-%{version}-%{release}
  167. fi
  168. #
  169. # Create a user and group if need be
  170. #
  171. if [ ! -n "`/usr/bin/id -g %{torgroup} 2>/dev/null`" ]; then
  172. # One would like to default the GID, but doing that properly would
  173. # require thought.
  174. %{_sbindir}/groupadd %{torgroup} 2> /dev/null
  175. fi
  176. if [ ! -n "`/usr/bin/id -u %{toruser} 2>/dev/null`" ]; then
  177. # One would also like to default the UID, but doing that properly would
  178. # also require thought.
  179. if [ -x %{_sbindir}/nologin ]; then
  180. %{_sbindir}/useradd -r -g %{torgroup} -d% {_localstatedir}/lib/%{name} -s %{_sbindir}/nologin %{toruser} 2> /dev/null
  181. else
  182. %{_sbindir}/useradd -r -g %{torgroup} -d %{_localstatedir}/lib/%{name} -s /bin/false %{toruser} 2> /dev/null
  183. fi
  184. fi
  185. exit 0
  186. %post
  187. # If this is a new installation, use chkconfig to put tor in the
  188. # default set of runlevels. If it's an upgrade, leave the existing
  189. # configuration alone.
  190. if [ $1 -eq 1 ]; then
  191. /sbin/chkconfig --add %{name}
  192. /sbin/chkconfig %{name} on
  193. fi
  194. # Older tor RPMS used a different username for the tor daemon.
  195. # Make sure the runtime data have the right ownership.
  196. %__chown -R %{toruser}.%{torgroup} %{_localstatedir}/{lib,log,run}/%{name}
  197. if [ -f /%{_localstatedir}/tmp/${name}-was-running-%{version}-%{release} ]; then
  198. /sbin/service %{name} start
  199. %__rm -f /%{_localstatedir}/tmp/${name}-was-running-%{version}-%{release}
  200. fi
  201. exit 0
  202. %preun
  203. # If no instances of tor will be installed when we're done, make
  204. # sure that it gets killed. We *don't* want to kill it or delete
  205. # any of its data on uninstall if it's being upgraded to a new
  206. # version, because the new version will actually already have
  207. # been installed and started before the uninstall script for
  208. # the old version is run, and we'd end up hosing it.
  209. if [ $1 -le 0 ]; then
  210. if [ -f %{_initrddir}/%{name} ] && /sbin/service %{name} status ; then
  211. /sbin/service %{name} stop
  212. fi
  213. %/sbin/chkconfig --del %{name}
  214. %__rm -f ${_localstatedir}/lib/%{name}/cached-directory
  215. %__rm -f ${_localstatedir}/lib/%{name}/bw_accounting
  216. %__rm -f ${_localstatedir}/lib/%{name}/control_auth_cookie
  217. %__rm -f ${_localstatedir}/lib/%{name}/router.desc
  218. %__rm -f ${_localstatedir}/lib/%{name}/fingerprint
  219. fi
  220. exit 0
  221. %files
  222. %defattr(-,root,root)
  223. %doc AUTHORS INSTALL LICENSE README ChangeLog doc/HACKING doc/TODO
  224. %{_mandir}/man*/*
  225. %{_bindir}/tor
  226. %{_bindir}/torctl
  227. %{_bindir}/torify
  228. %{_bindir}/tor-resolve
  229. %{_bindir}/tor-gencert
  230. %{_datadir}/tor/geoip
  231. %config %{_initrddir}/%{name}
  232. %config(noreplace) %attr(0644,root,root) %{_sysconfdir}/logrotate.d/%{name}
  233. %dir %attr(0755,root,%{torgroup}) %{_sysconfdir}/%{name}/
  234. %config(noreplace) %attr(0644,root,%{torgroup}) %{_sysconfdir}/%{name}/*
  235. %attr(0700,%{toruser},%{torgroup}) %dir %{_localstatedir}/lib/%{name}
  236. %attr(0750,%{toruser},%{torgroup}) %dir %{_localstatedir}/run/%{name}
  237. %attr(0750,%{toruser},%{torgroup}) %dir %{_localstatedir}/log/%{name}
  238. %changelog
  239. * Sun Feb 22 2009 Andrew Lewman <andrew@torproject.org>
  240. - update the description, vendor, and packager
  241. * Thu Sep 11 2008 Andrew Lewman <phobos@rootme.org>
  242. - See r16867
  243. - http://archives.seul.org/or/cvs/Sep-2008/msg00156.html
  244. * Tue Feb 27 2007 Andrew Lewman <phobos@rootme.org>
  245. - Fix a potential race condition in how we determine the running state of tor. Found by Stefan Nordhausen.
  246. - see OR-CVS for details
  247. * Fri May 26 2006 Andrew Lewman <phobos@rootme.org>
  248. - Add in a few "SUSEisms" to make dist-rpm actually work on suse
  249. - Turn Tor "on" via chkconfig
  250. - Update -mcpu to -mtune to make GCC happy
  251. - see OR-CVS for details
  252. * Tue Mar 28 2006 Andrew Lewman <phobos@rootme.org>
  253. - converted to build the specified target cpu and arch
  254. - override related rpm macros to build correctly
  255. - see OR-CVS for details
  256. * Mon Jan 17 2005 John Bashinski <jbash@velvet.com>
  257. - Take runtime user and group names from configure system. Default
  258. user/group names are now "_tor"; blame Roger...
  259. - Make logrotate control file a separate file in the source distribution,
  260. rather than creating it from the spec file.
  261. - Properly handle the order in which RPM executes scriptlets on upgrade.
  262. The old code would kill the daemon on upgrade.
  263. - Start the tor daemon after installation if and only if it was
  264. running before installation. Preserve runlevel setup on upgrade.
  265. - Package the torctl script; the init script is now a wrapper around it.
  266. * Tue Nov 5 2004 John Bashinski <jbash@velvet.com>
  267. - Add skeletal support for multiple distributions
  268. - Even more ridiculous level of macro-ization
  269. - Modify version numbers so RPM can determine when it has a newer version
  270. - Return to including distribution name in package release number
  271. - Sharply trim description
  272. - Change user/group name from "tor" to "tordmn"; "tor" is a common
  273. given name (reported by Marius Hjelle)
  274. - Change group to "System Environment/Daemons" (suggested by Marius Hjelle)
  275. - Create logrotate file (suggested by Marius Hjelle)
  276. - Make Tor run as a user proxy by default (suggested by Marius Hjelle)
  277. - Autogenerate spec file from GNU autotools data, substituting version
  278. and whatnot
  279. - Be perhaps excessively paranoid with config file and directory modes
  280. - Remove auto-start and auto-stop at installation time; there's some kind
  281. of weird race going on, and it's arguably a bad thing anyway.
  282. * Mon Jun 06 2004 Nick Mathewson <nickm@freehaven.net> 0.0.7-0.std.0.1.rc2
  283. - Make spec file more happy with fc2 packaging
  284. * Sat Jan 17 2004 John Bashinski <jbash@velvet.com>
  285. - Basic spec file; tested with Red Hat 9.