Debian Codegraph @

confmodule

raw
1 #!/bin/sh
2 # This is a shell library to interface to the Debian configuration management
3 # system.
4
5 ###############################################################################
6 # Initialization.
7
8 _DEBCONF_IMPL=
9 if [ "${DEBCONF_USE_CDEBCONF:-}" ]; then
10 # Use cdebconf if explicitly requested.
11 _DEBCONF_IMPL=cdebconf
12 elif [ -x /usr/share/debconf/frontend ] && \
13 [ ! -h /usr/share/debconf/frontend ]; then
14 # Fall back to debconf, but only if installed. (cdebconf currently
15 # installs /usr/share/debconf/frontend as a symlink to
16 # /usr/lib/cdebconf/debconf.)
17 _DEBCONF_IMPL=debconf
18 else
19 # Last resort: use cdebconf although not explicitly requested.
20 _DEBCONF_IMPL=cdebconf
21 fi
22
23 # Check to see if a FrontEnd is running.
24 if [ ! "${DEBIAN_HAS_FRONTEND:-}" ]; then
25 # Since there is no FrontEnd, this program execs a FrontEnd.
26 # It will then run a new copy of $0 that can talk to it.
27 if [ "$_DEBCONF_IMPL" = cdebconf ]; then
28 exec /usr/lib/cdebconf/debconf -- $0 "$@"
29 else
30 export PERL_DL_NONLAZY=1
31 exec /usr/share/debconf/frontend $0 "$@"
32 fi
33 fi
34
35 # Only do this once.
36 if [ -z "${DEBCONF_REDIR:-}" ]; then
37 # Redirect standard output to standard error. This prevents common
38 # mistakes by making all the output of the postinst or whatever
39 # script is using this library not be parsed as confmodule commands.
40 #
41 # To actually send something to standard output, send it to fd 3.
42 exec 3>&1
43 if [ "$_DEBCONF_IMPL" = cdebconf ]; then
44 exec 1>&5
45 else
46 exec 1>&2
47 fi
48 DEBCONF_REDIR=1
49 export DEBCONF_REDIR
50 fi
51
52 # In cdebconf, the original stdin/stdout/stderr fds are duplicated onto fds
53 # DEBCONF_OLD_FD_BASE to DEBCONF_OLD_FD_BASE + 2. These values are exported
54 # so that you can get the original fds back. This is kind of a hack:
55 # ideally, we might use something like a socket for the debconf protocol
56 # instead of stdio.
57 DEBCONF_OLD_FD_BASE='4'
58 export DEBCONF_OLD_FD_BASE
59
60 ###############################################################################
61 # Commands.
62
63 _db_cmd () {
64 local _db_internal_IFS="$IFS"
65 IFS=' '
66 printf '%s\n' "$*" >&3
67 # Set to newline to get whole line.
68 IFS='
69 '
70 read -r _db_internal_line
71 IFS="$_db_internal_IFS"
72
73 # Disgusting, but it's the only good way to split the line,
74 # preserving all other whitespace.
75 RET="${_db_internal_line#[! ][ ]}"
76 local _db_status="${_db_internal_line%%[ ]*}"
77 case "$_db_status" in
78 1) # escaped data
79 if [ "$_DEBCONF_IMPL" = cdebconf ]; then
80 _DEBCONF_ESCAPE=/usr/lib/cdebconf/debconf-escape
81 else
82 _DEBCONF_ESCAPE=debconf-escape
83 fi
84 RET="$(printf '%s' "$RET" | $_DEBCONF_ESCAPE -u)"
85 return 0
86 ;;
87 esac
88 return "$_db_status"
89 }
90
91 db_beginblock () { _db_cmd "BEGINBLOCK" "$@"; }
92 db_capb () { _db_cmd "CAPB" "$@"; }
93 db_clear () { _db_cmd "CLEAR" "$@"; }
94 db_data () { _db_cmd "DATA" "$@"; }
95 db_endblock () { _db_cmd "ENDBLOCK" "$@"; }
96 db_fget () { _db_cmd "FGET" "$@"; }
97 db_fset () { _db_cmd "FSET" "$@"; }
98 db_get () { _db_cmd "GET" "$@"; }
99 db_go () { _db_cmd "GO" "$@"; }
100 db_info () { _db_cmd "INFO" "$@"; }
101 db_input () { _db_cmd "INPUT" "$@"; }
102 db_metaget () { _db_cmd "METAGET" "$@"; }
103 db_progress () { _db_cmd "PROGRESS" "$@"; }
104 db_purge () { _db_cmd "PURGE" "$@"; }
105 db_register () { _db_cmd "REGISTER" "$@"; }
106 db_reset () { _db_cmd "RESET" "$@"; }
107 db_set () { _db_cmd "SET" "$@"; }
108 db_settitle () { _db_cmd "SETTITLE" "$@"; }
109 db_subst () { _db_cmd "SUBST" "$@"; }
110 db_title () { _db_cmd "TITLE" "$@"; }
111 db_unregister () { _db_cmd "UNREGISTER" "$@"; }
112 db_version () { _db_cmd "VERSION" "$@"; }
113 db_x_loadtemplatefile () { _db_cmd "X_LOADTEMPLATEFILE" "$@"; }
114
115 # An old alias for input.
116 db_text () {
117 db_input "$@"
118 }
119
120 # Cannot read a return code, since there is none and it would block.
121 db_stop () {
122 echo STOP >&3
123 }