File: Forcevideo

package info (click to toggle)
clonezilla 5.12.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,580 kB
  • sloc: sh: 41,014; perl: 193; python: 59; makefile: 26
file content (243 lines) | stat: -rwxr-xr-x 6,874 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# 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

if ! type X >/dev/null 2>&1; then
  echo "No X program! Skip X configure!"
  exit 0
fi

# Default settings
xconf="/etc/X11/xorg.conf"
start_x="yes"

# Load functions
. /usr/share/gparted/bin/gl-functions

# 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
#
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 Forcevideo\" 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 startx\" 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_prority
#
choose_resolution() {
  echo '*****************************************************'
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "This program will create $xconf with screen freq 60 Hz."
  echo "Which resolution do you want ?"
  [ "$BOOTUP" = "color" ] && $SETCOLOR_NORMAL
  echo "0: 640x480"
  echo "1: 800x600"
  echo "2: 1024x768"
  echo "3: 1152x864"
  echo "4: 1280x960"
  echo "5: 1280x1024"
  echo "6: 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 960 60"   
       pmode="1280x960"
       ;;
    5) gtf_param="1280 1024 60"   
       pmode="1280x1024"
       ;;
    6) gtf_param="1440 1080 60"   
       pmode="1440x1080"
       ;;
    *) gtf_param="1024 768 60"   
       pmode="1024x768"
       ;;
  esac
  echo '*****************************************************'
  [ "$BOOTUP" = "color" ] && $SETCOLOR_WARNING
  echo "What driver for your VGA card ? Ex. vesa, i810, nv, ati..."
  [ "$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 "What color depth do you 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 GParted 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."
    [ "$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 startx\" 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 startx
       ;;
  esac
fi