#!/bin/bash

## Copyright (C) 2012 - 2025 ENCRYPTED SUPPORT LLC <adrelanos@whonix.org>
## See the file COPYING for copying conditions.

#### meta start
#### project Whonix
#### category networking and apps
#### workstation_only yes
#### description
## Emulates Tor by copying and chmodding the correct state files such as
## <code>/run/tor/control.authcookie</code>.
#### meta end

set -e

mkdir --parents /run/tor --mode=2755
mkdir --parents /var/lib/tor --mode=2700

## system Tor default '/run/tor/control.authcookie' auth cookie file
cp /usr/share/anon-ws-disable-stacked-tor/control.authcookie /run/tor/control.authcookie
chmod 640 /run/tor/control.authcookie

## tor-firejail uses '/run/tor/control_auth_cookie' auth cookie file
## https://git.schwanenlied.me/yawning/tor-firejail/src/master/start-tor-browser
## https://lists.torproject.org/pipermail/tor-dev/2016-July/011226.html
## https://lists.torproject.org/pipermail/tor-dev/2016-July/011227.html
cp /usr/share/anon-ws-disable-stacked-tor/control.authcookie /run/tor/control_auth_cookie
chmod 640 /run/tor/control_auth_cookie

## Tor by default uses '/var/lib/tor/control_auth_cookie' auth cookie file
## https://trac.torproject.org/projects/tor/ticket/19572
cp /usr/share/anon-ws-disable-stacked-tor/control.authcookie /var/lib/tor/control_auth_cookie
chmod 640 /var/lib/tor/control_auth_cookie

chown --recursive debian-tor:debian-tor /run/tor
chown --recursive debian-tor:debian-tor /var/lib/tor
