tor.spec.in 13 KB

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