| 12
 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
 
 | #!/bin/sh
set -eu
STATUS_LIB=/var/lib/di-netboot-assistant
TFTP_ROOT=/var/lib/tftpboot
N_A_DIR=d-i/n-a
if [ -e /etc/di-netboot-assistant/di-netboot-assistant.conf ] ; then
    . /etc/di-netboot-assistant/di-netboot-assistant.conf
fi
migrate_pxelinux_prefix() {
    echo 'Migrating current setup to use PXELinux "::/" (absolute TFTP path).'
    SEDCMD1='s,^\(\s*\(KERNEL\|APPEND\|include\|config\|menu background\|f[0-9]\)\s\+\)\(debian-installer\),\1::/\3,i'
    SEDCMD2='s,^\(\s*APPEND\s\+.*initrd=\)\([^:]\),\1::/\2,i'
    SEDCMD3='s,^\(\s*\(default\|display\)\s\+\)\([^:].*/\),\1::/\3,i'
    if [ -d "$STATUS_LIB" ]; then
	find $STATUS_LIB -name '*.pxelinux.menu.fragment' \
	  | xargs -r -n 1 \
	  sed -i -e "$SEDCMD1"
    fi
    if [ -d "$TFTP_ROOT/debian-installer" ]; then
	find $TFTP_ROOT/debian-installer -type f -a \( -name "default" -o -name "boot.txt" -o -name '*.cfg' \) \
	  | xargs -r -n 1 \
	  sed --in-place=.mig-bak -e "$SEDCMD1" -e "$SEDCMD2" -e "$SEDCMD3"
    fi
}
migrate_dir() {
    echo "Migrating setup to use $TFTP_ROOT/$N_A_DIR/ as di-netboot-assistant's directory."
    if [ -d "$TFTP_ROOT/debian-installer" ] && \
           grep -q di-netboot-assistant $TFTP_ROOT/debian-installer/README.txt > /dev/null 2>&1 ; then
        [ -d  "$TFTP_ROOT/$N_A_DIR" ] && mv $TFTP_ROOT/$N_A_DIR $TFTP_ROOT/${N_A_DIR}_$(date +%Y%m%d%H%M%S)
        mkdir -p $TFTP_ROOT/$N_A_DIR
        mv $TFTP_ROOT/debian-installer/* $TFTP_ROOT/$N_A_DIR && \
            rmdir --ignore-fail-on-non-empty $TFTP_ROOT/debian-installer
        find $TFTP_ROOT/$N_A_DIR -type f -a \( -name "default" -o -name "boot.txt" -o -name '*.cfg' \) \
            | xargs -r -n 1 sed -i -e "s#::/debian-installer/#::/$N_A_DIR/#g"
        sed -i -e "s# /debian-installer/# /$N_A_DIR/#g" $TFTP_ROOT/$N_A_DIR/grub/grub.cfg
    else
        echo "Directory $TFTP_ROOT/debian-installer not found or not managed by di-netboot-assistant."
    fi
    if [ -d "$STATUS_LIB" ]; then
	find $STATUS_LIB -type f | xargs -r -n 1 sed -i -e "s#debian-installer/#$N_A_DIR/#g"
    fi
}
case "$1" in
    configure)
        oldver=$2
        if [ "$oldver" ] && dpkg --compare-versions "$2" lt 0.37; then
            migrate_pxelinux_prefix
        fi
        if [ "$oldver" ] && dpkg --compare-versions "$2" lt 0.51; then
            migrate_dir
        fi
    ;;
    abort-upgrade|abort-remove|abort-deconfigure)
    ;;
    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
#DEBHELPER#
exit 0
 |