-# whoever runs this script.
-P_PIDFILE=`pwd`/${P_USER}.pid
-# User that will own the Privoxy process.
-P_DAEMON_OWNER="$USER"
+# whoever runs this script and by Privoxy itself.
+P_PIDFILE=/var/run/privoxy.pid
+# If uncommented, this script will try to run as USER=privoxy, which
+# may require special handling of config, *.action, trust, logfile,
+# jarfile, and pidfile.
+P_USER=privoxy
+
+# If a privoxy user is specified, lets try that. /bin/sh does not seem to
+# know about $UID.
+if [ 0 = `id -u` ]; then
+ if [ -n "$P_USER" ]; then
+ id $P_USER 2>/dev/null >/dev/null
+ if [ $? -eq 0 ]; then
+ P_USER_SETTINGS="--user $P_USER"
+ else
+ echo "User $P_USER doesn't exist, exiting."
+ exit 1
+ fi
+ else
+ # The user has sufficient rights, but $P_USER isn't set
+ echo "Running Privoxy as root is not recommended!"
+ P_USER_SETTINGS=""
+ fi
+else
+ # The user has insufficient rights to run Privoxy as $P_USER
+ # and may not be able to write or delete the PID file.
+ echo "You aren't root, expect trouble!"
+ P_USER_SETTINGS=""
+fi