ports/121395: [PATCH] dialog wrapper script for OPTIONS to make it work with an invalid $TERM
Hiroki Sato
hrs at FreeBSD.org
Wed Mar 5 16:00:02 UTC 2008
>Number: 121395
>Category: ports
>Synopsis: [PATCH] dialog wrapper script for OPTIONS to make it work with an invalid $TERM
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: change-request
>Submitter-Id: current-users
>Arrival-Date: Wed Mar 05 16:00:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator: Hiroki Sato
>Release: FreeBSD 6.3-PRERELEASE i386
>Organization:
Tokyo University of Science
>Environment:
System: FreeBSD alph.allbsd.org 6.3-PRERELEASE FreeBSD 6.3-PRERELEASE #0: Wed Jan 9 01:39:40 JST 2008 hrs at alph.allbsd.org:/usr/obj/usr/src/sys/ALPH i386
>Description:
The "make config" should support line-based terminal, and the
attached patch implements it.
The motivation is as follows. The "config" target invokes
$DIALOG when $OPTIONS defined in the port, but it fails or it
can make the display screwed up if $TERM envirionment variable
is not set properly or the terminal itself is not screen-based
like a dumb terminal. While a terminal without screen
manipulation capability is uncommon these days, recovering a
broken system via serial console access, for example, can
trigger this problem. In the current implementation, if
dialog(1) cannot open a terminal set by $TERM, it fails and
the user cannot set his configuration.
>How-To-Repeat:
% cd /usr/ports/ports-mgmt/portupgrade && env TERM=FOO make config
>Fix:
Apply the following patch. This can also be found at
http://people.allbsd.org/~hrs/FreeBSD/ports-dialog.diff.
Index: Mk/bsd.port.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.port.mk,v
retrieving revision 1.589
diff -d -u -I\$FreeBSD:.*\$ -I\$NetBSD:.*\$ -I\$OpenBSD:.*\$ -I\$DragonFly:.*\$ -I\$Id:.*\$ -I\$Translation:.*\$ -I\$hrs:.*\$ -r1.589 bsd.port.mk
--- Mk/bsd.port.mk 17 Oct 2007 10:12:24 -0000 1.589
+++ Mk/bsd.port.mk 5 Mar 2008 15:03:50 -0000
@@ -5826,7 +5826,7 @@
done; \
TMPOPTIONSFILE=$$(mktemp -t portoptions); \
trap "${RM} -f $${TMPOPTIONSFILE}; exit 1" 1 2 3 5 10 13 15; \
- ${SH} -c "${DIALOG} --checklist \"Options for ${PKGNAME:C/-([^-]+)$/ \1/}\" 21 70 15 $${DEFOPTIONS} 2> $${TMPOPTIONSFILE}"; \
+ ${SH} -c "${DIALOG} --checklist \"Options for ${PKGNAME:C/-([^-]+)$/ \1/}\" -1 -1 15 $${DEFOPTIONS} 2> $${TMPOPTIONSFILE}"; \
status=$$?; \
if [ $${status} -ne 0 ] ; then \
${RM} -f $${TMPOPTIONSFILE}; \
Index: Mk/bsd.commands.mk
===================================================================
RCS file: /home/ncvs/ports/Mk/bsd.commands.mk,v
retrieving revision 1.1
diff -d -u -I\$FreeBSD:.*\$ -I\$NetBSD:.*\$ -I\$OpenBSD:.*\$ -I\$DragonFly:.*\$ -I\$Id:.*\$ -I\$Translation:.*\$ -I\$hrs:.*\$ -r1.1 bsd.commands.mk
--- Mk/bsd.commands.mk 4 Aug 2007 11:37:23 -0000 1.1
+++ Mk/bsd.commands.mk 2 Sep 2007 13:17:14 -0000
@@ -33,7 +33,7 @@
CPIO?= /usr/bin/cpio
CUT?= /usr/bin/cut
DC?= /usr/bin/dc
-DIALOG?= /usr/bin/dialog
+DIALOG?= ${PORTSDIR}/Tools/scripts/dialog.sh
DIFF?= /usr/bin/diff
DIRNAME?= /usr/bin/dirname
EGREP?= /usr/bin/egrep
Index: Tools/scripts/dialog.sh
===================================================================
RCS file: Tools/scripts/dialog.sh
diff -N Tools/scripts/dialog.sh
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ Tools/scripts/dialog.sh 5 Mar 2008 15:02:37 -0000
@@ -0,0 +1,150 @@
+#!/bin/sh
+#
+# $FreeBSD$
+#
+# Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hiroki Sato <hrs at FreeBSD.org>,
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+# notice, this list of conditions and the following disclaimer in the
+# documentation and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+# SUCH DAMAGE.
+#
+DIALOG_CMD=/usr/bin/dialog
+
+if ${DIALOG_CMD} --clear 2> /dev/null; then
+ exec ${DIALOG_CMD} "$@"
+fi
+
+print_separator()
+{
+ echo "---- $*"
+}
+
+print_sw()
+{
+ _begin=$((${IPAGE} * ${PAGE} + 1))
+ case ${PAGE} in
+ ${NPAGE}) _ritems=$(((${NITEMS} - ${IPAGE} * ${PAGE}) % ${IPAGE})) ;;
+ *) _ritems=${IPAGE} ;;
+ esac
+ _end=$((${_begin} + ${_ritems} - 1))
+
+ for _i in `jot ${_ritems} ${_begin}`; do
+ printf "%3d) [%3s] %s\n" ${_i} "`eval echo \\$PSW_${_i}`" "`eval echo \\$PITEM_${_i}`"
+ done
+
+ print_separator
+
+ case "${_begin}:${_ritems}:${PAGE}" in
+ 1:1:*) echo -n "${_begin},q) " ;;
+ 1:*:${NPAGE}) echo -n "${_begin}-${_end},q) " ;;
+ *:1:*) echo -n "${_begin},p,q) ";
+ VALIDC="p" ;;
+ *:*:${NPAGE}) echo -n "${_begin}-${_end},p,q) ";
+ VALIDC="p" ;;
+ 1:*:*) echo -n "${_begin}-${_end}(max:${NITEMS}),n,q) ";
+ VALIDC="n" ;;
+ *) echo -n "${_begin}-${_end}(max:${NITEMS}),p,n,q) ";
+ VALIDC="pn" ;;
+ esac
+}
+
+print_sw_stderr()
+{
+ for _i in `jot ${NITEMS}`; do
+ case `eval echo \\$PSW_${_i}` in
+ on) echo -n " \"`eval echo \\$PTAG_\${_i}`\"" ;;
+ esac
+ done
+}
+
+flipflop()
+{
+ _tmp=`eval echo \\$PSW_$1`
+
+ case "${_tmp}" in
+ on) echo "off" ;;
+ off) echo "on" ;;
+ *) echo "${_tmp}" ;;
+ esac
+}
+
+check_input()
+{
+ read _in
+
+ case "${_in}:${VALIDC}" in
+ [123456789]:*|[123456789][0123456789]:*|[123456789][0123456789][0123456789]:*)
+ echo "PSW_${_in}=`flipflop ${_in}`"
+ ;;
+ q:*|Q:*)
+ echo "DONE=1"
+ ;;
+ n:*n*|N:*n*)
+ echo "PAGE=$((${PAGE}+1))"
+ ;;
+ p:*p*|P:*p*)
+ echo "PAGE=$((${PAGE}-1))"
+ ;;
+ esac
+}
+
+# main
+
+DONE=0
+PAGE=0
+NITEMS=0 # total number of items
+NPAGE=0 # total number of pages
+IPAGE=10 # items per page
+
+while [ $# != 0 ]; do
+ case $1 in
+ --checklist)
+ shift; TITLE=$1
+ shift; WIDTH=$1
+ shift; HEIGHT=$1
+ shift; LHEIGHT=$1
+ shift;
+
+ NITEMS=$(($# / 3))
+ NPAGE=$(($# / 3 / ${IPAGE}))
+
+ for i in `jot ${NITEMS}`; do
+ eval "PTAG_${i}=\"$1\""
+ eval "PITEM_${i}=\"$2\""
+ eval "PSW_${i}=\"$3\""
+ shift 3
+ done
+
+ break
+ ;;
+ *)
+ shift
+ ;;
+ esac
+done
+
+while [ "${DONE}" != 1 ]; do
+ print_separator "${TITLE}"
+ print_sw "${NITEMS}" "${PAGE}" "${IPAGE}"
+ eval `check_input "${NITEMS}" "${PAGE}" "${IPAGE}"`
+done
+
+print_sw_stderr >&2
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list