#!/bin/bash # mkorgconfig - Create a working xorg.xonf file # (C) Klaus Knopper 2006 # License: GPL V2 PATH="/bin:/usr/bin:/sbin:/usr/sbin"; export PATH umask 022 # [ "`id -u`" != "0" ] && echo "WARNING: $0 has to run as root to work properly." 1>&2 # ANSI COLORS CRE=" " NORMAL="" # RED: Failure or error message RED="" # GREEN: Success message GREEN="" # YELLOW: Descriptions YELLOW="" # BLUE: System messages BLUE="" # MAGENTA: Found devices or drivers MAGENTA="" # CYAN: Questions CYAN="" # BOLD WHITE: Hint WHITE="" TMPFILE="/tmp/mkxorgconfig-$$" MONITORTMP="$TMPFILE-monitor" rm -f "$TMPFILE" "$MONITORTMP" ### Utility Function(s) KVER="$(uname -r)" # Reread boot command line; echo last parameter's argument or return false. CMDLINE="$(cat /proc/cmdline)" # "modelines" and "no composite" is the safe default NOMODELINES="" COMPOSITE="" for i in "$@"; do case "$i" in -nomodeline*) NOMODELINES="true";; -composite*) COMPOSITE="true";; esac done getbootparam(){ case "$CMDLINE" in *\ $1=*) ;; *) return 1; ;; esac result="${CMDLINE##*$1=}" result="${result%%[ ]*}" echo "$result" return 0 } checkbootparam(){ case "$CMDLINE" in *\ $1*) return 0;; esac return 1 } # Read in what hwsetup has found for X [ -f /etc/sysconfig/xserver ] && . /etc/sysconfig/xserver # Xserver, Xmodule, Xscreen, Xvrefresh, if specified by commandline # MUST/WILL be set (default "Xorg"). if [ -z "$XSERVER" ]; then NEWXSERVER="$(getbootparam xserver 2>/dev/null)" [ -z "$NEWXSERVER" ] && NEWXSERVER="Xorg" XSERVER="$NEWXSERVER" echo "XSERVER='$XSERVER'" >> /etc/sysconfig/knoppix ; echo "XSERVER='$XSERVER'" >> /etc/sysconfig/xserver fi # MUST/WILL be set (default "vesa"). if [ -z "$XMODULE" ]; then NEWXMODULE="$(getbootparam xmodule 2>/dev/null)" [ -z "$NEWXMODULE" ] && NEWXMODULE="vesa" XMODULE="$NEWXMODULE" echo "XMODULE='$XMODULE'" >> /etc/sysconfig/knoppix echo "XMODULE='$XMODULE'" >> /etc/sysconfig/xserver fi # Optional. if [ -z "$XSCREEN" ]; then XSCREEN="$(getbootparam xscreen 2>/dev/null)" [ -z "$XSCREEN" ] && XSCREEN="$(getbootparam screen 2>/dev/null)" [ -n "$XSCREEN" ] && { echo "XSCREEN='$XSCREEN'" >> /etc/sysconfig/knoppix ; echo "XSCREEN='$XSCREEN'" >> /etc/sysconfig/xserver; } fi # Optional if [ -z "$XVREFRESH" ]; then XVREFRESH="$(getbootparam xvrefresh 2>/dev/null)" [ -n "$XVREFRESH" ] || XVREFRESH="$(getbootparam vrefresh 2>/dev/null)" [ -n "$XVREFRESH" ] || XVREFRESH="$(getbootparam xvsync 2>/dev/null)" [ -n "$XVREFRESH" ] || XVREFRESH="$(getbootparam vsync 2>/dev/null)" [ -n "$XVREFRESH" ] && { echo "XVREFRESH='$XVREFRESH'" >> /etc/sysconfig/knoppix ; echo "XVREFRESH='$XVREFRESH'" >> /etc/sysconfig/xserver; } fi # Optional if [ -z "$XHREFRESH" ]; then XHREFRESH="$(getbootparam xhrefresh 2>/dev/null)" [ -n "$XHREFRESH" ] || XHREFRESH="$(getbootparam hrefresh 2>/dev/null)" [ -n "$XHREFRESH" ] || XHREFRESH="$(getbootparam xhsync 2>/dev/null)" [ -n "$XHREFRESH" ] || XHREFRESH="$(getbootparam hsync 2>/dev/null)" [ -n "$XHREFRESH" ] && { echo "XHREFRESH='$XHREFRESH'" >> /etc/sysconfig/knoppix ; echo "XHREFRESH='$XHREFRESH'" >> /etc/sysconfig/xserver; } fi # Optional if [ -z "$XHREFRESH" ]; then XDEPTH="$(getbootparam xdepth 2>/dev/null)" [ -n "$XDEPTH" ] || XDEPTH="$(getbootparam depth 2>/dev/null)" [ -n "$XDEPTH" ] && { echo "XDEPTH='$XDEPTH'" >> /etc/sysconfig/knoppix ; echo "XDEPTH='$XDEPTH'" >> /etc/sysconfig/xserver; } fi # Wheel WHEEL="" if checkbootparam "wheel"; then WHEEL='s|"PS/2"|"IMPS/2"\ Option "ZAxisMapping" "4 5"|g;' elif checkbootparam "nowheel"; then # Don't change the default, which is plain PS/2 WHEEL="" else # Apparently, the mouse auto-protocol option works in XFree 4.3 now. Let's give it a try. WHEEL='s|"PS/2"|"auto"\ Option "ZAxisMapping" "4 5"|g;' fi # Read in changes [ -f /etc/sysconfig/xserver ] && . /etc/sysconfig/xserver # Read default keyboard from config file. # There seems to be no reliable autoprobe possible. [ -f /etc/sysconfig/keyboard ] && . /etc/sysconfig/keyboard # Create mouse link and insert a mouse default type into xorg.conf # if not already done by hwsetup [ -f /etc/sysconfig/mouse ] && . /etc/sysconfig/mouse [ -e /dev/mouse ] || ln -sf /dev/ttyS0 /dev/mouse # PROTO="${XMOUSETYPE:-Auto}" PROTO="${XMOUSETYPE:-Microsoft}" NOEMU="" [ "${XEMU3}" = "no" ] && NOEMU='s|^.*Emulate3|# No 2 -> 3 Button emulation|g' DEADKEYS="" [ "$XKEYBOARD" = "de" ] || DEADKEYS='s|^.*nodeadkeys.*$||g;' if [ -n "XMODULE" ]; then # Check for Framebuffer X-Modules and initialize framebuffer module case "$XMODULE" in pvr2fb) modprobe "$XMODULE" >/dev/null 2>&1 ; XMODULE="fbdev"; ;; esac fi NODDC="" checkbootparam noddc && NODDC="true" MONITOR="" COMPLETE="" RC="" if [ -z "$NODDC" ]; then # Try to get Monitor data via ddcxinfo-knoppix if [ -z "$NOMODELINES" ]; then MONITOR="$(ddcxinfo-knoppix -monitor)" else MONITOR="$(ddcxinfo-knoppix -monitor | sed 's/ModeLine/# ModeLine/ig')" fi RC="$?" COMPLETE="$(awk '/EndSection/{print}' <"$MONITORTMP" # /etc/X11/XF86Config is the configuration file for VERY OLD cards that still need XFree3. if [ -r /etc/X11//etc/X11/XF86Config.in ] && [ ! -f /etc/X11/XF86Config -o /etc/X11/XF86Config.in -nt /etc/X11/XF86Config ]; then # Remove it, just in case it's a link to CD rm -f /etc/XF86Config /etc/X11/XF86Config 2>/dev/null sed -e 's|@@PROTOCOL@@|'"$PROTO"'|g;'"$NOEMU" \ -e '/@@MONITOR@@/r '"$MONITORTMP" \ -e 's|@@MONITOR@@||g' \ -e 's|@@MODES@@|'"$MODES"'|g;'"$DEPTH" \ -e 's|XkbLayout *"[^"]*"|XkbLayout "'"$XKEYBOARD"'"|g;'"$DEADKEYS" \ /etc/X11/XF86Config.in > /etc/X11/XF86Config fi # (Re-)create /etc/X11/xorg.conf if not present or /etc/X11/xorg.conf.in has been updated recently if [ -r /etc/X11/xorg.conf.in ] && [ ! -f /etc/X11/xorg.conf -o /etc/X11/xorg.conf.in -nt /etc/X11/xorg.conf ]; then rm -f /etc/X11/xorg.conf /etc/X11/xorg.conf.new 2>/dev/null # VMWare special handling VMWARE="" if [ "$XMODULE" = "vmware" ]; then VMWARE='s|^.*BusID.*PCI.*$|BusID "PCI:0:15:0"|g;' DEPTH='s|DefaultColorDepth |# DefaultColorDepth |g;' fi # Do NOT use a default colordepth setting if we are using the "fbdev" module if [ "$XMODULE" = "fbdev" ]; then DEPTH='s|DefaultColorDepth |# DefaultColorDepth |g;' fi # These drivers need the sw_cursor option SWCURSOR="" case "$XMODULE" in trident) SWCURSOR='s|^.*#Option.*"sw_cursor".*$|Option "sw_cursor"|g;';; esac # We must use NoPM, because some machines freeze if Power management is being activated. NOPM="" DPMS="" checkbootparam noapm && NOPM='Option "NoPM" "true"' || DPMS='Option "DPMS" "true"' sed -e 's|@@PROTOCOL@@|'"$PROTO"'|g;'"$NOEMU" \ -e '/@@MONITOR@@/r '"$MONITORTMP" \ -e 's|@@MONITOR@@||g' \ -e 's|@@COMPOSITE@@|'"$COMPOSITE"'|g' \ -e 's|@@NOPM@@|'"$NOPM"'|g' \ -e 's|@@XMODULE@@|'"$XMODULE"'|g;'"$VMWARE""$SERIALMOUSE""$USBMOUSE""$PSMOUSE""$SWCURSOR""$WHEEL" \ -e 's|@@MODES@@|'"$MODES"'|g;'"$DEPTH" \ -e 's|"XkbLayout" *"[^"]*"|"XkbLayout" "'"$XKEYBOARD"'"|g;'"$DEADKEYS" \ /etc/X11/xorg.conf.in >/etc/X11/xorg.conf if [ -n "$DPMS" ]; then sed -e 's|Identifier[ ]*"Monitor0"|Identifier "Monitor0"\ '"$DPMS"'|g' /etc/X11/xorg.conf >/etc/X11/xorg.conf.new mv -f /etc/X11/xorg.conf.new /etc/X11/xorg.conf fi fi rm -f "$TMPFILE" "$MONITORTMP" 2>/dev/null # Print info about selected X-Server [ -n "$XDESC" ] || XDESC="(yet) unknown card" echo -n " ${GREEN}Video is" [ -n "$XDESC" ] && echo -n " ${YELLOW}$XDESC${GREEN}," echo -n " using ${YELLOW}${XSERVER:-generic VESA}" [ -n "$XMODULE" ] && echo -n "(${MAGENTA}$XMODULE${YELLOW})" echo " Server${NORMAL}" echo -n " ${GREEN}Monitor is ${YELLOW}${MODEL:-Generic Monitor}${NORMAL}" [ -n "$HREFRESH" -a -n "$VREFRESH" ] && echo "${GREEN}, ${GREEN}H:${YELLOW}${HREFRESH}kHz${GREEN}, V:${YELLOW}${VREFRESH}Hz${NORMAL}" || echo "" [ -n "$XVREFRESH" ] && echo " ${GREEN}Trying specified vrefresh rate of ${YELLOW}${XVREFRESH}Hz.${NORMAL}" [ -n "$MODES" ] && echo " ${GREEN}Using Modes ${YELLOW}${MODES##Modes }${NORMAL}"