makedepends=(systemd libevent  )

description="Tor is a anonymous network and proxy."
url="http://www.torproject.org/"

packager="Great-OS Team"
contributors="rems"

name=tor
version=0.4.9.5
release=1

source=(https://www.torproject.org/dist/tor-$version.tar.gz
        tor.rc
        tor-config.patch)

prepare() {
  cd $name-$version
  patch -p 1 -i ../tor-config.patch

  # fix for find: The relative path `~/bin' is included in the PATH
  # environment variable, which is insecure in combination with the
  # -execdir action of find. Please remove that entry from $PATH
  export PATH='/sbin:/usr/sbin:/bin:/usr/bin'
}

build() {
  cd $name-$version
  ./configure --prefix=/usr \
              --localstatedir=/var \
              --sysconfdir=/etc \
              --enable-systemd

  make
  make DESTDIR=$PKG install

  install -d $PKG/var/lib/tor

  chown root:root $PKG/var/lib/tor

  touch $PKG/var/lib/tor/cached-certs \
        $PKG/var/lib/tor/cached-consensus \
        $PKG/var/lib/tor/cached-descriptors \
        $PKG/var/lib/tor/cached-descriptors.new \
        $PKG/var/lib/tor/cached-routers.new \
        $PKG/var/lib/tor/state

  find $PKG/var/lib/tor/ -type f -execdir chown root:root {} \; -execdir chmod 0600 {} \;

  mv $PKG/etc/tor/torrc.sample $PKG/etc/tor/torrc
  find $PKG/etc/tor/ -type f -exec chown root:tor {} \; -execdir chmod 0640 {} \;

  find $PKG/usr/bin -type f -execdir chown root:tor {} \; -execdir chmod 0750 {} \;

  install -d $PKG/var/log/tor
  chown root:root $PKG/var/log/tor
  touch $PKG/var/log/tor/notices.log
  find $PKG/var/log/tor/ -type f -exec chown root:root {} \; -execdir chmod 0640 {} \;

  install -m 0750 -D $SRC/tor.rc $PKG/etc/rc.d/tor
}
