#!/bin/sh
# A script to change the XkbModel variable in xorg.conf
# Part of the Puppy XkbConfigurator
#130117 rodin.s: adding gettext. BK: slight mods.

##--------variables---------->>
INFILE='/etc/X11/xorg.conf'
OUTFILE='/etc/X11/xorg.conf.tmp1'
LIST="/etc/X11/xkb/rules/xorg.lst"
# exported the following from main
#ERRMSG='Xdialog --title "ERROR" --msgbox "An Error has occured! Try again." 0 0'
#SUCCESS='Xdialog --title "Success!" --no-buttons --infobox "Changes applied successfuly!" 0 0 2000'

export TEXTDOMAIN=xkbconfig #xkb
export TEXTDOMAINDIR=/usr/share/locale
export OUTPUT_CHARSET=UTF-8
. gettext.sh

#-----------------------------#

# the full line containing XkbModel:
ORIGINAL=`fgrep '"XkbModel"' $INFILE | grep -v '^#'`
[ "$ORIGINAL" = "" ] && Xdialog --title "$(gettext 'ERROR')" --msgbox "$(gettext 'Your xorg.conf file does not contain any XkbModel options!')" 0 0 && exit
# the current model:
CURRENT=`echo "$ORIGINAL" | cut -d'"' -f4`
MODEL=`fgrep -w -m1 "$CURRENT" $LIST`
# line numbers to pass to the MakeList script:
#STARTNUM=`fgrep -n '! model' $LIST | cut -d: -f1`
#ENDNUM=`fgrep -n '! layout' $LIST | cut -d: -f1`

