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
|
#!/bin/sh
# This script compiles and installs a small wrapper that will allow to
# automatically run Xdialog instead of (c)dialog when a script using
# (c)dialog is ran under the X server. It will also optionally replace
# gdialog.
# Change this to suit your compiler...
CC="gcc"
CCOPT="-Wall -o Xdialog.wrapper Xdialog.wrapper.c"
BOX_TITLE="Xdialog wrapper"
BACKTITLE="Xdialog wrapper installation"
function errors() {
if (( $? != 0 )) ; then
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" --no-close \
--icon ./warning.xpm \
--yesno "An error occured, do you want\nto see details about it ?" 0 0
if (( $? == 0 )) ; then
Xdialog --title "$BOX_TITLE" --backtitle "Error message:" --no-cancel \
--textbox /tmp/wrapper.$$ 20 64
fi
rm -f /tmp/wrapper.$$
exit 1
fi
}
if [ -x /usr/bin/Xdialog.wrapper ] ; then
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" \
--msgbox "Xdialog wrapper already installed." 0 0
exit 0
fi
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" \
--yesno "This script installs a small wrapper\n\
that will automatically invoke \"Xdialog\"\n\
instead of \"dialog\" or \"cdialog\", when\n\
the user is working under X.\n\n\
Do you want to continue (note that you
must be root to run this script) ?" 0 0
if (( $? != 0 )) ; then
exit 0
fi
DIALOG=""
CDIALOG=""
PATH_LIST=`echo $PATH | sed -e "y/:/ /"`
for i in $PATH_LIST; do
if [ "$DIALOG" == "" ] && [ -d $i ] ; then
DIALOG=`find $i -name dialog -print`
fi
if [ "$CDIALOG" == "" ] && [ -d $i ] ; then
CDIALOG=`find $i -name cdialog -print`
fi
done
if ! [ -x Xdialog.wrapper ] ; then
if ! [ -f Xdialog.wrapper.c ] ; then
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" --left \
--msgbox "Error:\nCan't find \"Xdialog.wrapper.c\"" 0 0
rm -f /tmp/wrapper.$$
exit 1
fi
echo "" >/tmp/wrapper.$$
( echo "Compiling the wrapper..." ; $CC $CCOPT 2>&1 ; echo "Done." ) | \
Xdialog --title "$BOX_TITLE" --backtitle "Compiling Xdialog.wrapper..." \
--no-close --no-cancel --tailbox "-" 20 64
fi
if ! [ -x Xdialog.wrapper ] ; then
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" --left \
--msgbox "Error:\nCan't find \"Xdialog.wrapper\"" 0 0
rm -f /tmp/wrapper.$$
exit 1
fi
mv Xdialog.wrapper /usr/bin/ 2>/tmp/wrapper.$$
errors
chmod 755 /usr/bin/Xdialog.wrapper 2>/tmp/wrapper.$$
errors
if [ "$DIALOG" != "" ] && [ -f $DIALOG ] ; then
mv $DIALOG $DIALOG.wrapped 2>/tmp/wrapper.$$
errors
ln -s /usr/bin/Xdialog.wrapper /usr/bin/dialog 2>/tmp/wrapper.$$
errors
fi
if [ "$CDIALOG" != "" ] && [ -f $CDIALOG ] ; then
mv $CDIALOG $CDIALOG.wrapped 2>/tmp/wrapper.$$
errors
ln -s /usr/bin/Xdialog.wrapper /usr/bin/cdialog 2>/tmp/wrapper.$$
errors
fi
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" \
--msgbox "Wrapper installed succesfully." 0 0
GDIALOG=""
XDIALOG=""
for i in $PATH_LIST; do
if [ "$GDIALOG" == "" ] && [ -d $i ] ; then
GDIALOG=`find $i -name gdialog -print`
fi
if [ "$XDIALOG" == "" ] && [ -d $i ] ; then
XDIALOG=`find $i -name Xdialog -print`
fi
done
if [ "$XDIALOG" != "" ] && [ "$GDIALOG" != "" ] && ! [ -x $GDIALOG.orig ] ; then
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" \
--yesno "I also found \"gdialog\" on your system...\nDo you want \"Xdialog\" to replace it ?" 0 0
if (( $? == 0 )) ; then
mv $GDIALOG $GDIALOG.orig 2>/tmp/wrapper.$$
errors
ln -s $XDIALOG $GDIALOG 2>/tmp/wrapper.$$
errors
Xdialog --title "$BOX_TITLE" --backtitle "$BACKTITLE" \
--msgbox "\"gdialog\" replaced succesfully." 0 0
fi
fi
rm -f /tmp/wrapper.$$
|