This file is indexed.

postinst is in bilibop-rules 0.4.20.

This file is a maintainer script. It is executed when installing (*inst) or removing (*rm) the package.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/bin/sh

set -e

# Source debconf library:
. /usr/share/debconf/confmodule

# Source bilibop library:
. /lib/bilibop/common.sh
get_udev_root

PATH="${PATH}:/usr/share/bilibop"
ETC_RULES_DIR="/etc/udev/rules.d"

belongs_to_floppy_group() {
    stat -c %G ${1}* | grep -q '^floppy$'
}

global_filter_is_supported() {
    local version="$(dpkg -l lvm2 | awk '/^ii/ {print $3}')"
    dpkg --compare-versions ${version} ge 2.02.98
}

case "${1}" in
    configure|reconfigure)

        # GRUB device.map management
        # ==========================

        # Backup device.map; it will be restored when (if) the package will be
        # purged.
        DEVICE_MAP="/boot/grub/device.map"
        if [ -f "${DEVICE_MAP}" -a ! -f "${DEVICE_MAP}.bak" ]; then
            cp -a ${DEVICE_MAP} ${DEVICE_MAP}.bak
        fi

        # Debconf specific configuration
        # ==============================

        # At first, backup some values if this is not already done.
        HELPER="physical_volumes_filter"
        LVMCONF="/etc/lvm/lvm.conf"
        lvm_variables="obtain_device_list_from_udev filter"
        global_filter_is_supported && lvm_variables="${lvm_variables} global_filter"
        if [ -f "${LVMCONF}" ]; then
            for lvmvar in ${lvm_variables}; do
                db_fget bilibop-rules/${HELPER}/${lvmvar} seen
                [ "${RET}" = "true" ] && continue
                lvmval="$(grep "^[[:blank:]]*${lvmvar}[[:blank:]]*=" ${LVMCONF} | sed 's,^[^=]\+=\s*,,')"
                if [ -n "${lvmval}" ]; then
                    db_set bilibop-rules/${HELPER}/${lvmvar} ${lvmval}
                    db_fset bilibop-rules/${HELPER}/${lvmvar} seen true
                    # Now the initial values of 'obtain_device_list_from_udev',
                    # 'filter' and 'global_filter' are stored in the debconf
                    # db. They will be restored if the package is purged.
                fi
            done
        fi

        # Modify system settings only if the package is not intended to be
        # installed on a Live System.
        db_get bilibop-rules/on-live-system
        if [ "${RET}" = "false" ]; then

            # make_unpersistent_rules
            # -----------------------

            # Replace persistent rules files by symlinks in a per-file basis
            # (this can be useful if the external system travels with a PCMCIA
            # ethernet card or an external CD/DVD burner)
            HELPER="make_unpersistent_rules"
            db_get bilibop-rules/${HELPER}
            case "${RET}" in
                keep)
                    ;;
                cd|net)
                    ${HELPER} --only ${RET}
                    ;;
                none)
                    ${HELPER} --restore
                    ;;
                all)
                    ${HELPER}
                    ;;
            esac

            # grub_device_map_manager
            # -----------------------

            # Set GRUB device map only if GRUB is installed (both as package
            # and as bootloader):
            # This is for MBR/ms-dos partition tables:
            #GRUB="$(dd if=${BILIBOP_DISK} bs=1 skip=384 count=4 2>/dev/null)"
            HELPER="grub_device_map_manager"
            if [ -d "/boot/grub" -a -x "/usr/sbin/grub-mkdevicemap" ]; then
                db_get bilibop-rules/${HELPER}
                if [ "${RET}" != "keep" ]; then
                    CONFIGFILE="/etc/bilibop/bilibop.conf"
                    KEY="BILIBOP_RULES_FAKE_DEVICE_MAP"
                    case "${RET}" in
                        static)
                            opt="--update"
                            if [ -h "${DEVICE_MAP}" ]; then
                                opt="--remove ${opt}"
                            fi
                            ;;
                        fake)
                            opt="--fake"
                            if [ -h "${DEVICE_MAP}" ]; then
                                opt="--remove ${opt}"
                            fi
                            ;;
                        dynamic)
                            opt="--link"
                            if [ -f "${CONFIGFILE}" ]; then
                                # Override the variable ?
                                #echo "${KEY}=\"true\"" >>${CONFIGFILE}
                                # Change the value ?
                                #sed -i "s:^\(\s*${KEY}\)=\([\"\']\?\)false\2:\1=\2true\2:" ${CONFIGFILE}
                                # Comment the line ?
                                #sed -i "s:^\(\s*${KEY}\)=\([\"\']\?\)false\2:#&:" ${CONFIGFILE}
                                # Delete the line ?
                                sed -Ei "/^(\s*${KEY})=([\"\']?)false\2/d" ${CONFIGFILE}
                            fi
                            ;;
                        ondemand)
                            opt="--link --update"
                            if grep -qs "^[[:blank:]]*${KEY}=" ${CONFIGFILE}; then
                                grep -Eq "^[[:blank:]]*${KEY}=([\"\']?)false\1" ${CONFIGFILE} ||
                                sed -Ei "s:^(\s*${KEY})=.*:\1=\"false\":" ${CONFIGFILE}
                            elif grep -Eqs "^[[:blank:]]*(#[[:blank:]]*)+${KEY}=([\"\']?)false\2" ${CONFIGFILE}; then
                                sed -Ei "s:^(\s*)(#\s*)+(${KEY})=([\"\']?)false\4:\1\3=\"false\":" ${CONFIGFILE}
                            else
                                echo "${KEY}=\"false\"" >>${CONFIGFILE}
                            fi
                            ;;
                    esac
                    ${HELPER} ${opt}
                fi
            fi
        fi

        # Now we have to take care of the order of the processes:
        # 1. Ask the user if she wants to use a custom rules file
        # 2. Trigger uevents to apply bilibop (custom or generic)
        #    udev rules
        # 3. Then ask the user if she wants to modify lvm.conf
        #    (needs BILIBOP udev-tagged devices)
        # 4. Update initramfs by including the (modified or not)
        #    lvm.conf

        if [ -h /proc/mounts -a -d /sys/block -a -c ${udev_root}/null ] &&
            invoke-rc.d udev status >${udev_root}/null 2>&1 &&
            BILIBOP_DISK="$(physical_hard_disk /)" &&
            query_sysfs_attrs ${BILIBOP_DISK} | grep -Eq '^[[:blank:]]*SUBSYSTEMS=="(usb|firewire|memstick|mmc)"'; then
            db_get bilibop-rules/on-live-system
            if [ "${RET}" = "false" ]; then

                # bilibop_rules_generator
                # -----------------------

                # Maybe build custom rules
                CUSTOM_RULES="false"
                HELPER="bilibop_rules_generator"
                if [ -f ${ETC_RULES_DIR}/66-bilibop.rules ]; then
                    db_get bilibop-rules/${HELPER}/overwrite
                    if [ "${RET}" = "rebuild" ]; then
                        CUSTOM_RULES="true"
                    elif [ "${RET}" = "remove" ]; then
                        rm ${ETC_RULES_DIR}/66-bilibop.rules
                        # Now that the custom rules file has been removed,
                        # say to debconf the user does not want to build it.
                        db_reset bilibop-rules/${HELPER}/customize
                        db_fset bilibop-rules/${HELPER}/customize seen true
                        # But also say to keep it if it is rebuilt manually.
                        # We don't set the seen flag to true: if the custom
                        # rules file has been built manually, the question
                        # should be asked on next package upgrade.
                        db_reset bilibop-rules/${HELPER}/overwrite
                    fi
                else
                    db_get bilibop-rules/${HELPER}/customize
                    if [ "${RET}" = "true" ]; then
                        CUSTOM_RULES="true"
                    fi
                fi

                # Build the custom rules:
                if [ "${CUSTOM_RULES}" = "true" ]; then
                    db_get bilibop-rules/${HELPER}/options
                    if ${HELPER} ${RET} -t ${BILIBOP_DISK} 2>${udev_root}/null; then
                        # Custom rules file has been successfully created;
                        # so say debconf to keep it the next time the package
                        # is configured:
                        db_reset bilibop-rules/${HELPER}/overwrite
                        db_fset bilibop-rules/${HELPER}/overwrite seen true
                    else
                        CUSTOM_RULES="false"
                    fi
                fi
            fi

            # Udev specific configuration
            # ===========================

            # Trigger uevents for block devices owned by 'disk' group
            # or being on the same disk than the root filesystem.
            BILIBOP_LIST="$(lsbilibop -l)"
            opt="--sysname-match=${BILIBOP_DISK##*/}*"
            for dev in ${BILIBOP_LIST}; do
                case "${dev}" in
                    ${BILIBOP_DISK}*)
                        ;;
                    *)
                        opt="${opt} --sysname-match=${dev##*/}"
                        ;;
                esac
            done
            udevadm trigger ${opt}
            udevadm settle

            # But it can happen that this doesn't work and new rules must be
            # explicitly loaded before triggering uevents:
            if belongs_to_floppy_group ${BILIBOP_DISK}; then
                udevadm control --reload-rules
                udevadm trigger ${opt}
                udevadm settle

                # Now do something if the drive and its partitions still belong
                # to the floppy group.
                if belongs_to_floppy_group ${BILIBOP_DISK}; then
                    for dev in $(find ${BILIBOP_DISK}* -group floppy); do
                        flop="${flop:+${flop} }${dev}"
                    done
                    if [ -f "${ETC_RULES_DIR}/66-bilibop.rules" -a "${CUSTOM_RULES}" != "true" ]; then
                        # Custom rules file exists, but it has not been created
                        # just before:
                        db_subst bilibop-rules/belongs_to_floppy_group/custom_rules_error DEVICE "${flop}"
                        db_input critical bilibop-rules/belongs_to_floppy_group/custom_rules_error || true
                        db_go || true
                    else
                        # Custom rules file does not exist, or it has just been
                        # created:
                        db_subst bilibop-rules/belongs_to_floppy_group/internal_error DEVICE "${flop}"
                        db_input critical bilibop-rules/belongs_to_floppy_group/internal_error || true
                        db_go || true
                    fi
                fi
            fi

            # Debconf stuff... again (because we need updated udev tags to do it)
            # ======================
            db_get bilibop-rules/on-live-system
            if [ "${RET}" = "false" ]; then

                # physical_volumes_filter
                # -----------------------

                HELPER="physical_volumes_filter"
                # The file copied into the initrd is always /etc/lvm/lvm.conf
                # (the hook does not care about LVM_SYSTEM_DIR); so we reset
                # LVM_SYSTEM_DIR to be sure the helper script will apply to
                # this file.
                export LVM_SYSTEM_DIR="/etc/lvm"
                LVMCONF_RECONFIGURE="0"

                if lsblk ${BILIBOP_DISK} --noheadings -o type,fstype | grep -Eq '\<(lvm|LVM2_member)\>'; then

                    OLDPVFILTER="$(${HELPER})" || true
                    db_get bilibop-rules/${HELPER}/system-only

                    if [ "${RET}" = "true" ]; then
                        unlinked=
                        untagged=
                        PV_LIST="$(lsblk --noheadings -o fstype,kname ${BILIBOP_DISK} | awk '/^LVM2_member/ {print $2}')"
                        for dev in ${PV_LIST}; do
                            linked="false"
                            for symlink in $(udevadm info --query symlink --name ${dev}); do
                                case "${symlink}" in
                                    disk/by-id/*|mapper/*)
                                        linked="true"
                                        break
                                        ;;
                                esac
                            done
                            [ "${linked}" = "true" ] ||
                                unlinked="${unlinked:+${unlinked} }${udev_root}/${dev}"
                            [ "$(lsbilibop ${udev_root}/${dev})" = "${udev_root}/${dev}" ] ||
                                untagged="${untagged:+${untagged} }${udev_root}/${dev}"
                        done
                    fi

                    if [ "${RET}" = "true" -a -z "${untagged}" -a -z "${unlinked}" ]; then
                        [ -f "${LVMCONF}" ] || ${HELPER} --init
                        ${HELPER} --overwrite --udev --accept bilibop --reject all

                    else
                        if [ "${RET}" = "true" ]; then
                            db_reset bilibop-rules/${HELPER}/system-only

                            if global_filter_is_supported; then
                                warning="with_global_filter/warning"
                                db_get bilibop-rules/${HELPER}/global_filter
                                db_subst bilibop-rules/${HELPER}/${warning} GLOBAL_FILTER "${RET}"
                            else
                                warning="without_global_filter/warning"
                            fi
                            db_subst bilibop-rules/${HELPER}/${warning} UNTAGGED "${untagged}"
                            db_subst bilibop-rules/${HELPER}/${warning} UNLINKED "${unlinked}"
                            db_get bilibop-rules/${HELPER}/obtain_device_list_from_udev
                            db_subst bilibop-rules/${HELPER}/${warning} FROMUDEV "${RET}"
                            db_get bilibop-rules/${HELPER}/filter
                            db_subst bilibop-rules/${HELPER}/${warning} FILTER "${RET}"
                            db_input critical bilibop-rules/${HELPER}/${warning} || true
                            db_go || true
                        fi
                        for lvmvar in ${lvm_variables}; do
                            db_get bilibop-rules/${HELPER}/${lvmvar}
                            if [ -n "${RET}" ] && grep -qs "^[[:blank:]]*${lvmvar}[[:blank:]]*=" ${LVMCONF}; then
                                grep -Eq "^[[:blank:]]*${lvmvar}[[:blank:]]*=[[:blank:]]*${RET}[[:blank:]]*(#|$)" ${LVMCONF} ||
                                sed -Ei "s@^(\s*${lvmvar}\s*=).*@\1 ${RET}@" ${LVMCONF}
                            fi
                        done
                    fi

                    NEWPVFILTER="$(${HELPER})" || true
                    if [ "${NEWPVFILTER}" != "${OLDPVFILTER}" ]; then
                        LVMCONF_RECONFIGURE="1"
                        # Regenerate cache file:
                        vgscan --ignorelockingfailure
                    fi
                fi
            fi
        fi
        db_stop

        # Add a new script in the initramfs. And modify it also if LVM has
        # been reconfigured (see above):
        if [ -x /usr/sbin/update-initramfs ]; then
            if [ "${DEBCONF_RECONFIGURE}" = "1" ]; then
                if [ "${LVMCONF_RECONFIGURE}" = "1" ]; then
                    update-initramfs -u
                fi
            else
                update-initramfs -u
            fi
        fi
        ;;
esac


:
# vim: et ts=4 sts=4 sw=4