home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / bin / dexconf < prev    next >
Encoding:
Text File  |  2006-07-05  |  14.8 KB  |  535 lines

  1. #!/bin/sh
  2.  
  3. # dexconf: Debian X server configuration file writer
  4. #
  5. # This tool is a backend which uses debconf database values.  It writes an
  6. # XFree86 X server configuration file based on the information in the database.
  7. #
  8. # Author: Branden Robinson
  9.  
  10. # Copyright 2000--2004 Progeny Linux Systems, Inc.
  11. #
  12. # This is free software; you may redistribute it and/or modify
  13. # it under the terms of the GNU General Public License as
  14. # published by the Free Software Foundation; either version 2,
  15. # or (at your option) any later version.
  16. #
  17. # This is distributed in the hope that it will be useful, but
  18. # WITHOUT ANY WARRANTY; without even the implied warranty of
  19. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. # GNU General Public License for more details.
  21. #
  22. # You should have received a copy of the GNU General Public License with
  23. # the Debian operating system, in /usr/share/common-licenses/GPL;  if
  24. # not, write to the Free Software Foundation, Inc., 59 Temple Place,
  25. # Suite 330, Boston, MA 02111-1307 USA
  26.  
  27. set -e
  28.  
  29. # source debconf library
  30. . /usr/share/debconf/confmodule
  31.  
  32. # display a usage message
  33. usage () {
  34.   cat <<EOF
  35. Usage: $PROGNAME [OPTION ...]
  36.   write an Xorg X server configuration file based on debconf database values
  37. Options:
  38.   -h, --help                                 display this usage message and exit
  39.   -o FILE, --output=FILE                        write configuration file to FILE
  40. This help message is intended only as a quick reference.  For a description of
  41. the usage of $PROGNAME, see the $PROGNAME(1) manual page.
  42. EOF
  43. }
  44.  
  45. # the error-out function
  46. bomb () {
  47.   echo "$PROGNAME: error: $*" | fold -s -w "${COLUMNS:-80}" >&2
  48.   exit 1
  49. }
  50.  
  51. # wrapper around db_get to ensure that the info we try to retrieve exists; it
  52. # is (almost) always a fatal error for the values to be null
  53. fetch () {
  54.   db_get "$1" || true
  55.   if [ -z "$RET" ]; then
  56.     ERRMSG="cannot generate configuration file; $1 not set.  Aborting."
  57.     ERRMSG="$ERRMSG  Reconfigure the X server with \"dpkg-reconfigure"
  58.     if [ -n "$XSERVERPKG" ]; then
  59.       ERRMSG="$ERRMSG $XSERVERPKG"
  60.     fi
  61.     ERRMSG="$ERRMSG\" to correct this problem."
  62.     bomb "$ERRMSG"
  63.   fi
  64. }
  65.  
  66. # convert a debconf comma-delimited list to a shell whitespace-delimited list
  67. list_convert () {
  68.   echo $(IFS=", "; set -- $RET; while [ $# -gt 0 ]; do echo \"$1\"; shift; done)
  69. }
  70.  
  71. PROGNAME=${0##*/}
  72. SHOWHELP=
  73. EARLYEXIT=
  74.  
  75. GETOPT_OUTPUT=$(getopt --options ho: \
  76.                        --longoptions help,output: \
  77.                        -n "$PROGNAME" -- "$@")
  78.  
  79. if [ $? -ne 0 ]; then
  80.     bomb "error while getting options; use \"$PROGNAME --help\" for help"
  81. fi
  82.  
  83. eval set -- "$GETOPT_OUTPUT"
  84.  
  85. while :; do
  86.     case "$1" in
  87.         -f|--format)
  88.           bomb "This option, and XFree86 3.x output, are no longer supported."
  89.           ;;
  90.         -h|--help) SHOWHELP=yes EARLYEXIT=yes ;;
  91.         -o|--output) XF86CONFIG="$2"; shift ;;
  92.         --) shift; break ;;
  93.         *)
  94.           bomb "unrecognized option \"$1\"; use \"$PROGNAME --help\" for help"
  95.           ;;
  96.     esac
  97.     shift
  98. done
  99.  
  100. if [ -n "$SHOWHELP" ]; then
  101.     usage
  102. fi
  103.  
  104. if [ -n "$EARLYEXIT" ]; then
  105.     exit 0
  106. fi
  107.  
  108.  
  109. if which laptop-detect >/dev/null 2>&1; then
  110.   if laptop-detect > /dev/null ; then
  111.     LAPTOP=true
  112.   fi
  113. fi
  114.  
  115. DEXCONFTMPDIR=
  116.  
  117. trap 'if [ -e "$DEXCONFTMPDIR/backup" ] && [ -n "$XF86CONFIG" ]; then \
  118.         cat "$DEXCONFTMPDIR/backup" >"$XF86CONFIG"; \
  119.       fi; \
  120.       rm -rf "$DEXCONFTMPDIR"; \
  121.       bomb "received signal; aborting"' HUP INT QUIT TERM
  122.  
  123. # Ensure we know how to write a configuation file for the X server in use.
  124. fetch shared/default-x-server
  125. XSERVERPKG="$RET"
  126. case "$XSERVERPKG" in
  127.   xserver-xorg|xserver-xorg-dbg|xserver-xorg-core)
  128.     : ${XF86CONFIG:=/etc/X11/xorg.conf}
  129.     REALCONFIG="/etc/X11/xorg.conf"
  130.     SERVER="xorg"
  131.     ;;
  132.   *)
  133.     bomb "this program does not know how to configure the \"$XSERVERPKG\" X" \
  134.       "server"
  135. esac
  136.  
  137. # Set up a temporary directory for the files we'll be writing.
  138. TDIR_PARENT="${TMPDIR:-/tmp}"
  139. TDIR="${TMPDIR:-/tmp}/dexconf-tmp-$$"
  140.  
  141. if [ ! -d "$TDIR_PARENT" ]; then
  142.   bomb "cannot create temporary work directory; \"$TDIR_PARENT\" does not" \
  143.     "exist or is not a directory"
  144. fi
  145.  
  146. if [ ! -w "$TDIR_PARENT" ]; then
  147.   bomb "cannot create temporary work directory in \"$TDIR_PARENT\"; directory" \
  148.     "not writable"
  149. fi
  150.  
  151. rm -rf "$TDIR"
  152.  
  153. if mkdir -m 0700 "$TDIR"; then
  154.   DEXCONFTMPDIR="$TDIR"
  155. else
  156.   bomb "creation of temporary work directory \"$TDIR\" failed"
  157. fi
  158.  
  159. # xorg.conf sections:
  160. #   Files          File pathnames
  161. #   ServerFlags    Server flags                      NOT USED BY DEXCONF
  162. #   Module         Dynamic module loading
  163. #   InputDevice    Input device description
  164. #   Device         Graphics device description
  165. #   VideoAdaptor   Xv video adaptor description      NOT USED BY DEXCONF
  166. #   Monitor        Monitor description
  167. #   Modes          Video modes descriptions          NOT USED BY DEXCONF
  168. #   Screen         Screen configuration
  169. #   ServerLayout   Overall layout
  170. #   DRI            DRI-specific configuration
  171. #   Vendor         Vendor-specific configuration     NOT USED BY DEXCONF
  172.  
  173. ### HEADER
  174.  
  175. # Because debconf hijacks standard output and its confmodule uses file
  176. # descriptor 3 for its own purposes, we will write our output to file descriptor
  177. # 4 instead of standard output.
  178.  
  179. exec 4>"$DEXCONFTMPDIR/Header"
  180. cat >&4 <<SECTION
  181. # $REALCONFIG ($SERVER X Window System server configuration file)
  182. #
  183. # This file was generated by dexconf, the Debian X Configuration tool, using
  184. # values from the debconf database.
  185. #
  186. # Edit this file with caution, and see the $REALCONFIG manual page.
  187. # (Type "man $REALCONFIG" at the shell prompt.)
  188. #
  189. # This file is automatically updated on $XSERVERPKG package upgrades *only*
  190. # if it has not been modified since the last upgrade of the $XSERVERPKG
  191. # package.
  192. #
  193. # If you have edited this file but would like it to be automatically updated
  194. # again, run the following command:
  195. #   sudo dpkg-reconfigure -phigh $XSERVERPKG
  196. SECTION
  197.  
  198. ### FILES
  199.  
  200. fetch xserver-$SERVER/config/write_files_section
  201. if [ "$RET" = "true" ]; then
  202.   exec 4>"$DEXCONFTMPDIR/Files"
  203.   cat >&4 <<SECTION
  204. Section "Files"
  205.     FontPath    "/usr/share/X11/fonts/misc"
  206.     FontPath    "/usr/share/X11/fonts/cyrillic"
  207.     FontPath    "/usr/share/X11/fonts/100dpi/:unscaled"
  208.     FontPath    "/usr/share/X11/fonts/75dpi/:unscaled"
  209.     FontPath    "/usr/share/X11/fonts/Type1"
  210.     FontPath    "/usr/share/X11/fonts/100dpi"
  211.     FontPath    "/usr/share/X11/fonts/75dpi"
  212.     FontPath    "/usr/share/fonts/X11/misc"
  213.     # path to defoma fonts
  214.     FontPath    "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType"
  215. EndSection
  216. SECTION
  217. fi
  218.  
  219. ### MODULE
  220.  
  221. # The module list is permitted to be null.
  222. db_get xserver-$SERVER/config/modules || true
  223. if [ -n "$RET" ]; then
  224.   MODULES=$(list_convert "$RET")
  225.   exec 4>"$DEXCONFTMPDIR/Module"
  226.   printf "Section \"Module\"\n" >&4
  227.   for MODULE in $MODULES; do
  228.     printf "\tLoad\t$MODULE\n" >&4
  229.   done
  230.   printf "EndSection\n" >&4
  231. fi
  232.  
  233. ### KEYBOARD / INPUTDEVICE
  234.  
  235. fetch xserver-$SERVER/config/inputdevice/keyboard/rules
  236. XKB_RULES="$RET"
  237. fetch xserver-$SERVER/config/inputdevice/keyboard/model
  238. XKB_MODEL="$RET"
  239. fetch xserver-$SERVER/config/inputdevice/keyboard/layout
  240. XKB_LAYOUT="$RET"
  241. # XkbVariant and XkbOptions are permitted to be null.
  242. db_get xserver-$SERVER/config/inputdevice/keyboard/variant
  243. XKB_VARIANT="$RET"
  244. db_get xserver-$SERVER/config/inputdevice/keyboard/options
  245. XKB_OPTIONS="$RET"
  246.  
  247. exec 4>"$DEXCONFTMPDIR/InputDeviceKeyboard"
  248. cat >&4 <<SECTION
  249. Section "InputDevice"
  250.     Identifier    "Generic Keyboard"
  251.     Driver        "kbd"
  252.     Option        "CoreKeyboard"
  253.     Option        "XkbRules"    "$XKB_RULES"
  254.     Option        "XkbModel"    "$XKB_MODEL"
  255.     Option        "XkbLayout"    "$XKB_LAYOUT"
  256. SECTION
  257. if [ -n "$XKB_VARIANT" ]; then
  258.   printf "\tOption\t\t\"XkbVariant\"\t\"$XKB_VARIANT\"\n" >&4
  259. fi
  260. if [ -n "$XKB_OPTIONS" ]; then
  261.   printf "\tOption\t\t\"XkbOptions\"\t\"$XKB_OPTIONS\"\n" >&4
  262. fi
  263. printf "EndSection\n" >&4
  264.  
  265. ### MOUSE / INPUTDEVICE
  266.  
  267. DO_EMULATE3BUTTONS=
  268.  
  269. fetch xserver-$SERVER/config/inputdevice/mouse/port
  270. MOUSE_PORT="$RET"
  271. fetch xserver-$SERVER/config/inputdevice/mouse/protocol
  272. MOUSE_PROTOCOL="$RET"
  273. fetch xserver-$SERVER/config/inputdevice/mouse/emulate3buttons
  274. if [ "$RET" = "true" ]; then
  275.   DO_EMULATE3BUTTONS=true
  276. fi
  277.  
  278. exec 4>"$DEXCONFTMPDIR/InputDeviceMouse"
  279. cat >&4 <<SECTION
  280. Section "InputDevice"
  281.     Identifier    "Configured Mouse"
  282.     Driver        "mouse"
  283.     Option        "CorePointer"
  284.     Option        "Device"        "/dev/input/mice"
  285.     Option        "Protocol"        "ExplorerPS/2"
  286.     Option        "ZAxisMapping"        "4 5"
  287. SECTION
  288. if [ -n "$DO_EMULATE3BUTTONS" ]; then
  289.   printf "\tOption\t\t\"Emulate3Buttons\"\t\"true\"\n" >&4
  290. fi
  291. printf "EndSection\n" >&4
  292.  
  293. if [ -n "$LAPTOP" ]; then
  294.   cat >&4 <<SECTION
  295.  
  296. Section "InputDevice"
  297.     Identifier    "Synaptics Touchpad"
  298.     Driver        "synaptics"
  299.     Option        "SendCoreEvents"    "true"
  300.     Option        "Device"        "/dev/psaux"
  301.     Option        "Protocol"        "auto-dev"
  302.     Option        "HorizScrollDelta"    "0"
  303. EndSection
  304. SECTION
  305. fi
  306.  
  307. cat >&4 <<SECTION
  308.  
  309. Section "InputDevice"
  310.   Driver        "wacom"
  311.   Identifier    "stylus"
  312.   Option        "Device"        "/dev/wacom"          # Change to 
  313.                                                       # /dev/input/event
  314.                                                       # for USB
  315.   Option        "Type"          "stylus"
  316.   Option        "ForceDevice"   "ISDV4"               # Tablet PC ONLY
  317. EndSection
  318.  
  319. Section "InputDevice"
  320.   Driver        "wacom"
  321.   Identifier    "eraser"
  322.   Option        "Device"        "/dev/wacom"          # Change to 
  323.                                                       # /dev/input/event
  324.                                                       # for USB
  325.   Option        "Type"          "eraser"
  326.   Option        "ForceDevice"   "ISDV4"               # Tablet PC ONLY
  327. EndSection
  328.  
  329. Section "InputDevice"
  330.   Driver        "wacom"
  331.   Identifier    "cursor"
  332.   Option        "Device"        "/dev/wacom"          # Change to 
  333.                                                       # /dev/input/event
  334.                                                       # for USB
  335.   Option        "Type"          "cursor"
  336.   Option        "ForceDevice"   "ISDV4"               # Tablet PC ONLY
  337. EndSection
  338. SECTION
  339.  
  340. ### DEVICE
  341.  
  342. fetch xserver-$SERVER/config/device/identifier
  343. DEVICE_IDENTIFIER="$RET"
  344. fetch xserver-$SERVER/config/device/driver
  345. DEVICE_DRIVER="$RET"
  346. # BusID, VideoRam, and UseFBDev are permitted to be null.
  347. db_get xserver-$SERVER/config/device/bus_id
  348. DEVICE_BUSID="$RET"
  349. db_get xserver-$SERVER/config/device/video_ram
  350. DEVICE_VIDEO_RAM="$RET"
  351. db_get xserver-$SERVER/config/device/use_fbdev
  352. DEVICE_USE_FBDEV="$RET"
  353. fetch xserver-$SERVER/config/monitor/identifier
  354. MONITOR_IDENTIFIER="$RET"
  355. exec 4>"$DEXCONFTMPDIR/Device"
  356. cat >&4 <<SECTION
  357. Section "Device"
  358.     Identifier    "$DEVICE_IDENTIFIER"
  359.     Driver        "$DEVICE_DRIVER"
  360. SECTION
  361. if [ -n "$DEVICE_BUSID" ]; then
  362.   printf "\tBusID\t\t\"$DEVICE_BUSID\"\n" >&4
  363. fi
  364. if [ -n "$DEVICE_VIDEO_RAM" ]; then
  365.    printf "\tVideoRam\t$DEVICE_VIDEO_RAM\n" >&4
  366. fi
  367. if [ "$DEVICE_USE_FBDEV" = "true" ]; then
  368.   printf "\tOption\t\t\"UseFBDev\"\t\t\"$DEVICE_USE_FBDEV\"\n" >&4
  369. fi
  370. if [ "$DEVICE_DRIVER" = "i810" ] && \
  371.   [ "$DEVICE_IDENTIFIER" = "Intel Corporation 82852/855GM Integrated Graphics Device" ] && \
  372.     [ "$MONITOR_IDENTIFIER" = "3M Touchscreen" ]; then
  373.       printf "\tOption\t\t\"DisplayInfo\"\t\t\"False\"\n" >&4
  374. fi
  375. if [ "$DEVICE_DRIVER" = "mga" ]; then
  376.   printf "\tOption\t\t\"OldDmaInit\"\t\t\"True\"\n" >&4
  377. fi
  378. printf "EndSection\n" >&4
  379.  
  380. ### Elographic touch screen. It's both screen and input..
  381.  
  382. ELOTOUCH=no
  383. if [ "$DEVICE_DRIVER" = "i810" ] && \
  384.    [ "$DEVICE_IDENTIFIER" = "Intel Corporation 82845G/GL[Brookdale-G]/GE Chipset Integrated Graphics Device" ] && \
  385.    [ "$MONITOR_IDENTIFIER" = "Elographic Screen" ]; then
  386. ELOTOUCH=yes
  387. exec 4>>"$DEXCONFTMPDIR/InputDeviceMouse"
  388. cat >&4 <<SECTION
  389.  
  390. Section "InputDevice"
  391.         Identifier "Elographic TouchScreen"
  392.         Driver "elographics" 
  393.         Option "Device" "/dev/ttyS6"
  394.         Option "AlwaysCore"
  395.         Option "CorePointer"
  396.         Option "screenno" "0"
  397.         Option "MinX" "0"
  398.         Option "MaxX" "3950"
  399.         Option "MinY" "0"
  400.         Option "MaxY" "3950"
  401.         Option "UntouchDelay" "3"
  402.         Option "ReportDelay" "1"
  403. EndSection
  404. SECTION
  405. fi
  406.  
  407. ### MONITOR
  408.  
  409. fetch xserver-$SERVER/config/monitor/identifier
  410. MONITOR_IDENTIFIER="$RET"
  411. fetch xserver-$SERVER/config/monitor/horiz-sync
  412. MONITOR_HORIZ_SYNC="$RET"
  413. fetch xserver-$SERVER/config/monitor/vert-refresh
  414. MONITOR_VERT_REFRESH="$RET"
  415. db_get xserver-$SERVER/config/monitor/use_sync_ranges
  416. MONITOR_SYNC_RANGES="$RET"
  417.  
  418. exec 4>"$DEXCONFTMPDIR/Monitor"
  419. cat >&4 <<SECTION
  420. Section "Monitor"
  421.     Identifier    "$MONITOR_IDENTIFIER"
  422.     Option        "DPMS"
  423. SECTION
  424.  
  425. if [ "$MONITOR_SYNC_RANGES" = "true" ]; then
  426. cat >&4 <<SECTION
  427.     HorizSync    $MONITOR_HORIZ_SYNC
  428.     VertRefresh    $MONITOR_VERT_REFRESH
  429. SECTION
  430. fi
  431.  
  432. printf "EndSection\n" >&4
  433.  
  434. ### SCREEN
  435.  
  436. fetch xserver-$SERVER/config/display/default_depth
  437. DISPLAY_DEFAULT_DEPTH="$RET"
  438. fetch xserver-$SERVER/config/display/modes
  439. DISPLAY_MODES="$(list_convert $RET)"
  440.  
  441. exec 4>"$DEXCONFTMPDIR/Screen"
  442. cat >&4 <<SECTION
  443. Section "Screen"
  444.     Identifier    "Default Screen"
  445.     Device        "$DEVICE_IDENTIFIER"
  446.     Monitor        "$MONITOR_IDENTIFIER"
  447.     DefaultDepth    $DISPLAY_DEFAULT_DEPTH
  448. SECTION
  449. for DEPTH in 1 4 8 15 16 24; do
  450.   printf "\tSubSection \"Display\"\n" >&4
  451.   printf "\t\tDepth\t\t$DEPTH\n" >&4
  452.   if [ -n "$DISPLAY_MODES" ]; then
  453.     printf "\t\tModes\t\t$DISPLAY_MODES\n" >&4
  454.   fi
  455.   printf "\tEndSubSection\n" >&4
  456. done
  457. printf "EndSection\n" >&4
  458.  
  459. ### SERVERLAYOUT
  460.  
  461. exec 4>"$DEXCONFTMPDIR/ServerLayout"
  462. cat >&4 <<SECTION
  463. Section "ServerLayout"
  464.     Identifier    "Default Layout"
  465.     Screen        "Default Screen"
  466.     InputDevice    "Generic Keyboard"
  467.     InputDevice    "Configured Mouse"
  468.     InputDevice     "stylus" "SendCoreEvents"
  469.     InputDevice     "cursor" "SendCoreEvents"
  470.     InputDevice     "eraser" "SendCoreEvents"
  471. SECTION
  472. if [ -n "$LAPTOP" ]; then
  473.   printf "\tInputDevice\t\"Synaptics Touchpad\"\n" >&4
  474. fi
  475. if [ "$ELOTOUCH" = "yes" ]; then
  476.   printf "\tInputDevice\t\"Elographic TouchScreen\"\n" >&4
  477. fi
  478. printf "EndSection\n" >&4
  479.  
  480. ### DRI
  481. exec 4>"$DEXCONFTMPDIR/DRI"
  482. cat >&4 <<SECTION
  483. Section "DRI"
  484.     Mode    0666
  485. EndSection
  486. SECTION
  487.  
  488. # Tell debconf to stop listening to us.
  489. db_stop
  490.  
  491. # Write the configuration file.  Put a blank line before every section we write
  492. # except the first.
  493.  
  494. OUTFILE="$DEXCONFTMPDIR/dexconf-out"
  495. umask 022
  496. : >"$OUTFILE"
  497.  
  498. SPACER=
  499. for SECTION in Header Files Module InputDeviceKeyboard InputDeviceMouse \
  500.                Device Monitor Screen ServerLayout DRI; do
  501.   if [ -e "$DEXCONFTMPDIR/$SECTION" ]; then
  502.     eval $SPACER
  503.     cat "$DEXCONFTMPDIR/$SECTION" >>"$OUTFILE"
  504.     SPACER='echo "" >>"$OUTFILE"'
  505.   fi
  506. done
  507.  
  508. # Ensure we can write to our destination if it already exits.
  509. if [ -e "$XF86CONFIG" ]; then
  510.   if [ ! -w "$XF86CONFIG" ]; then
  511.     bomb "unable to write to \"$XF86CONFIG\""
  512.   fi
  513. fi
  514.  
  515. BACKUP=
  516. # Create a backup of the existing configuration file if it already exists.
  517. if [ -e "$XF86CONFIG" ]; then
  518.   cat "$XF86CONFIG" >"$DEXCONFTMPDIR/backup"
  519.   BACKUP=true
  520. fi
  521.  
  522. # Move the new file into place.
  523. if ! cat "$OUTFILE" >"$XF86CONFIG"; then
  524.   # Failed; try to restore the backup.
  525.   if [ -n "$BACKUP" ]; then
  526.     cat "$DEXCONFTMPDIR/backup" >"$XF86CONFIG"
  527.   fi
  528. fi
  529.  
  530. rm -rf "$DEXCONFTMPDIR"
  531.  
  532. exit 0
  533.  
  534. # vim:set ai et sts=2 sw=2 tw=80:
  535.