| 1 |
#!/bin/sh |
| 2 |
# |
| 3 |
# guess-helper |
| 4 |
# Copyright (C) 2004 Tobias Grimm <[email protected]> |
| 5 |
# |
| 6 |
# $Id: guess-helper 925 2010-01-24 11:40:38Z tiber $ |
| 7 |
# |
| 8 |
|
| 9 |
# prepare to use gettext, if installed: |
| 10 |
if [ -x /usr/bin/gettext ] |
| 11 |
then |
| 12 |
export TEXTDOMAIN=guess-helper |
| 13 |
echo="gettext -s" |
| 14 |
else |
| 15 |
echo="echo" |
| 16 |
fi |
| 17 |
|
| 18 |
# clear console window and print header line |
| 19 |
ClearScreen () |
| 20 |
{ |
| 21 |
clear |
| 22 |
echo |
| 23 |
echo guess-helper |
| 24 |
echo ------------ |
| 25 |
echo |
| 26 |
} |
| 27 |
|
| 28 |
# AskQuestion "Do you like Debian?" Y n > Do you like Debian? [Y/n] |
| 29 |
AskQuestion () |
| 30 |
{ |
| 31 |
if [ -x /usr/bin/gettext ] |
| 32 |
then |
| 33 |
question=`gettext "$1"` |
| 34 |
else |
| 35 |
question=$1 |
| 36 |
fi |
| 37 |
|
| 38 |
shift |
| 39 |
|
| 40 |
answers="" |
| 41 |
for answer in $* |
| 42 |
do |
| 43 |
if [ -x /usr/bin/gettext ] |
| 44 |
then |
| 45 |
answer=`gettext "$answer"` |
| 46 |
fi |
| 47 |
answers="$answers $answer" |
| 48 |
done |
| 49 |
|
| 50 |
choices="" |
| 51 |
for answer in $answers |
| 52 |
do |
| 53 |
if [ "$choices" = "" ] |
| 54 |
then |
| 55 |
choices="[$answer" |
| 56 |
else |
| 57 |
choices="$choices/$answer" |
| 58 |
fi |
| 59 |
done |
| 60 |
choices="$choices]" |
| 61 |
|
| 62 |
answers=`$echo $answers | tr '[:lower:]' '[:upper:]'` |
| 63 |
|
| 64 |
result=0 |
| 65 |
|
| 66 |
while [ $result -eq 0 ] |
| 67 |
do |
| 68 |
echo -n "$question" "$choices " |
| 69 |
read input |
| 70 |
|
| 71 |
if [ "$input" = "" ] |
| 72 |
then |
| 73 |
result=1 |
| 74 |
else |
| 75 |
input=`echo $input | tr '[:lower:]' '[:upper:]'` |
| 76 |
i=1 |
| 77 |
for answer in $answers |
| 78 |
do |
| 79 |
if [ "$answer" = "$input" ] |
| 80 |
then |
| 81 |
result=$i |
| 82 |
fi |
| 83 |
i=`expr $i + 1` |
| 84 |
done |
| 85 |
fi |
| 86 |
done |
| 87 |
|
| 88 |
return $result |
| 89 |
} |
| 90 |
|
| 91 |
# Translate and print text lines |
| 92 |
EchoTextLines () |
| 93 |
{ |
| 94 |
textLines="" |
| 95 |
|
| 96 |
while [ "$1" ] |
| 97 |
do |
| 98 |
textLines="$textLines$1" |
| 99 |
shift |
| 100 |
done |
| 101 |
|
| 102 |
$echo -ne "$textLines" |
| 103 |
} |
| 104 |
|
| 105 |
# show next wakeup time settings and ask for reboot |
| 106 |
ShowBiosSettings () |
| 107 |
{ |
| 108 |
ClearScreen |
| 109 |
EchoTextLines \ |
| 110 |
"On the next reboot, please enter the BIOS settings and change\n" \ |
| 111 |
"the wakeup time settings to the following values:\n" |
| 112 |
echo |
| 113 |
$echo -n "Day = " ; echo "$1" |
| 114 |
$echo -n "Hour = " ; echo "$2" |
| 115 |
$echo -n "Minute = " ; echo "$3" |
| 116 |
$echo -n "Second = " ; echo "$4" |
| 117 |
if [ $5 -eq 1 ] |
| 118 |
then |
| 119 |
$echo "Enabled = Yes" |
| 120 |
else |
| 121 |
$echo "Enabled = No" |
| 122 |
fi |
| 123 |
echo |
| 124 |
AskQuestion "Restart or Abort?" "A" "r" |
| 125 |
if [ $? -eq 2 ] |
| 126 |
then |
| 127 |
echo |
| 128 |
EchoTextLines \ |
| 129 |
"After changing the wakeup time in the BIOS settings and rebooting the PC,\n"\ |
| 130 |
"please run this script again (PC will reboot in 10 seconds...)\n" |
| 131 |
sleep 10 |
| 132 |
shutdown -r now |
| 133 |
exit 0 |
| 134 |
else |
| 135 |
echo |
| 136 |
$echo "Script aborted !!!" |
| 137 |
echo |
| 138 |
exit 0 |
| 139 |
fi |
| 140 |
} |
| 141 |
|
| 142 |
ReadNvram () |
| 143 |
{ |
| 144 |
cat_nvram $catOptions > ~/guess-directisa/$1 2>~/guess-directisa/cat_nvram.log |
| 145 |
[ -c /dev/nvram ] && \ |
| 146 |
cat /dev/nvram > ~/guess-nvram-module/$1 2>~/guess-nvram-module/cat.log |
| 147 |
if [ ! -s ~/guess-directisa/$1 ] && [ ! -s ~/guess-nvram-module/$1 ] ; then |
| 148 |
EchoTextLines\ |
| 149 |
"cat_nvram and cat /dev/nvram failed.\n" |
| 150 |
"Please check the cat_nvram.log for the details, fix the errors and run\n" |
| 151 |
"guess-helper again.\n" |
| 152 |
# if they exist, they are empty. Remove them. |
| 153 |
rm -fr ~/guess-directisa/$1 ~/guess-nvram-module/$1 |
| 154 |
exit 1 |
| 155 |
fi |
| 156 |
} |
| 157 |
|
| 158 |
step0file=guess-helper.conf |
| 159 |
step1file=31.23.59.59+ |
| 160 |
step2file=11.12.13.14+ |
| 161 |
step3file=01.00.00.00+ |
| 162 |
step4file=01.00.00.00- |
| 163 |
|
| 164 |
# check for needed binaries |
| 165 |
if ! (which cat_nvram >/dev/null && \ |
| 166 |
which cat >/dev/null && \ |
| 167 |
which guess >/dev/null ) ; then |
| 168 |
EchoTextLines \ |
| 169 |
"Please check that the tools cat_nvram, cat and guess are installed.\n\n"\ |
| 170 |
"guess-helper aborted!\n" |
| 171 |
exit 1 |
| 172 |
fi |
| 173 |
|
| 174 |
if [ ! -f ~/guess-directisa/$step0file ] |
| 175 |
then |
| 176 |
ClearScreen |
| 177 |
EchoTextLines \ |
| 178 |
"The aim of this script is to help you figuring out the addresses of the\n"\ |
| 179 |
"wakeup time in the NVRAM of your PC. You will have to do this only,\n"\ |
| 180 |
"if your mainboard couldn't be detected by nvram-wakeup.\n"\ |
| 181 |
"\n"\ |
| 182 |
"In several steps it will be necessary to reboot the PC, change the\n"\ |
| 183 |
"wakeup time in the BIOS and then run guess-helper again.\n"\ |
| 184 |
"\n"\ |
| 185 |
"This script will create several temporary files and a config file for\n"\ |
| 186 |
"nvram-wakeup. This will be done in your home directory.\n" |
| 187 |
echo |
| 188 |
AskQuestion "Continue with the first step of the nvram-wakeup address detection?" "N" "y" |
| 189 |
[ $? -eq 1 ] && exit |
| 190 |
ClearScreen |
| 191 |
mkdir -p ~/guess-directisa |
| 192 |
EchoTextLines \ |
| 193 |
"Please select the chipset of your Board -\n"\ |
| 194 |
" [U] Unknown (i.e, disable access to upper nvram);\n"\ |
| 195 |
" [I] Intel;\n"\ |
| 196 |
" [V] VIA VT82Cxxx (xxx=686A,686B,596,...), nVidia nForce2, ATI RADEON 9100 IGP; \n"\ |
| 197 |
" [3] VIA VT8233/35/37;\n"\ |
| 198 |
" [D] DS1685\n" |
| 199 |
|
| 200 |
AskQuestion "Select one of the above:" "U" "i" "v" "3" "d" |
| 201 |
case $? in |
| 202 |
2) |
| 203 |
catOptions="INTEL" |
| 204 |
;; |
| 205 |
3) |
| 206 |
catOptions="VT82Cxxx" |
| 207 |
;; |
| 208 |
4) |
| 209 |
catOptions="VT8235_37" |
| 210 |
;; |
| 211 |
5) |
| 212 |
catOptions="DS1685" |
| 213 |
;; |
| 214 |
esac |
| 215 |
echo catOptions=\"$catOptions\" >~/guess-directisa/$step0file |
| 216 |
ShowBiosSettings 31 23 59 59 1 |
| 217 |
else |
| 218 |
. ~/guess-directisa/$step0file |
| 219 |
if [ ! -f ~/guess-directisa/$step1file ] |
| 220 |
then |
| 221 |
[ -c /dev/nvram ] && mkdir -p ~/guess-nvram-module |
| 222 |
ReadNvram $step1file |
| 223 |
ShowBiosSettings 11 12 13 14 1 |
| 224 |
else |
| 225 |
if [ ! -f ~/guess-directisa/$step2file ] |
| 226 |
then |
| 227 |
ReadNvram $step2file |
| 228 |
ShowBiosSettings 01 00 00 00 1 |
| 229 |
else |
| 230 |
if [ ! -f ~/guess-directisa/$step3file ] |
| 231 |
then |
| 232 |
ReadNvram $step3file |
| 233 |
ShowBiosSettings 01 00 00 00 0 |
| 234 |
else |
| 235 |
if [ ! -f ~/guess-directisa/$step4file ] |
| 236 |
then |
| 237 |
ReadNvram $step4file |
| 238 |
fi |
| 239 |
|
| 240 |
ClearScreen |
| 241 |
|
| 242 |
cd ~/guess-directisa |
| 243 |
guess > nvram-wakeup.conf 2> guess-error.log |
| 244 |
[ "$catOptions" = "" ] || echo upper_method = $catOptions >> nvram-wakeup.conf |
| 245 |
if [ -d ~/guess-nvram-module ] ; then |
| 246 |
cd ~/guess-nvram-module |
| 247 |
guess > nvram-wakeup.conf 2> guess-error.log |
| 248 |
cd .. |
| 249 |
fi |
| 250 |
|
| 251 |
EchoTextLines \ |
| 252 |
"The nvram-wakeup address detection is finished now.\n"\ |
| 253 |
"If everything went well, you will find the detected nvram-wakeup\n"\ |
| 254 |
"settings in the file ~/guess-directisa/nvram-wakeup.conf. This file\n"\ |
| 255 |
"has been generated using the 'directisa' access method.\n" |
| 256 |
[ -c /dev/nvram ] && EchoTextLines \ |
| 257 |
"In the directory ~/guess-nvram-module you will find the results using\n"\ |
| 258 |
"the 'nvram-kernel-module' access method. It's up to you to decide,\n"\ |
| 259 |
"what access method worked.\n" |
| 260 |
EchoTextLines \ |
| 261 |
"Check the files nvram-wakeup.conf and guess-error.log to see if\n"\ |
| 262 |
"everything went well. In order to use the generated conf file, you\n"\ |
| 263 |
"have to pass it as a command line parameter with the option -C to\n"\ |
| 264 |
"nvram-wakeup. Before doing this, you should copy it to /etc.\n"\ |
| 265 |
"If the settings in your nvram-wakup.conf seem to work, please submit\n"\ |
| 266 |
"this file to the mainboard tracker:\n" |
| 267 |
echo |
| 268 |
echo "https://sourceforge.net/tracker/?group_id=35022&atid=412959" |
| 269 |
echo |
| 270 |
$echo "By doing so, you are helping to keep nvram-wakeup support more boards." |
| 271 |
fi |
| 272 |
fi |
| 273 |
fi |
| 274 |
fi |