github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/acceptancetests/repository/charms/client-forwardproxy/hooks/config-changed (about) 1 #!/bin/bash 2 set -eux 3 4 PROXY_IP="" 5 PROXY_PORT="" 6 7 8 status-set maintenance "Checking config" || true 9 PROPOSED_PACKAGES="$(config-get proposed-packages)" 10 if [[ "$PROPOSED_PACKAGES" != "" ]]; then 11 status-set maintenance "Disabling firewall to install packages" || true 12 UFW_STATUS=$(ufw status | cut -d ' ' -f2) 13 ufw disable 14 status-set maintenance "Installing packages from the proposed archive" || true 15 RELEASE=$(lsb_release -sc) 16 apt-get update 17 apt-get install -y -t $RELEASE-proposed $PROPOSED_PACKAGES 18 status-set maintenance "Packages installed" || true 19 if [[ $UFW_STATUS == "active" ]]; then 20 status-set maintenance "Enabling the firewall" || true 21 ufw --force enable 22 fi 23 fi 24 25 status-set maintenance "Checking proxy." || true 26 set +e 27 # This is a hack. We don't want to iterate, but we need to 28 # because we need the state of relations and config to know 29 # if this charm is active or something else. 30 for app in $(relation-ids forwardproxy); do 31 for unit in $(relation-list -r $app); do 32 PROXY_IP="$(relation-get -r $app ip $unit)" 33 PROXY_PORT="$(relation-get -r $app port $unit)" 34 done 35 done 36 set -e 37 38 if [[ "$PROXY_IP" == "" || "$PROXY_PORT" == "" ]]; then 39 status-set maintenance "Removing firewall rules" || true 40 echo "PATH="$PATH"" > /etc/environment 41 status-set waiting "Waiting for forwardproxy" || true 42 exit 0 43 fi 44 45 # LXD was given the 10.0.8.* by scripts/setup-lxd.sh 46 LXD_ADDRESSES="$(echo 10.0.8.{1..255} | sed 's/ /,/g')" 47 EXTRA_NO_PROXY="$(config-get extra-no-proxy | sed -e 's/ /,/g')" 48 NO_PROXY="localhost,127.0.0.1,$EXTRA_NO_PROXY,$LXD_ADDRESSES" 49 status-set maintenance "Updating proxy rules." || true 50 cat > /etc/environment << EOF 51 PATH="$PATH" 52 http_proxy=http://$PROXY_IP:$PROXY_PORT/ 53 https_proxy=http://$PROXY_IP:$PROXY_PORT/ 54 ftp_proxy=http://$PROXY_IP:$PROXY_PORT/ 55 no_proxy=$NO_PROXY 56 HTTP_PROXY=http://$PROXY_IP:$PROXY_PORT/ 57 HTTPS_PROXY=http://$PROXY_IP:$PROXY_PORT/ 58 FTP_PROXY=http://$PROXY_IP:$PROXY_PORT/ 59 NO_PROXY=$NO_PROXY 60 EOF 61 status-set active "Updated proxy rules" || true