| 1 | #!/bin/bash |
| 2 | # Author: Steven Shiau <steven _at_ clonezilla org> |
| 3 | # License: GPL |
| 4 | # 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. |
| 5 | # Ref: http://forums.debian.net/viewtopic.php?t=26577 |
| 6 | |
| 7 | # Load DRBL setting and functions |
| 8 | DRBL_SCRIPT_PATH="${DRBL_SCRIPT_PATH:-/usr/share/drbl}" |
| 9 | |
| 10 | . $DRBL_SCRIPT_PATH/sbin/drbl-conf-functions |
| 11 | [ -e /etc/drbl/drbl-ocs.conf ] && . /etc/drbl/drbl-ocs.conf |
| 12 | [ -e $DRBL_SCRIPT_PATH/sbin/ocs-functions ] && . $DRBL_SCRIPT_PATH/sbin/ocs-functions |
| 13 | |
| 14 | # Load ocs_lang if it exists |
| 15 | [ -e /etc/ocs/ocs-live.conf ] && . /etc/ocs/ocs-live.conf |
| 16 | |
| 17 | # |
| 18 | check_if_root |
| 19 | |
| 20 | # Get the live media mount point. |
| 21 | get_live_media_mnt_point |
| 22 | |
| 23 | # |
| 24 | ask_and_load_lang_set |
| 25 | |
| 26 | # |
| 27 | if [ -z "$LIVE_MEDIA" -o ! -d "/$LIVE_MEDIA" ]; then |
| 28 | echo "$0 should be run in DRBL Live!" |
| 29 | echo "Program terminated!" |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | # |
| 34 | if ! type X >/dev/null 2>&1; then |
| 35 | echo "No X program! Skip X configure!" |
| 36 | exit 3 |
| 37 | fi |
| 38 | |
| 39 | # Default settings |
| 40 | xconf="/etc/X11/xorg.conf" |
| 41 | start_x="yes" |
| 42 | |
| 43 | # functions |
| 44 | USAGE() { |
| 45 | echo "Usage:" |
| 46 | echo "To configure X config" |
| 47 | echo "$0 [OPTION]" |
| 48 | echo "OPTION:" |
| 49 | echo "-s, --skip-start-x After xorg.conf is created, skip asking if want to start X" |
| 50 | } # end of USAGE |
| 51 | # Check if root or not |
| 52 | check_if_root() { |
| 53 | if [ ! "$UID" = "0" ]; then |
| 54 | echo |
| 55 | echo "[$LOGNAME] You need to run this script \"`basename $0`\" as root." |
| 56 | echo |
| 57 | exit 1 |
| 58 | fi |
| 59 | } # end of check_if_root |
| 60 | # |
| 61 | set_priority() { |
| 62 | echo '*****************************************************' |
| 63 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 64 | echo "Which mode do you want when configuring X ?" |
| 65 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 66 | echo "0: Beginner mode, use whatever the default priority of question is." |
| 67 | echo "1: Medium mode." |
| 68 | echo "2: Expert mode, very verbose." |
| 69 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 70 | echo "///NOTE/// If graphical environment (X-window) fails to start, you can:" |
| 71 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 72 | 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." |
| 73 | echo " (b): Run \"sudo service lightdm restart\" to enter graphical environment." |
| 74 | echo -n "[0] " |
| 75 | read ans_ver |
| 76 | case "$ans_ver" in |
| 77 | # Beginner means only ask high priority question |
| 78 | # Expert means ask low priority question |
| 79 | 1) PRIORITY="medium" ;; |
| 80 | 2) PRIORITY="low" ;; |
| 81 | *) PRIORITY="high" ;; |
| 82 | esac |
| 83 | } # end of set_priority |
| 84 | # |
| 85 | choose_resolution() { |
| 86 | echo '*****************************************************' |
| 87 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 88 | echo "$msg_program_to_create_X_config_with_60_Hz" |
| 89 | echo "$msg_which_resolution_do_u_want" |
| 90 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 91 | echo "0: 640x480" |
| 92 | echo "1: 800x600" |
| 93 | echo "2: 1024x768" |
| 94 | echo "3: 1152x864" |
| 95 | echo "4: 1280x800" |
| 96 | echo "5: 1280x960" |
| 97 | echo "6: 1280x1024" |
| 98 | echo "7: 1440x1080" |
| 99 | echo -n "[2] " |
| 100 | read ans_res |
| 101 | case "$ans_res" in |
| 102 | 0) gtf_param="640 480 60" |
| 103 | pmode="640x480" |
| 104 | ;; |
| 105 | 1) gtf_param="800 600 60" |
| 106 | pmode="800x600" |
| 107 | ;; |
| 108 | 3) gtf_param="1152 864 60" |
| 109 | pmode="1152x864" |
| 110 | ;; |
| 111 | 4) gtf_param="1280 800 60" |
| 112 | pmode="1280x800" |
| 113 | ;; |
| 114 | 5) gtf_param="1280 960 60" |
| 115 | pmode="1280x960" |
| 116 | ;; |
| 117 | 6) gtf_param="1280 1024 60" |
| 118 | pmode="1280x1024" |
| 119 | ;; |
| 120 | 7) gtf_param="1440 1080 60" |
| 121 | pmode="1440x1080" |
| 122 | ;; |
| 123 | *) gtf_param="1024 768 60" |
| 124 | pmode="1024x768" |
| 125 | ;; |
| 126 | esac |
| 127 | echo '*****************************************************' |
| 128 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 129 | echo "$msg_which_vga_card_driver" |
| 130 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 131 | echo -n "[vesa] " |
| 132 | read ans_vga |
| 133 | case "$ans_vga" in |
| 134 | "") vga_driver="vesa" ;; |
| 135 | *) vga_driver="$ans_vga" ;; |
| 136 | esac |
| 137 | echo '*****************************************************' |
| 138 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 139 | echo "$msg_which_color_depth_do_u_want" |
| 140 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 141 | echo "0: 24" |
| 142 | echo "1: 16" |
| 143 | echo "2: 15" |
| 144 | echo "3: 8" |
| 145 | echo -n "[0] " |
| 146 | read ans_dep |
| 147 | case "$ans_dep" in |
| 148 | 1) depth="16" ;; |
| 149 | 2) depth="15" ;; |
| 150 | 3) depth="8" ;; |
| 151 | *) depth="24" ;; |
| 152 | esac |
| 153 | } # end of choose_resolution |
| 154 | # |
| 155 | gen_xorg.conf() { |
| 156 | cat <<-XCONF_END > $xconf |
| 157 | # xorg.conf (X.Org X Window System server configuration file) |
| 158 | # |
| 159 | # This file was generated by DRBL live. |
| 160 | # |
| 161 | # Edit this file with caution, and see the xorg.conf manual page. |
| 162 | |
| 163 | Section "InputDevice" |
| 164 | # ///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. |
| 165 | Identifier "Generic Keyboard" |
| 166 | Driver "kbd" |
| 167 | Option "XkbRules" "xorg" |
| 168 | Option "XkbModel" "pc104" |
| 169 | Option "XkbLayout" "us" |
| 170 | EndSection |
| 171 | |
| 172 | Section "InputDevice" |
| 173 | Identifier "Configured Mouse" |
| 174 | Driver "mouse" |
| 175 | EndSection |
| 176 | |
| 177 | Section "Device" |
| 178 | Identifier "Configured Video Device" |
| 179 | XCONF_END |
| 180 | |
| 181 | cat <<-XCONF_END >> $xconf |
| 182 | Driver "$vga_driver" |
| 183 | EndSection |
| 184 | |
| 185 | XCONF_END |
| 186 | |
| 187 | cat <<-XCONF_END >> $xconf |
| 188 | Section "Monitor" |
| 189 | Identifier "Configured Monitor" |
| 190 | XCONF_END |
| 191 | |
| 192 | gtf $gtf_param >> $xconf |
| 193 | |
| 194 | cat <<-XCONF_END >> $xconf |
| 195 | Option "PreferredMode" "$pmode" |
| 196 | XCONF_END |
| 197 | |
| 198 | cat <<-XCONF_END >> $xconf |
| 199 | EndSection |
| 200 | |
| 201 | Section "Screen" |
| 202 | Identifier "Default Screen" |
| 203 | Monitor "Configured Monitor" |
| 204 | DefaultDepth $depth |
| 205 | SubSection "Display" |
| 206 | Depth $depth |
| 207 | Modes "$pmode" |
| 208 | EndSubSection |
| 209 | EndSection |
| 210 | |
| 211 | XCONF_END |
| 212 | } # end of gen_xorg.conf |
| 213 | # |
| 214 | reconfig_Xorg() { |
| 215 | local xver RC |
| 216 | xver="$(dpkg-query -W --showformat '${Version}\n' xserver-xorg | awk -F":" '{print $2}')" |
| 217 | # Ref: https://bugs.launchpad.net/bugs/207409 |
| 218 | if dpkg --compare-versions "$xver" ">=" "7.3"; then |
| 219 | choose_resolution |
| 220 | gen_xorg.conf |
| 221 | echo "$xconf was created." |
| 222 | [ -e "$xconf" ] && RC=0 |
| 223 | else |
| 224 | # For old version, we can use dpkg-reconfigure xserver-xorg |
| 225 | set_priority |
| 226 | echo -n "Running \"dpkg-reconfigure --priority=$PRIORITY xserver-xorg\"... " |
| 227 | LC_ALL=C dpkg-reconfigure --priority=$PRIORITY xserver-xorg |
| 228 | RC=$? |
| 229 | fi |
| 230 | if [ "$RC" -eq 0 ]; then |
| 231 | echo "X is now configured." |
| 232 | else |
| 233 | [ "$BOOTUP" = "color" ] && $SETCOLOR_FAILURE |
| 234 | echo "Failed to configure X config file." |
| 235 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 236 | echo "$msg_program_stop" |
| 237 | exit 1 |
| 238 | fi |
| 239 | } # end of reconfig_Xorg |
| 240 | |
| 241 | ############ |
| 242 | ### MAIN ### |
| 243 | ############ |
| 244 | |
| 245 | check_if_root |
| 246 | |
| 247 | # |
| 248 | while [ $# -gt 0 ]; do |
| 249 | case "$1" in |
| 250 | -s|--skip-start-x) |
| 251 | start_x="no" |
| 252 | shift ;; |
| 253 | -*) echo "${0}: ${1}: invalid option" >&2 |
| 254 | USAGE >& 2 |
| 255 | exit 2 ;; |
| 256 | *) break ;; |
| 257 | esac |
| 258 | done |
| 259 | |
| 260 | # Clean the old config if exists before reconfigure. It must be empty otherwise the setting we append won't work. |
| 261 | rm -f $xconf |
| 262 | reconfig_Xorg |
| 263 | |
| 264 | # |
| 265 | if [ "$start_x" = "yes" ]; then |
| 266 | echo '*****************************************************' |
| 267 | [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING |
| 268 | echo "Do you want to run \"sudo service lightdm restart\" to enter graphical environment ?" |
| 269 | [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL |
| 270 | echo -n "[Y/n] " |
| 271 | read enter_X |
| 272 | case "$enter_X" in |
| 273 | n|N|[nN][oO]) |
| 274 | exit 1 |
| 275 | ;; |
| 276 | *) |
| 277 | sudo service lightdm restart |
| 278 | ;; |
| 279 | esac |
| 280 | fi |