2
# This provides a stripped down 'failsafe' mode for situations
3
# where X is failing to start up.
5
# Author: Bryce W. Harrington <bryce@canonical.com>
7
# Copyright 2007, 2008 Canonical, Ltd
9
# This is free software; you may redistribute it and/or modify
10
# it under the terms of the GNU General Public License as
11
# published by the Free Software Foundation; either version 2,
12
# or (at your option) any later version.
14
# This is distributed in the hope that it will be useful, but
15
# WITHOUT ANY WARRANTY; without even the implied warranty of
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
# GNU General Public License for more details.
19
# You should have received a copy of the GNU General Public License with
20
# the Debian operating system, in /usr/share/common-licenses/GPL; if
21
# not, write to the Free Software Foundation, Inc., 59 Temple Place,
22
# Suite 330, Boston, MA 02111-1307 USA
28
xorg_log="/var/log/Xorg.${display}.log"
29
gdm_log="/var/log/gdm/:${display}.log"
30
gdm_log_1="/var/log/gdm/:${display}.log.1"
31
gdm_log_2="/var/log/gdm/:${display}.log.2"
32
apport_hook="/usr/share/apport/xserver_hook"
36
app_title="$(gettext 'Ubuntu Failsafe-X')"
38
timestamp=$(date +%y%m%d%H%M%S)
41
TEXTDOMAIN=failsafexinit
43
TEXTDOMAINDIR=/usr/share/locale-langpack
49
--title "$app_title" \
50
--width $app_width --height $app_height \
51
--text "$(gettext 'What would you like to do?')" \
52
--column "" --column "$(gettext 'Choice')" --column "" \
53
TRUE LOW_RES_MODE "$(gettext 'Run Ubuntu in low-graphics mode for just one session')" \
54
FALSE RECONFIGURE "$(gettext 'Reconfigure graphics')" \
55
FALSE TROUBLESHOOT "$(gettext 'Troubleshoot the error')" \
56
FALSE EXIT_TO_CONSOLE "$(gettext 'Exit to console login')" \
57
FALSE RESTART_X "$(gettext 'Restart X')" \
60
# TODO: 3 FILE_BUG "Report a bug about this failure" \
63
display_reconfigure_menu() {
64
# TODO: Only display SELECT_BACKUP if backups are available
68
--title "$app_title : $(gettext 'Reconfiguration')" \
69
--text "$(gettext 'How would you like to reconfigure your display?')" \
70
--width $app_width --height $app_height \
71
--column "" --column "$(gettext 'Choice')" --column "" \
72
TRUE DEFAULT_CONFIG "$(gettext 'Use default (generic) configuration')" \
73
FALSE RUN_XORGCONF "$(gettext 'Create new configuration for this hardware')" \
74
FALSE SELECT_BACKUP "$(gettext 'Use your backed-up configuration')" \
78
display_troubleshooting_menu() {
81
--title "$app_title : $(gettext 'Troubleshooting')" \
82
--text "$(gettext 'What information would you like to review?')" \
83
--width $app_width --height $app_height \
84
--column "" --column "$(gettext 'Choice')" --column "" \
85
TRUE VIEW_XORG_LOG "$(gettext 'Review the xserver log file')" \
86
FALSE VIEW_GDM_LOG "$(gettext 'Review the startup errors')" \
87
FALSE EDIT_CONFIG "$(gettext 'Edit configuration file')" \
88
FALSE SAVE_CONFIG_LOGS "$(gettext 'Archive configuration and logs')" \
90
# TODO: 5 VERIFY_XORGCONF "Check configuration file"
93
# TODO: Should we just go ahead and file a bug for them without presenting an option?
94
display_filebug_menu() {
95
# Run apport to file a bug
96
if [ -e $apport_hook ]; then
99
zenity --info --text "$(gettext 'A bug report has been written.\nYou can send it next time you log in.')"
101
zenity --error --text "$(gettext 'Your bug could not be recorded successfully.\n')"
104
zenity --error --text "$(eval_gettext 'Cannot file bug: \$apport_hook is not present.')"
109
# TODO: backup xorg.conf more elegantly...
110
xorg_conf_backup="/etc/X11/xorg.conf-backup-${timestamp}"
111
cp /etc/X11/xorg.conf ${xorg_conf_backup}
113
return zenity --question --text "$(gettext 'Your config could not be backed up.\nDo you want to continue anyway?\n')"
118
backup_xorg_conf || return 1
120
rm /etc/X11/xorg.conf
122
zenity --info --text "$(gettext 'Your configuration has been restored to default,\nand your old configuration backed up.\nPlease restart.\n')"
124
zenity --error --text "$(gettext 'Failure restoring configuration to default.\nYour config has not been changed.')"
129
backup_xorg_conf || return 1
133
zenity --info --text "$(gettext 'A new configuration has been generated,\nand your old configuration backed up.\nPlease restart.\n')"
135
zenity --error --text "$(gettext 'Could not generate a new configuration')"
140
zenity --text-info --filename=$xorg_log --width=640 --height=480
144
zenity --text-info --filename=${gdm_log_1} --width=640 --height=480
148
# Run Alberto's xorg.conf checker (once it's available in main)
149
zenity --error --text "$(gettext 'Sorry, this option is not implemented yet')"
153
backup_xorg_conf || return 1
155
xorg_conf_tmp=$(mktemp -t xorg.conf.XXXXXXXX)
156
zenity --text-info --editable --filename=/etc/X11/xorg.conf --width=640 --height=480 > "${xorg_conf_tmp}" && mv "${xorg_conf_tmp}" /etc/X11/xorg.conf
157
chmod 644 /etc/X11/xorg.conf
161
xorg_backup_name=failsafeX-backup-${timestamp}
162
xorg_backup_dir=$(mktemp -d -t ${xorg_backup_name}.XXX)
163
xorg_backup_file=/var/log/${xorg_backup_name}.tar
165
# cp $xorg_conf $xorg_backup_dir
166
cp /etc/X11/xorg.conf $xorg_backup_dir
167
cp ${xorg_log} $xorg_backup_dir
168
cp ${xorg_log}.old $xorg_backup_dir
169
cp ${gdm_log} $xorg_backup_dir
170
cp ${gdm_log_1} $xorg_backup_dir
171
cp ${gdm_log_2} $xorg_backup_dir
172
lspci -vvnn > ${xorg_backup_dir}/lspci-vvnn.txt
173
xrandr --verbose > ${xorg_backup_dir}/xrandr-verbose.txt
174
tar -cf ${xorg_backup_file} ${xorg_backup_dir}
175
rm -rf ${xorg_backup_dir}
177
zenity --info --text "$(eval_gettext 'Relevant configuration and log files have been saved to:\n')"$xorg_backup_file"\n$(gettext 'Bug reports can be submitted at http://www.launchpad.net/ubuntu/.\n')"
180
# Scan Xorg.0.log for errors
181
LOG_ERRORS=$(grep -e "^(EE)" $xorg_log)
183
if [ -z "$LOG_ERRORS" ]; then
184
zenity --warning --text "$(gettext '<big><b>Ubuntu is running in low-graphics mode</b></big>\n\nYour screen, graphics card, and input device settings\ncould not be detected correctly. You will need to configure these yourself.')"
186
zenity --warning --text "$(gettext '<big><b>Ubuntu is running in low-graphics mode</b></big>\n\nThe following error was encountered. You may need\nto update your configuration to solve this.\n\n')""${LOG_ERRORS}"
189
# TODO: Add --window-icon "$app_icon" to all zenity windows
194
LOW_RES_MODE ) with_gdm="low-res"; break ;;
195
RECONFIGURE ) choice=$(display_reconfigure_menu) ;;
196
TROUBLESHOOT ) choice=$(display_troubleshooting_menu) ;;
197
FILE_BUG ) choice=$(display_filebug_menu) ;;
198
RESTART_X ) with_gdm="restart"; break ;;
200
## Reconfigure Menu ##
201
DEFAULT_CONFIG ) choice="RECONFIGURE"; default_config ;;
202
RUN_XORGCONF ) choice="RECONFIGURE"; run_xorgconf ;;
203
SELECT_BACKUP ) choice="RECONFIGURE"; ;;
205
## Troubleshooting Menu ##
206
VIEW_XORG_LOG ) choice="TROUBLESHOOT"; view_xorg_log ;;
207
VIEW_GDM_LOG ) choice="TROUBLESHOOT"; view_gdm_log ;;
208
VERIFY_XORGCONF ) choice="TROUBLESHOOT"; verify_xorgconf ;;
209
EDIT_CONFIG ) choice="TROUBLESHOOT"; edit_config ;;
210
SAVE_CONFIG_LOGS ) choice="TROUBLESHOOT"; save_config_logs ;;
211
EXIT_TO_CONSOLE ) with_gdm=""; break ;;
214
*) choice=$(display_main_menu) || break ;;
218
if [ "x$with_gdm" = "xwith-gdm" ]; then
219
XORGCONFIG="/etc/X11/xorg.conf"
220
elif [ "x$with_gdm" = "xlow-res" ]; then
221
XORGCONFIG=${xorg_conf}
222
elif [ "x$with_gdm" = "xrestart" ]; then
229
start gdm XORGCONFIG=$XORGCONFIG | \
230
zenity --progress --pulsate --text "$(gettext 'Stand by one minute while the display restarts...')"