AlaK4X
Linux lhjmq-records 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64



Your IP : 18.227.46.87


Current Path : /var/lib/dpkg/info/
Upload File :
Current File : /var/lib/dpkg/info/ubuntu-advantage-tools.preinst

#!/bin/sh

set -e

remove_old_config_fields() {
    PREVIOUS_PKG_VER="$1"
    if dpkg --compare-versions "$PREVIOUS_PKG_VER" le "27.8"; then
        if grep -q "^license_check_log_file:" /etc/ubuntu-advantage/uaclient.conf; then
            sed -i '/^license_check_log_file:.*$/d' /etc/ubuntu-advantage/uaclient.conf || true
        fi
    fi
}

restore_previous_conffile() {
    previous_pkg_version=$1
    # Back up existing conffile in case of an error unwind
    cp -a /etc/ubuntu-advantage/uaclient.conf /etc/ubuntu-advantage/uaclient.conf.preinst-remove

    if dpkg --compare-versions "$previous_pkg_version" ge 27.13.1~; then
      # Restore the default conffile that shipped with 27.13.X
      cat > /etc/ubuntu-advantage/uaclient.conf <<EOT
# Ubuntu Pro Client config file.
# If you modify this file, run "pro refresh config" to ensure changes are
# picked up by Ubuntu Pro Client.

contract_url: https://contracts.canonical.com
data_dir: /var/lib/ubuntu-advantage
log_file: /var/log/ubuntu-advantage.log
log_level: debug
security_url: https://ubuntu.com/security
timer_log_file: /var/log/ubuntu-advantage-timer.log
daemon_log_file: /var/log/ubuntu-advantage-daemon.log
ua_config:
  apt_http_proxy: null
  apt_https_proxy: null
  http_proxy: null
  https_proxy: null
  update_messaging_timer: 21600
  metering_timer: 14400
EOT
  else
      # Restore the default conffile that shipped with 27.11.3 through 27.12
      cat > /etc/ubuntu-advantage/uaclient.conf <<EOT
# Ubuntu Pro Client config file.
# If you modify this file, run "pro refresh config" to ensure changes are
# picked up by Ubuntu Pro Client.

contract_url: https://contracts.canonical.com
data_dir: /var/lib/ubuntu-advantage
log_file: /var/log/ubuntu-advantage.log
log_level: debug
security_url: https://ubuntu.com/security
timer_log_file: /var/log/ubuntu-advantage-timer.log
daemon_log_file: /var/log/ubuntu-advantage-daemon.log
ua_config:
  apt_http_proxy: null
  apt_https_proxy: null
  http_proxy: null
  https_proxy: null
  update_messaging_timer: 21600
  update_status_timer: 43200
  metering_timer: 14400
EOT
  fi
}

case "$1" in
    install|upgrade)
        if [ -n "$2" ]; then
            PREVIOUS_PKG_VER=$2
            remove_old_config_fields "$PREVIOUS_PKG_VER"
        fi
    
        # LP: #2003977
        # If the user used "pro config set apt_news=false|true" previously,
        # then we don't want a conffile prompt if they haven't otherwise
        # changed the conffile. In these two cases, restore the conffile back
        # to how it shipped, and then fix up in postinst if required. The
        # version gate is open ended, and should be closed when the apt_news
        # configuration is moved away from a conffile.
        if dpkg --compare-versions "$2" ge 27.11.3~; then
            if [ -f /etc/ubuntu-advantage/uaclient.conf ]; then
                conffile_hash=$(md5sum /etc/ubuntu-advantage/uaclient.conf|awk '{print $1}')
                case "$conffile_hash" in
                    038902993a843cac6cbe3efa4d1fcb92|f8049c664dff27e212a77aef514e4b64)
                        # User had run "pro config set apt_news=false" with no other
                        # conffile changes
                        mkdir -p /var/lib/ubuntu-advantage
                        touch /var/lib/ubuntu-advantage/preinst-detected-apt-news-disabled
                        restore_previous_conffile $2
                        ;;
                    3b01d7406cbb4ba628a9ffa57485d324|d9971401a6409032b1c9069236040dc4)
                        # User had run "pro config set apt_news=true" with no other
                        # conffile changes
                        restore_previous_conffile $2
                        ;;
                esac
            fi
        fi
        ;;
esac

# Automatically added by dh_installdeb/13.6ubuntu1
dpkg-maintscript-helper rm_conffile /etc/update-motd.d/99-esm 19.1~ ubuntu-advantage-tools -- "$@"
# End automatically added section
# Automatically added by dh_installdeb/13.6ubuntu1
dpkg-maintscript-helper rm_conffile /etc/update-motd.d/80-esm 19.1~ ubuntu-advantage-tools -- "$@"
# End automatically added section
# Automatically added by dh_installdeb/13.6ubuntu1
dpkg-maintscript-helper rm_conffile /etc/update-motd.d/80-livepatch 19.1~ ubuntu-advantage-tools -- "$@"
# End automatically added section
# Automatically added by dh_installdeb/13.6ubuntu1
dpkg-maintscript-helper rm_conffile /etc/cron.daily/ubuntu-advantage-tools 19.1~ ubuntu-advantage-tools -- "$@"
# End automatically added section
# Automatically added by dh_installdeb/13.6ubuntu1
dpkg-maintscript-helper rm_conffile /etc/init/ua-auto-attach.conf 20.2~ ubuntu-advantage-tools -- "$@"
# End automatically added section

exit 0