# Give dialog with list of models:
CHOICE=`Xdialog --left --stdout --title "$(gettext 'Select XkbModel')" --menubox "$(gettext 'Here is a list of all the keyboard models available.
The model you are currently using is:')

${MODEL}

$(gettext 'To replace it, please select one and press OK
To keep the current model, press cancel...')" 30 80 0 pc101 "Generic 101-key PC" pc102 "Generic 102-key (Intl) PC" pc104 "Generic 104-key PC" pc105 "Generic 105-key (Intl) PC" dell101 "Dell 101-key PC" everex "Everex STEPnote" flexpro "Keytronic FlexPro" microsoft "Microsoft Natural" omnikey101 "Northgate OmniKey 101" winbook "Winbook Model XP5" jp106 "Japanese 106-key" pc98 "PC-98xx Series" a4techKB21 "A4Tech KB-21" a4techKBS8 "A4Tech KBS-8" abnt2 "Brazilian ABNT2" airkey "Acer AirKey V" acpi "ACPI Standard" azonaRF2300 "Azona RF2300 wireless Internet Keyboard" scorpius "Advance Scorpius KI" brother "Brother Internet Keyboard" btc5113rf "BTC 5113RF Multimedia" btc5126t "BTC 5126T" btc9000 "BTC 9000" btc9000a "BTC 9000A" btc9001ah "BTC 9001AH" btc5090 "BTC 5090" cherryblue "Cherry Blue Line CyBo@rd" cherryblueb "Cherry CyMotion Master XPress" cherrybluea "Cherry Blue Line CyBo@rd (alternate option)" chicony "Chicony Internet Keyboard" chicony9885 "Chicony KB-9885" compaqeak8 "Compaq Easy Access Keyboard" compaqik7 "Compaq Internet Keyboard (7 keys)" compaqik13 "Compaq Internet Keyboard (13 keys)" compaqik18 "Compaq Internet Keyboard (18 keys)" cymotionlinux "Cherry CyMotion Master Linux" armada "Laptop/notebook Compaq (eg. Armada) Laptop Keyboard" presario "Laptop/notebook Compaq (eg. Presario) Internet Keyboard" ipaq "Compaq iPaq Keyboard" dell "Dell" inspiron "Laptop/notebook Dell Inspiron 8xxx" dexxa "Dexxa Wireless Desktop Keyboard" diamond "Diamond 9801 / 9802 series" dtk2000 "DTK2000" ennyah_dkb1008 "Ennyah DKB-1008" genius "Genius Comfy KB-16M / Genius MM Keyboard KWD-910" geniuscomfy2 "Genius Comfy KB-21e-Scroll" gyration "Gyration" hpi6 "Hewlett-Packard Internet Keyboard" hp2501 "Hewlett-Packard SK-2501 Multimedia Keyboard" hp2505 "Hewlett-Packard SK-2505 Internet Keyboard" hpxe3gc "Hewlett-Packard Omnibook XE3 GC" hpxe3gf "Hewlett-Packard Omnibook XE3 GF" hpxt1000 "Hewlett-Packard Omnibook XT1000" hpzt11xx "Hewlett-Packard Pavilion ZT11xx" hp500fa "Hewlett-Packard Omnibook 500 FA" hp5xx "Hewlett-Packard Omnibook 5xx" hp6000 "Hewlett-Packard Omnibook 6000/6100" honeywell_euroboard "Honeywell Euroboard" rapidaccess "IBM Rapid Access" rapidaccess2 "IBM Rapid Access II" rapidaccess2a "IBM Rapid Access II (alternate option)" thinkpad "IBM ThinkPad 560Z/600/600E/A22E" logiaccess "Logitech Access Keyboard" ltcd "Logitech Cordless Desktop" logicdit "Logitech Cordless Desktop iTouch" logicdp "Logitech Cordless Desktop Pro" logicdpa "Logitech Cordless Desktop Pro (alternate option)" logicdpa2 "Logitech Cordless Desktop Pro (alternate option2)" logicdo "Logitech Cordless Desktop Optical" logicfn "Logitech Cordless Freedom/Desktop Navigator" logicdn "Logitech Cordless Desktop Navigator" logidak "Logitech Deluxe Access Keyboard" logiitc "Logitech iTouch Cordless Keyboard (model Y-RB6)" logiik "Logitech Internet Keyboard" itouch "Logitech iTouch" logiitc "Logitech iTouch Cordless Keyboard (model Y-RB6)" logiik "Logitech Internet Keyboard" logiink "Logitech Internet Navigator Keyboard" itouchin "Logitech iTouch keyboard Internet Navigator" logiultrax "Logitech Ultra-X Keyboard" mx1998 "Memorex MX1998" mx2500 "Memorex MX2500 EZ-Access Keyboard" mx2750 "Memorex MX2750" microsoftinet "Microsoft Internet Keyboard" microsoftpro "Microsoft Natural Keyboard Pro / Microsoft Internet Keyboard Pro" microsoftprousb "Microsoft Natural Keyboard Pro USB / Microsoft Internet Keyboard Pro" microsoftprooem "Microsoft Natural Keyboard Pro OEM" microsoftprose "Microsoft Internet Keyboard Pro, Swedish" microsoftoffice "Microsoft Office Keyboard" microsoftmult "Microsoft Wireless Multimedia Keyboard 1.0A" oretec "Oretec MCK-800 MM/Internet keyboard" propeller "Propeller Voyager (KTEZ-1000)" qtronix "QTronix Scorpius 98N+" samsung4500 "Samsung SDM 4500P" samsung4510 "Samsung SDM 4510P" sk1300 "SK-1300" sk2500 "SK-2500" sk6200 "SK-6200" sk7100 "SK-7100" sp_inet "Super Power Multimedia Keyboard" sven "SVEN Ergonomic 2500" symplon "Symplon PaceBook (tablet PC)" toshiba_s3000 "Toshiba Satellite S3000" trust "Trust Wireless Keyboard Classic" trustda "Trust Direct Access Keyboard" yahoo "Yahoo! Internet Keyboard"  acer_tm_800 "Acer TravelMate 800"`
[ ! $? -eq 0 ] && echo "cancelled" && exit 

# create the modified line to replace original:
MODIFIED=`echo "$ORIGINAL" | sed "s%\"$CURRENT\"%\"$CHOICE\"%"`

# add to file
cat $INFILE | sed "s%$ORIGINAL%$MODIFIED%" >$OUTFILE

if ! fgrep -q '"XkbModel"' $OUTFILE ; then
	eval $ERRMSG
	rm -f $OUTFILE
else
	mv -f $OUTFILE $INFILE
	eval $SUCCESS
fi
exit
