#!/bin/sh
#
PATH=/bin:/usr/bin:/sbin:/usr/sbin

cat > /etc/X11/xorg.conf << "EOF"
Section "Module"
    Load        "extmod"
    SubSection  "extmod"
    Option      "omit xfree86-dga"
    EndSubSection
EndSection

Section "Files"
	RgbPath      "/usr/share/X11/rgb"
	ModulePath   "/usr/lib/xorg/modules"
	FontPath     "/usr/share/fonts/TTF"
	FontPath     "/usr/share/fonts/misc"
        FontPath     "/usr/share/fonts/75dpi"
EndSection

Section "ServerFlags"
EndSection

Section "Monitor"
    Identifier  "My Monitor"
    Option	"DPMS"
EOF

ddcxinfo -monitor -modes 2>/dev/null > /tmp/ddcxinfo
if ! grep -q -w HorizSync /tmp/ddcxinfo ; then
echo "        HorizSync  28.0 - 68.0
        VertRefresh  60.0 - 85.0
EndSection" >> /etc/X11/xorg.conf
Modes='Modes "1024x768"'
else
grep -w HorizSync /tmp/ddcxinfo >> /etc/X11/xorg.conf
echo "        VertRefresh  60.0 - 85.0" >> /etc/X11/xorg.conf
echo "EndSection" >> /etc/X11/xorg.conf
if grep -q -w Modes /tmp/ddcxinfo ; then
Modes="`grep -w Modes /tmp/ddcxinfo`"
else
Modes='Modes "1024x768"'
fi
fi

cat >> /etc/X11/xorg.conf << EOF

Section "InputDevice"
    Identifier	"Keyboard1"
    Driver	"kbd"
    Option	"AutoRepeat"	"250 30"
EndSection

Section "InputDevice"
    Identifier	    "Mouse1"
    Driver	    "mouse"
    Option	    "Protocol" "Auto"
EOF

mouse_probe() {
mouse="`mdetect -n -x 2>/dev/null | head -n 1`"
if [ ! "$mouse" = "" ]; then
if [ -r "$mouse" ]; then
if [ "$mouse" = "/dev/input/mouse0" -a -r "/dev/input/mice" ]; then
echo '    Option      "Device"        "/dev/input/mice"' >> /etc/X11/xorg.conf
else
echo '    Option      "Device"        "'$mouse'"' >> /etc/X11/xorg.conf
fi
else
if [ -r /dev/input/mouse0 -a -r /dev/input/mice ]; then
echo '    Option      "Device"        "/dev/input/mice"' >> /etc/X11/xorg.conf
elif [ -r /dev/psaux ]; then
echo '    Option      "Device"        "/dev/psaux"' >> /etc/X11/xorg.conf
elif [ -r /dev/mouse ]; then
echo '    Option      "Device"        "/dev/mouse"' >> /etc/X11/xorg.conf
fi
fi
else
if [ -r /dev/input/mouse0 -a -r /dev/input/mice ]; then
echo '    Option      "Device"        "/dev/input/mice"' >> /etc/X11/xorg.conf
elif [ -r /dev/psaux ]; then
echo '    Option      "Device"        "/dev/psaux"' >> /etc/X11/xorg.conf
elif [ -r /dev/mouse ]; then
echo '    Option      "Device"        "/dev/mouse"' >> /etc/X11/xorg.conf
fi
fi
}

mouse_probe

cat >> /etc/X11/xorg.conf << EOF
    Option          "ZAxisMapping" "4 5"
EndSection
EOF

if grep -q Synaptics /proc/bus/input/devices ; then
cat >> /etc/X11/xorg.conf << EOF

Section "InputDevice"
    Identifier	"Synaptics Touchpad"
    Driver	"synaptics"
    Option	"Protocol"	"auto-dev"
EOF

mouse_probe

cat >> /etc/X11/xorg.conf << EOF
    Option	"LeftEdge"      "1700"
    Option	"RightEdge"     "5300"
    Option	"TopEdge"       "1700"
    Option	"BottomEdge"    "4200"
    Option	"FingerLow"	"25"
    Option	"FingerHigh"	"30"
    Option	"MaxTapTime"	"180"
    Option	"MaxTapMove"	"220"
    Option	"VertScrollDelta" "100"
    Option	"MinSpeed"	"0.09"
    Option	"MaxSpeed"	"0.18"
    Option	"AccelFactor"	"0.0015"
    Option      "SHMConfig"     "on"
