]> git.proxmox.com Git - mirror_lxc.git/blame - hooks/squid-deb-proxy-client
Merge pull request #2842 from brauner/2019-02-11/fix_licensing
[mirror_lxc.git] / hooks / squid-deb-proxy-client
CommitLineData
4213a747
CG
1#!/bin/sh
2#
3# Make the cloned container aware of squid-deb-proxy settings at start.
4#
5# Copyright © 2014 Christopher Glass.
6#
7# This library is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License version 2, as
9# published by the Free Software Foundation.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License along
17# with this program; if not, write to the Free Software Foundation, Inc.,
18# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19
20# When starting a container, inject the squid-deb-proxy-client proxy
21# address in the container's apt configuration.
22# This script should be added to templates as a pre-start script, such as:
23#lxc.hook.pre-start=/usr/share/lxc/hooks/squid-deb-proxy-client
24
25discovery_script=/usr/share/squid-deb-proxy-client/apt-avahi-discover
26proxy_file=/etc/apt/apt.conf.d/50squid-deb-proxy
959dd8f2 27container_proxy_file=$LXC_ROOTFS_PATH$proxy_file
4213a747
CG
28
29if [ -f $proxy_file ]; then
30 # The host has a proxy file - let's propagate the config to the guest.
4213a747
CG
31 cat $proxy_file > $container_proxy_file
32 exit 0
33fi
34
35if [ ! -f $discovery_script ]; then
36 # There is no squid-deb-proxy-client package installed. Do nothing.
37 exit 0
38fi
39
40proxy_line=$($discovery_script) #XXX: Could be multiline?
41
42if [ -n "$proxy_line" ]; then
43 doc="# Detected at container start from the host's squid-deb-proxy-client"
44 echo "Acquire::http::proxy \"$proxy_line\"; $doc" > $container_proxy_file
45else
46 if [ -f $proxy_file ]; then
47 rm $proxy_file
48 fi
49fi
50exit 0