#!/bin/bash # Author: Steven Shiau # License: GPL # Description: From X version 7.3, "dpkg-reconfigure xserver-xorg" won't ask about VGA driver and screeen resolution, therefore we have to drop the "dpkg-reconfigure xserver-xorg" mechanism. # Ref: http://forums.debian.net/viewtopic.php?t=26577 # Load DRBL setting and functions DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions [ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf [ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions # Load ocs_lang if it exists [ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf # check_if_root # Get the live media mount point. get_live_media_mnt_point # ask_and_load_lang_set # if [ -z "$LIVE_MEDIA" -o ! -d "/$LIVE_MEDIA" ]; then echo "$0 should be run in DRBL Live!" echo "Program terminated!" exit 1 fi # if ! type X >/dev/null 2>&1; then echo "No X program! Skip X configure!" exit 3 fi # Default settings xconf="/etc/X11/xorg.conf" start_x="yes" # functions USAGE() { echo "Usage:" echo "To configure X config" echo "$0 [OPTION]" echo "OPTION:" echo "-s, --skip-start-x After xorg.conf is created, skip asking if want to start X" } # end of USAGE # Check if root or not check_if_root() { if [ ! "$UID" = "0" ]; then echo echo "[$LOGNAME] You need to run this script \"`basename $0`\" as root." echo exit 1 fi } # end of check_if_root # set_priority() { echo '*****************************************************' [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING echo "Which mode do you want when configuring X ?" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo "0: Beginner mode, use whatever the default priority of question is." echo "1: Medium mode." echo "2: Expert mode, very verbose." [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING echo "///NOTE/// If graphical environment (X-window) fails to start, you can:" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo " (a): Run \"sudo $0\" to configure it again. Use '1: Medium mode' or '2: Expert mode', then say 'no' to 'Attempt to autodetect video buffer' so that you can choose 'vesa' as the X server driver. When 'Attempt monitor autodetection', say 'no' either so that you can choose 1024x768, 800x600 or 640x480 as your resolution. For the rest of settings, you can accept the default values if you have no idea about them." echo " (b): Run \"sudo service lightdm restart\" to enter graphical environment." echo -n "[0] " read ans_ver case "$ans_ver" in # Beginner means only ask high priority question # Expert means ask low priority question 1) PRIORITY="medium" ;; 2) PRIORITY="low" ;; *) PRIORITY="high" ;; esac } # end of set_priority # choose_resolution() { echo '*****************************************************' [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING echo "$msg_program_to_create_X_config_with_60_Hz" echo "$msg_which_resolution_do_u_want" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo "0: 640x480" echo "1: 800x600" echo "2: 1024x768" echo "3: 1152x864" echo "4: 1280x800" echo "5: 1280x960" echo "6: 1280x1024" echo "7: 1440x1080" echo -n "[2] " read ans_res case "$ans_res" in 0) gtf_param="640 480 60" pmode="640x480" ;; 1) gtf_param="800 600 60" pmode="800x600" ;; 3) gtf_param="1152 864 60" pmode="1152x864" ;; 4) gtf_param="1280 800 60" pmode="1280x800" ;; 5) gtf_param="1280 960 60" pmode="1280x960" ;; 6) gtf_param="1280 1024 60" pmode="1280x1024" ;; 7) gtf_param="1440 1080 60" pmode="1440x1080" ;; *) gtf_param="1024 768 60" pmode="1024x768" ;; esac echo '*****************************************************' [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING echo "$msg_which_vga_card_driver" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo -n "[vesa] " read ans_vga case "$ans_vga" in "") vga_driver="vesa" ;; *) vga_driver="$ans_vga" ;; esac echo '*****************************************************' [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING echo "$msg_which_color_depth_do_u_want" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo "0: 24" echo "1: 16" echo "2: 15" echo "3: 8" echo -n "[0] " read ans_dep case "$ans_dep" in 1) depth="16" ;; 2) depth="15" ;; 3) depth="8" ;; *) depth="24" ;; esac } # end of choose_resolution # gen_xorg.conf() { cat <<-XCONF_END > $xconf # xorg.conf (X.Org X Window System server configuration file) # # This file was generated by DRBL live. # # Edit this file with caution, and see the xorg.conf manual page. Section "InputDevice" # ///NOTE/// The keyboard layout will be overwritten when enter X by loadkey command. Therefore here this section is useless. Just for the X to start normally. Identifier "Generic Keyboard" Driver "kbd" Option "XkbRules" "xorg" Option "XkbModel" "pc104" Option "XkbLayout" "us" EndSection Section "InputDevice" Identifier "Configured Mouse" Driver "mouse" EndSection Section "Device" Identifier "Configured Video Device" XCONF_END cat <<-XCONF_END >> $xconf Driver "$vga_driver" EndSection XCONF_END cat <<-XCONF_END >> $xconf Section "Monitor" Identifier "Configured Monitor" XCONF_END gtf $gtf_param >> $xconf cat <<-XCONF_END >> $xconf Option "PreferredMode" "$pmode" XCONF_END cat <<-XCONF_END >> $xconf EndSection Section "Screen" Identifier "Default Screen" Monitor "Configured Monitor" DefaultDepth $depth SubSection "Display" Depth $depth Modes "$pmode" EndSubSection EndSection XCONF_END } # end of gen_xorg.conf # reconfig_Xorg() { local xver RC xver="$(dpkg-query -W --showformat '${Version}\n' xserver-xorg | awk -F":" '{print $2}')" # Ref: https://bugs.launchpad.net/bugs/207409 if dpkg --compare-versions "$xver" ">=" "7.3"; then choose_resolution gen_xorg.conf echo "$xconf was created." [ -e "$xconf" ] && RC=0 else # For old version, we can use dpkg-reconfigure xserver-xorg set_priority echo -n "Running \"dpkg-reconfigure --priority=$PRIORITY xserver-xorg\"... " LC_ALL=C dpkg-reconfigure --priority=$PRIORITY xserver-xorg RC=$? fi if [ "$RC" -eq 0 ]; then echo "X is now configured." else [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE echo "Failed to configure X config file." [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo "$msg_program_stop" exit 1 fi } # end of reconfig_Xorg ############ ### MAIN ### ############ check_if_root # while [ $# -gt 0 ]; do case "$1" in -s|--skip-start-x) start_x="no" shift ;; -*) echo "${0}: ${1}: invalid option" >&2 USAGE >& 2 exit 2 ;; *) break ;; esac done # Clean the old config if exists before reconfigure. It must be empty otherwise the setting we append won't work. rm -f $xconf reconfig_Xorg # if [ "$start_x" = "yes" ]; then echo '*****************************************************' [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING echo "Do you want to run \"sudo service lightdm restart\" to enter graphical environment ?" [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL echo -n "[Y/n] " read enter_X case "$enter_X" in n|N|[nN][oO]) exit 1 ;; *) sudo service lightdm restart ;; esac fi