EndSection
EOF
elif grep -q ALPS /proc/bus/input/devices ; then
cat >> /etc/X11/xorg.conf << EOF

Section "InputDevice"
    Identifier	"Alps Touchpad"
    Driver	"synaptics"
    Option	"Protocol"		"auto-dev"
EOF

mouse_probe

cat >> /etc/X11/xorg.conf << EOF
    Option	"LeftEdge"		"120"
    Option	"RightEdge"		"830"
    Option	"TopEdge"		"120"
    Option	"BottomEdge"		"650"
    Option	"FingerLow"		"14"
    Option	"FingerHigh"		"15"
    Option	"MaxTapTime"		"180"
    Option	"MaxTapMove"		"110"
    Option	"EmulateMidButtonTime"	"75"
    Option	"VertScrollDelta"	"20"
    Option	"HorizScrollDelta"	"20"
    Option	"MinSpeed"		"0.3"
    Option	"MaxSpeed"		"0.75"
    Option	"AccelFactor"		"0.015"
    Option	"EdgeMotionMinSpeed"	"200"
    Option	"EdgeMotionMaxSpeed"	"200"
    Option	"UpDownScrolling"	"1"
    Option	"CircularScrolling"	"1"
    Option	"CircScrollDelta"	"0.1"
    Option	"CircScrollTrigger"	"2"
EndSection
EOF
fi

cat >> /etc/X11/xorg.conf << EOF

Section "Device"
    Identifier  "Unknown Monitor"
    Driver      "vesa"
EndSection

Section "Screen"
    Identifier  "Screen 1"
    Device      "Unknown Monitor"
    Monitor     "My Monitor"
    DefaultDepth 16
    Subsection "Display"
        Depth       24
        $Modes
    EndSubsection
    Subsection "Display"
        Depth       16
        $Modes
    EndSubsection
EndSection

Section "ServerLayout"
    Identifier  "Simple Layout"
    Screen "Screen 1"
    InputDevice "Mouse1" "CorePointer"
EOF

if grep -q Synaptics /proc/bus/input/devices ; then
cat >> /etc/X11/xorg.conf << EOF
    InputDevice "Synaptics Touchpad" "SendCoreEvents"
EOF
elif grep -q ALPS /proc/bus/input/devices ; then
cat >> /etc/X11/xorg.conf << EOF
    InputDevice "Alps Touchpad" "SendCoreEvents"
EOF
fi

cat >> /etc/X11/xorg.conf << EOF
    InputDevice "Keyboard1" "CoreKeyboard"
EndSection
EOF

cat > $HOME/.xinitrc << EOF
#!/bin/sh
/usr/bin/xsetroot -solid "#266294"
echo "Don't delete this file!" > /tmp/.success
/usr/bin/xset s off
exec /usr/bin/fluxbox
EOF
chmod a+rwx $HOME/.xinitrc

echo "exec /usr/bin/Xorg -dpms -s 240 -bestRefresh -nolisten tcp" >/usr/bin/X
chmod a+rwx /usr/bin/X

dialog --title "DONE!" --msgbox \
"Setup network connection!
# dhclient (or) dhcpcd     

If you want to download and install Adobe Flashplayer for FireFOX!
# install-fp -i 

If you want to setup sound! 
# alsaconf
# alsaconf -a \"Non-interactive sound setup!\"

NOTE: Sound is probably already setup, because
      Kmod automatically loads the sound modules
      at boot time. There's no harm in doing it
      again.

You can also do any of the above from the X menu, in Setup!

# startx 

If X doesn't start, you probably have to forget about it!

Edit /etc/X11/xorg.conf to change anything!

In X, right-click mouse for menu, and move cursor
to bottom of screen to reveal toolbar. You can also
press Alt-F9 for menu, and Alt-F10 to exit menu!

Press Alt-F11 for sound mixer!

To switch to a console press Ctrl-Alt-F2 etc.,
and to switch back to X press Alt-F9." 20 55

echo
