<file_sep>## Proxy-auto-discovery for command line applications (pac4cli)

![CircleCI](https://img.shields.io/circleci/project/github/tkluck/pac4cli.svg)

### Introduction

On many corporate networks, applications need
[proxy-auto-discovery](https://en.wikipedia.org/wiki/Web_Proxy_Auto-Discovery_Protocol)
to know whether a certain URL is accessed either directly or through a web
proxy. Browsers can typically handle this, but many command line applications
(git, npm, apt, curl) rely on environment variable to hard-code a proxy
regardless of the destination URL.

This little daemon enables these applications for auto-discovery by:

- setting the `http_proxy` variable (and friends) to http://localhost:3128
- providing a simple proxy at that port that does proxy-auto-discovery and
  connects accordingly.

System dependencies:
- systemd
- NetworkManager

Python library dependencies from PyPI can be installed through:

    sudo pip3 install -r requirements.txt

### Installation instructions

#### Ubuntu

The latest builds are available through a PPA:

    sudo add-apt-repository ppa:tkluck/pac4cli
    sudo apt update
    sudo apt install pac4cli

You'll need to restart your shell for the new environment variables to take effect.

#### Archlinux

This package is available in AUR.

#### Other (Mac, other linuxes)

The dependencies can be installed through

    pip3 install -r requirements.txt

Then, use

    make install


<file_sep>#!/bin/sh

/bin/systemctl kill -s SIGHUP pac4cli
<file_sep>incremental
twisted
pyOpenSSL
service_identity
dbus-python
txdbus; sys_platform == "linux"
systemd; sys_platform == "linux"
<file_sep># Maintainer: <NAME> <khalid # kdehairy / com>
_pacparser_pkgver=1.3.7
_txdbus_pkgver=1.0.14
_systemd_pkgver=0.9.5
_service_identity_pkgver=17.0.0

pkgname=pac4cli-git
pkgver=0.1
pkgrel=1
pkgdesc="Proxy-auto-discovery for command line applications"
arch=('i686' 'x86_64')
url="https://github.com/tkluck/pac4cli"
license=('GPL3')
depends=('python>=3.6' 'python-twisted' 'python-pyopenssl' 'libsystemd' 'networkmanager' 'python-pyopenssl' 
		'python-pyasn1' 'python-pyasn1-modules' 'python-attrs')
makedepends=('git' 'python-pyasn1' 'python-pyasn1-modules' 'python-attrs' 'python-idna')
provides=('python-pacparser')
install=${pkgname%-git}.install
source=("${pkgname%-git}::git+https://github.com/tkluck/pac4cli.git"
		"https://github.com/pacparser/pacparser/archive/${_pacparser_pkgver}.tar.gz"
		"https://github.com/cocagne/txdbus/archive/${_txdbus_pkgver}.tar.gz"
		"https://files.pythonhosted.org/packages/source/s/systemd/systemd-${_systemd_pkgver}.tar.gz"
		"https://files.pythonhosted.org/packages/source/s/service_identity/service_identity-${_service_identity_pkgver}.tar.gz")
md5sums=('SKIP' 'SKIP' 'SKIP' 'SKIP' 'SKIP')

pkgver() {
	cd "$srcdir/${pkgname%-git}"
	LATEST_TAG=$(git describe --tags --abbrev=0 --match 'v*' 2>/dev/null)
	printf "%s" "${LATEST_TAG#*v}"
}

build() {
	#builds pacparser
	cd "${srcdir}/pacparser-${_pacparser_pkgver}"
	PYTHON=python3 make all pymod -C src

	#service_identity
	cd "${srcdir}/service_identity-${_service_identity_pkgver}"
	python3 setup.py build
}

package() {
	#package pacparser
	cd "${srcdir}/pacparser-${_pacparser_pkgver}"
	PYTHON=python3 make DESTDIR="${pkgdir}" -C src install-pymod

	#txdbus
	cd "${srcdir}/txdbus-${_txdbus_pkgver}"
	python3 setup.py install --root="${pkgdir}/" --prefix=/usr --optimize=1

	#systemd
	cd "${srcdir}/systemd-${_systemd_pkgver}"
	python3 setup.py install --root="${pkgdir}/" --prefix=/usr --optimize=1

	#service_identity
	cd "${srcdir}/service_identity-${_service_identity_pkgver}"
	python3 setup.py install --root="${pkgdir}/" --prefix=/usr --optimize=1 --skip-build

	#package pac4cli
	cd "${srcdir}/${pkgname%-git}"
	LATEST_TAG=$(git describe --tags --abbrev=0 --match 'v*' 2>/dev/null)	# get latest release tag
	if [[ "x${LATEST_TAG}" == "x" ]]; then
		echo "Could not find any releases to build."
		exit 1;
	fi
	git checkout ${LATEST_TAG}										# checkout latest release tag
	PYTHON=python3 make pythonsitedir=/usr/lib/python3.6/site-packages DESTDIR="${pkgdir}" prefix=/usr install
}
