squid-deb-proxy-client revision 4213a747e8f2f953114be798bab0e2bf11da4563
a02a0a8a7eb461619931f4a0e896afa247b52c54Mark Andrews# Make the cloned container aware of squid-deb-proxy settings at start.
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews# Copyright © 2014 Christopher Glass.
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews# This library is free software; you can redistribute it and/or modify
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# it under the terms of the GNU General Public License version 2, as
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# published by the Free Software Foundation.
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington# This program is distributed in the hope that it will be useful,
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews# but WITHOUT ANY WARRANTY; without even the implied warranty of
0756445a735e2df39bf798d8de42ae5dd030aa3bMark Andrews# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews# GNU General Public License for more details.
f8f37672a57524560fbdde52484e6ae3de1c3354Mark Andrews# You should have received a copy of the GNU General Public License along
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews# with this program; if not, write to the Free Software Foundation, Inc.,
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
0756445a735e2df39bf798d8de42ae5dd030aa3bMark Andrews# When starting a container, inject the squid-deb-proxy-client proxy
0756445a735e2df39bf798d8de42ae5dd030aa3bMark Andrews# address in the container's apt configuration.
a02a0a8a7eb461619931f4a0e896afa247b52c54Mark Andrews# This script should be added to templates as a pre-start script, such as:
91216cff91b34c9ff6e846dc23f248219cafe660Andreas Gustafsson#lxc.hook.pre-start=/usr/share/lxc/hooks/squid-deb-proxy-client
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrewsdiscovery_script=/usr/share/squid-deb-proxy-client/apt-avahi-discover
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrewsproxy_file=/etc/apt/apt.conf.d/50squid-deb-proxy
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrewsif [ -f $proxy_file ]; then
9e3a7b0faf417a10f5f689edf288807b2d5eedc5Brian Wellington # The host has a proxy file - let's propagate the config to the guest.
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrews container_proxy_file=$LXC_ROOTFS_PATH$proxy_file
75216e007570b8ea36b3ac9cca096bf70c0ca6f6Mark Andrewsif [ ! -f $discovery_script ]; then
068a66979695c77359e7a9181bb3f831c965b21cMark Andrews # There is no squid-deb-proxy-client package installed. Do nothing.
068a66979695c77359e7a9181bb3f831c965b21cMark Andrewsproxy_line=$($discovery_script) #XXX: Could be multiline?
068a66979695c77359e7a9181bb3f831c965b21cMark Andrewsif [ -n "$proxy_line" ]; then
a0624cf8d5711cca4e3907859fbc8062a7e460faMark Andrews doc="# Detected at container start from the host's squid-deb-proxy-client"
a0624cf8d5711cca4e3907859fbc8062a7e460faMark Andrews echo "Acquire::http::proxy \"$proxy_line\"; $doc" > $container_proxy_file