D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
lib
/
dpkg
/
info
/
Filename :
cloud-init-base.postinst
back
Copy
#!/bin/sh set -e # shellcheck source=/dev/null . /usr/share/debconf/confmodule set -f # disable pathname expansion db_capb escape # to support carriage return / multi-line values debug() { [ "${_CI_UPGRADE_DEBUG:-0}" = "0" ] && return 0 echo "$@" 1>&2 || : } update_cfg() { # takes filename, header, new object (in yaml), optionally 'remover' # and merges new into existing object in filename, and then updates file # remover a string that means "delete existing entry" python3 -c ' import sys, yaml def update(src, cand): if not (isinstance(src, dict) and isinstance(cand, dict)): return cand for k, v in cand.items(): # if the candidate has _ as value, delete source if v == REMOVER: if k in src: del src[k] continue if k not in src: src[k] = v else: src[k] = update(src[k], v) return src (fname, header, newyaml) = sys.argv[1:4] REMOVER = object if len(sys.argv) == 5: REMOVER = sys.argv[4] newcfg = yaml.safe_load(newyaml) with open(fname, "r") as fp: cfg = yaml.safe_load(fp) if not cfg: cfg = {} cfg = update(cfg, newcfg) with open(fname, "w") as fp: fp.write(header + "\n") fp.write(yaml.dump(cfg))' "$@" } # MAAS 3.6 no longer provides debconf settings, but instead uses curtin to # write /etc/cloud/cloud.cfg,d/95-cloudconfig-* files directly. When 3.6 is out # of support, cloud-init-base can drop support for handling any debconf values. handle_preseed_maas() { local cfg_file="/etc/cloud/cloud.cfg.d/90_dpkg_maas.cfg" local md_url="" creds_all="" c_key="" t_key="" t_sec=""; if process_debconf_setting maas-metadata-url; then md_url="$RET" fi if process_debconf_setting maas-metadata-credentials; then creds_all="$RET" fi # nothing to do [ -n "$md_url" ] || [ -n "$creds_all" ] || return 0 # change a url query string format into : delimited if [ -n "$creds_all" ] && [ "${creds_all#*&}" != "${creds_all}" ]; then # the command here ends up looking like: # python3 -c '...' 'oauth_consumer_key=v1&oauth_token_key=v2...' \ # oauth_consumer_key oauth_token_key oauth_token_secret creds_all=$(python3 -c 'from six.moves.urllib.parse import parse_qs; import sys; keys = parse_qs(sys.argv[1]) for k in sys.argv[2:]: sys.stdout.write("%s:" % keys.get(k,[""])[0])' "$creds_all" \ oauth_consumer_key oauth_token_key oauth_token_secret ) fi # now, if non-empty creds_all is: consumer_key:token_key:token_secret # shellcheck disable=SC2086 if [ -n "$creds_all" ]; then OIFS="$IFS"; IFS=:; set -- $creds_all; IFS="$OIFS" c_key=$1; t_key=$2; t_sec=$3 fi if [ "$md_url" = "_" ] && [ "${c_key}:${t_key}:${t_sec}" = "_:_:_" ]; then # if all these values were '_', the delete value, just delete the file. rm -f "$cfg_file" else local header="# written by cloud-init-base debian package per preseed entries # cloud-init-base/{maas-metadata-url,/maas-metadata-credentials}" local pair="" k="" v="" pload="" orig_umask="" for pair in "metadata_url:$md_url" "consumer_key:${c_key}" \ "token_key:${t_key}" "token_secret:$t_sec"; do k=${pair%%:*} v=${pair#"${k}":} [ -n "$v" ] && pload="${pload} $k: \"$v\"," done # '_' would indicate "delete", otherwise, existing entries are left orig_umask=$(umask) umask 066 : >> "$cfg_file" && chmod 600 "$cfg_file" update_cfg "$cfg_file" "$header" "datasource: { MAAS: { ${pload%,} } }" _ umask "${orig_umask}" fi } handle_preseed_local_cloud_config() { local ccfg="" local cfg_file="/etc/cloud/cloud.cfg.d/90_dpkg_local_cloud_config.cfg" local header="# written by cloud-init-base debian package per preseed entry # cloud-init-base/local-cloud-config" if process_debconf_setting local-cloud-config; then ccfg="$RET" fi if [ "$ccfg" = "_" ]; then rm -f "$cfg_file" elif [ -n "$ccfg" ]; then { echo "$header"; echo "$ccfg"; } > "$cfg_file" fi } # This handles the upgrade path from cloud-init to cloud-init-base. # 24.04 is the last LTS series to be released with cloud-init, so this code # can be removed in 26.10, to ensure the upgrade path from 24.04->26.04 is # not broken. process_debconf_setting() { local old="cloud-init/$1" new="cloud-init-base/$1" old_val="" new_val="" if db_get "$old" && [ -n "${RET}" ]; then old_val="$RET" fi if db_get "$new" && [ -n "${RET}" ]; then new_val="$RET" fi if [ -n "$new_val" ]; then echo "Encountered debconf setting for $new." if [ -n "$old_val" ]; then echo "Ignoring debconf $old setting due to $new." db_set "$old" "" || : fi # now clear the database of the values, as they've been consumed db_unregister "$new" || : RET="$new_val" return 0 fi if [ -n "$old_val" ]; then echo "Encountered debconf setting for $old." # We set empty string as cloud-init-base can't db_unregister cloud-init # debconf settings. Instead, set this value empty which is ignored. db_set "$old" "" || : RET="$old_val" return 0 fi return 1 } if [ "$1" = "configure" ]; then if process_debconf_setting datasources; then datasources="$RET" fi if [ -n "$datasources" ]; then cat > /etc/cloud/cloud.cfg.d/90_dpkg.cfg <<EOF # to update this file, run dpkg-reconfigure cloud-init-base datasource_list: [ $datasources ] EOF fi # if there are maas settings pre-seeded apply them handle_preseed_maas # if there is generic cloud-config preseed, apply them handle_preseed_local_cloud_config fi # Automatically added by dh_python3 if command -v py3compile >/dev/null 2>&1; then py3compile -p cloud-init-base || true fi if command -v pypy3compile >/dev/null 2>&1; then pypy3compile -p cloud-init-base || true fi # End automatically added section # Automatically added by dh_installdeb/13.31ubuntu1 dpkg-maintscript-helper rm_conffile /etc/init/cloud-config.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/init/cloud-final.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/init/cloud-init-blocknet.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/init/cloud-init-container.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/init/cloud-init-local.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/init/cloud-init-nonet.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/init/cloud-init.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/init/cloud-log-shutdown.conf 0.7.9-243-ge74d775-0ubuntu2\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/NetworkManager/dispatcher.d/hook-network-manager 23.3\~4ga31370af-0ubuntu1\~ -- "$@" dpkg-maintscript-helper rm_conffile /etc/cloud/clean.d/README 24.1\~4\~ -- "$@" # End automatically added section # Automatically added by dh_installsystemd/13.31ubuntu1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # The following line should be removed in trixie or trixie+1 deb-systemd-helper unmask 'cloud-config.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'cloud-config.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'cloud-config.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'cloud-config.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installsystemd/13.31ubuntu1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # The following line should be removed in trixie or trixie+1 deb-systemd-helper unmask 'cloud-final.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'cloud-final.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'cloud-final.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'cloud-final.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installsystemd/13.31ubuntu1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # The following line should be removed in trixie or trixie+1 deb-systemd-helper unmask 'cloud-init-hotplugd.socket' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'cloud-init-hotplugd.socket'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'cloud-init-hotplugd.socket' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'cloud-init-hotplugd.socket' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installsystemd/13.31ubuntu1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # The following line should be removed in trixie or trixie+1 deb-systemd-helper unmask 'cloud-init-local.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'cloud-init-local.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'cloud-init-local.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'cloud-init-local.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installsystemd/13.31ubuntu1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # The following line should be removed in trixie or trixie+1 deb-systemd-helper unmask 'cloud-init-main.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'cloud-init-main.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'cloud-init-main.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'cloud-init-main.service' >/dev/null || true fi fi # End automatically added section # Automatically added by dh_installsystemd/13.31ubuntu1 if [ "$1" = "configure" ] || [ "$1" = "abort-upgrade" ] || [ "$1" = "abort-deconfigure" ] || [ "$1" = "abort-remove" ] ; then # The following line should be removed in trixie or trixie+1 deb-systemd-helper unmask 'cloud-init-network.service' >/dev/null || true # was-enabled defaults to true, so new installations run enable. if deb-systemd-helper --quiet was-enabled 'cloud-init-network.service'; then # Enables the unit on first installation, creates new # symlinks on upgrades if the unit file has changed. deb-systemd-helper enable 'cloud-init-network.service' >/dev/null || true else # Update the statefile to add new symlinks (if any), which need to be # cleaned up on purge. Also remove old symlinks. deb-systemd-helper update-state 'cloud-init-network.service' >/dev/null || true fi fi # End automatically added section