apt.postinst 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #! /bin/sh
  2. set -e
  3. # set the proxy based on the admin users gconf settings
  4. #
  5. set_apt_proxy_from_gconf() {
  6. # try SUDO_USER first
  7. if [ -n "$SUDO_USER" ]; then
  8. admin_user="$SUDO_USER"
  9. else
  10. admin_user=$(getent group admin|cut -d: -f4|cut -d, -f1)
  11. fi
  12. # test if the user actually exists, getent returns "+" for e.g.
  13. # LDAP
  14. if ! id -u "$admin_user" > /dev/null 2>&1; then
  15. return
  16. fi
  17. # get the settings from gconf
  18. if [ -n "$admin_user" ] && [ -x /usr/bin/sudo ] && [ -z "$http_proxy" ] && [ -x /usr/bin/gconftool ]; then
  19. use=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/use_http_proxy 2>/dev/null)
  20. host=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/host 2>/dev/null)
  21. port=$(sudo -u "$admin_user" gconftool --get /system/http_proxy/port 2>/dev/null)
  22. if [ "$use" = "true" ] && [ -n "$host" ] && [ -n "$port" ]; then
  23. APT_CONF_PROXY=""
  24. eval $(apt-config shell APT_CONF_PROXY Acquire::http::proxy)
  25. if [ -z "$APT_CONF_PROXY" ]; then
  26. echo "Acquire::http::proxy \"http://$host:$port/\";" >> /etc/apt/apt.conf
  27. fi
  28. fi
  29. fi
  30. }
  31. # summary of how this script can be called:
  32. # * <postinst> `configure' <most-recently-configured-version>
  33. # * <old-postinst> `abort-upgrade' <new version>
  34. # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
  35. # <new-version>
  36. # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
  37. # <failed-install-package> <version> `removing'
  38. # <conflicting-package> <version>
  39. # for details, see http://www.debian.org/doc/debian-policy/ or
  40. # the debian-policy package
  41. case "$1" in
  42. configure)
  43. if ! test -f /etc/apt/trusted.gpg; then
  44. cp /usr/share/apt/ubuntu-archive.gpg /etc/apt/trusted.gpg
  45. fi
  46. # mvo: get gconf defaults once and write to a file, reason is
  47. # that sudo no longer honors http_proxy
  48. # this can be removed after lucid is released
  49. if dpkg --compare-versions "$2" lt-nl "0.7.25.3ubuntu2"; then
  50. set_apt_proxy_from_gconf || true
  51. fi
  52. ;;
  53. abort-upgrade|abort-remove|abort-deconfigure)
  54. ;;
  55. *)
  56. echo "postinst called with unknown argument \`$1'" >&2
  57. exit 1
  58. ;;
  59. esac
  60. # dh_installdeb will replace this with shell code automatically
  61. # generated by other debhelper scripts.
  62. #DEBHELPER#
  63. exit 0