]> code.delx.au - refind/blob - install.sh
Refinements to installation script.
[refind] / install.sh
1 #!/bin/bash
2 #
3 # Linux/MacOS X script to install rEFInd
4 #
5 # Usage:
6 #
7 # ./install.sh [options]
8 #
9 # options include:
10 # "--esp" to install to the ESP rather than to the system's root
11 # filesystem. This is the default on Linux
12 # "--usedefault {devicefile}" to install as default
13 # (/EFI/BOOT/BOOTX64.EFI and similar) to the specified device
14 # (/dev/sdd1 or whatever) without registering with the NVRAM.
15 # "--drivers" to install drivers along with regular files
16 # "--shim {shimfile}" to install a shim.efi file for Secure Boot
17 # "--localkeys" to re-sign x86-64 binaries with a locally-generated key
18 #
19 # The "esp" option is valid only on Mac OS X; it causes
20 # installation to the EFI System Partition (ESP) rather than
21 # to the current OS X boot partition. Under Linux, this script
22 # installs to the ESP by default.
23 #
24 # This program is copyright (c) 2012 by Roderick W. Smith
25 # It is released under the terms of the GNU GPL, version 3,
26 # a copy of which should be included in the file COPYING.txt.
27 #
28 # Revision history:
29 #
30 # 0.5.1 -- Added --shim & --localkeys options
31 # 0.5.0 -- Added --usedefault & --drivers options & changed "esp" option to "--esp"
32 # 0.4.5 -- Fixed check for rEFItBlesser in OS X
33 # 0.4.2 -- Added notice about BIOS-based OSes & made NVRAM changes in Linux smarter
34 # 0.4.1 -- Added check for rEFItBlesser in OS X
35 # 0.3.3.1 -- Fixed OS X 10.7 bug; also works as make target
36 # 0.3.2.1 -- Check for presence of source files; aborts if not present
37 # 0.3.2 -- Initial version
38 #
39 # Note: install.sh version numbers match those of the rEFInd package
40 # with which they first appeared.
41
42 TargetDir=/EFI/refind
43 EtcKeysDir=/etc/refind.d/keys
44 LocalKeysBase="refind_local"
45 ShimSource="none"
46 TargetX64="refind_x64.efi"
47 TargetIA32="refind_ia32.efi"
48 LocalKeys=0
49 DeleteRefindDir=0
50
51 #
52 # Functions used by both OS X and Linux....
53 #
54
55 GetParams() {
56 InstallToEspOnMac=0
57 InstallDrivers=0
58 while [[ $# -gt 0 ]]; do
59 case $1 in
60 --esp | --ESP) InstallToEspOnMac=1
61 ;;
62 --usedefault) TargetDir=/EFI/BOOT
63 TargetPart=$2
64 TargetX64="bootx64.efi"
65 TargetIA32="bootia32.efi"
66 shift
67 ;;
68 --shim) ShimSource=$2
69 shift
70 ;;
71 --drivers) InstallDrivers=1
72 ;;
73 --localkeys) LocalKeys=1
74 ;;
75 * ) echo "Usage: $0 [--esp | --usedefault {device-file}] [--drivers] "
76 echo " [--localkeys] [--shim {shim-filename}]"
77 echo "Aborting!"
78 exit 1
79 esac
80 shift
81 done
82 if [[ $InstallToEspOnMac == 1 && $TargetDir == '/EFI/BOOT' ]] ; then
83 echo "You may use --esp OR --usedefault, but not both! Aborting!"
84 exit 1
85 fi
86 # exit 1
87 } # GetParams()
88
89 # Abort if the rEFInd files can't be found.
90 # Also sets $ConfFile to point to the configuration file,
91 # $IconsDir to point to the icons directory, and
92 # $ShimSource to the source of the shim.efi file (if necessary).
93 CheckForFiles() {
94 # Note: This check is satisfied if EITHER the 32- or the 64-bit version
95 # is found, even on the wrong platform. This is because the platform
96 # hasn't yet been determined. This could obviously be improved, but it
97 # would mean restructuring lots more code....
98 if [[ ! -f $RefindDir/refind_ia32.efi && ! -f $RefindDir/refind_x64.efi ]] ; then
99 echo "The rEFInd binary file is missing! Aborting installation!"
100 exit 1
101 fi
102
103 if [[ -f $RefindDir/refind.conf-sample ]] ; then
104 ConfFile=$RefindDir/refind.conf-sample
105 elif [[ -f $ThisDir/refind.conf-sample ]] ; then
106 ConfFile=$ThisDir/refind.conf-sample
107 else
108 echo "The sample configuration file is missing! Aborting installation!"
109 exit 1
110 fi
111
112 if [[ -d $RefindDir/icons ]] ; then
113 IconsDir=$RefindDir/icons
114 elif [[ -d $ThisDir/icons ]] ; then
115 IconsDir=$ThisDir/icons
116 else
117 echo "The icons directory is missing! Aborting installation!"
118 exit 1
119 fi
120
121 if [[ $ShimSource != "none" ]] ; then
122 if [[ -f $ShimSource ]] ; then
123 TargetX64="grubx64.efi"
124 MokManagerSource=`dirname $ShimSource`/MokManager.efi
125 else
126 echo "The specified shim file, $ShimSource, doesn't exist!"
127 echo "Aborting installation!"
128 exit 1
129 fi
130 fi
131 } # CheckForFiles()
132
133 # Helper for CopyRefindFiles; copies shim files (including MokManager, if it's
134 # available) to target.
135 CopyShimFiles() {
136 cp $ShimSource $InstallDir/$TargetDir/$TargetShim
137 if [[ $? != 0 ]] ; then
138 Problems=1
139 fi
140 if [[ -f $MokManagerSource ]] ; then
141 cp $MokManagerSource $InstallDir/$TargetDir/
142 fi
143 if [[ $? != 0 ]] ; then
144 Problems=1
145 fi
146 } # CopyShimFiles()
147
148 # Copy the public keys to the installation medium
149 CopyKeys() {
150 if [[ $LocalKeys == 1 ]] ; then
151 cp $EtcKeysDir/$LocalKeysBase.cer $InstallDir/$TargetDir
152 cp $EtcKeysDir/$LocalKeysBase.crt $InstallDir/$TargetDir
153 else
154 cp $ThisDir/refind.cer $InstallDir/$TargetDir
155 cp $ThisDir/refind.crt $InstallDir/$TargetDir
156 fi
157 } # CopyKeys()
158
159 # Copy the rEFInd files to the ESP or OS X root partition.
160 # Sets Problems=1 if any critical commands fail.
161 CopyRefindFiles() {
162 mkdir -p $InstallDir/$TargetDir &> /dev/null
163 if [[ $TargetDir == '/EFI/BOOT' ]] ; then
164 cp $RefindDir/refind_ia32.efi $InstallDir/$TargetDir/$TargetIA32 2> /dev/null
165 if [[ $? != 0 ]] ; then
166 echo "Note: IA32 (x86) binary not installed!"
167 fi
168 cp $RefindDir/refind_x64.efi $InstallDir/$TargetDir/$TargetX64 2> /dev/null
169 if [[ $? != 0 ]] ; then
170 Problems=1
171 fi
172 if [[ $ShimSource != "none" ]] ; then
173 TargetShim="bootx64.efi"
174 CopyShimFiles
175 fi
176 if [[ $InstallDrivers == 1 ]] ; then
177 cp -r $RefindDir/drivers_* $InstallDir/$TargetDir/ 2> /dev/null
178 cp -r $ThisDir/drivers_* $InstallDir/$TargetDir/ 2> /dev/null
179 fi
180 Refind=""
181 CopyKeys
182 elif [[ $Platform == 'EFI32' ]] ; then
183 cp $RefindDir/refind_ia32.efi $InstallDir/$TargetDir/$TargetIA32
184 if [[ $? != 0 ]] ; then
185 Problems=1
186 fi
187 if [[ $InstallDrivers == 1 ]] ; then
188 mkdir -p $InstallDir/$TargetDir/drivers_ia32
189 cp $RefindDir/drivers_ia32/*_ia32.efi $InstallDir/$TargetDir/drivers_ia32/ 2> /dev/null
190 cp $ThisDir/drivers_ia32/*_ia32.efi $InstallDir/$TargetDir/drivers_ia32/ 2> /dev/null
191 fi
192 Refind="refind_ia32.efi"
193 elif [[ $Platform == 'EFI64' ]] ; then
194 cp $RefindDir/refind_x64.efi $InstallDir/$TargetDir/$TargetX64
195 if [[ $? != 0 ]] ; then
196 Problems=1
197 fi
198 if [[ $InstallDrivers == 1 ]] ; then
199 mkdir -p $InstallDir/$TargetDir/drivers_x64
200 cp $RefindDir/drivers_x64/*_x64.efi $InstallDir/$TargetDir/drivers_x64/ 2> /dev/null
201 cp $ThisDir/drivers_x64/*_x64.efi $InstallDir/$TargetDir/drivers_x64/ 2> /dev/null
202 fi
203 Refind="refind_x64.efi"
204 CopyKeys
205 if [[ $ShimSource != "none" ]] ; then
206 TargetShim=`basename $ShimSource`
207 CopyShimFiles
208 Refind=$TargetShim
209 if [[ $LocalKeys == 0 ]] ; then
210 echo "Storing copies of rEFInd Secure Boot public keys in $EtcKeysDir"
211 mkdir -p $EtcKeysDir
212 cp $ThisDir/refind.cer $EtcKeysDir
213 cp $ThisDir/refind.crt $EtcKeysDir
214 fi
215 fi
216 else
217 echo "Unknown platform! Aborting!"
218 exit 1
219 fi
220 echo "Copied rEFInd binary files"
221 echo ""
222 if [[ -d $InstallDir/$TargetDir/icons ]] ; then
223 rm -rf $InstallDir/$TargetDir/icons-backup &> /dev/null
224 mv -f $InstallDir/$TargetDir/icons $InstallDir/$TargetDir/icons-backup
225 echo "Notice: Backed up existing icons directory as icons-backup."
226 fi
227 cp -r $IconsDir $InstallDir/$TargetDir
228 if [[ $? != 0 ]] ; then
229 Problems=1
230 fi
231 if [[ -f $InstallDir/$TargetDir/refind.conf ]] ; then
232 echo "Existing refind.conf file found; copying sample file as refind.conf-sample"
233 echo "to avoid overwriting your customizations."
234 echo ""
235 cp -f $ConfFile $InstallDir/$TargetDir
236 if [[ $? != 0 ]] ; then
237 Problems=1
238 fi
239 else
240 echo "Copying sample configuration file as refind.conf; edit this file to configure"
241 echo "rEFInd."
242 echo ""
243 cp -f $ConfFile $InstallDir/$TargetDir/refind.conf
244 if [[ $? != 0 ]] ; then
245 Problems=1
246 fi
247 fi
248 if [[ $DeleteRefindDir == 1 ]] ; then
249 echo "Deleting the temporary directory $RefindDir"
250 rm -r $RefindDir
251 fi
252 } # CopyRefindFiles()
253
254 # Mount the partition the user specified with the --usedefault option
255 MountDefaultTarget() {
256 InstallDir=/tmp/refind_install
257 mkdir -p $InstallDir
258 if [[ $OSName == 'Darwin' ]] ; then
259 mount -t msdos $TargetPart $InstallDir
260 elif [[ $OSName == 'Linux' ]] ; then
261 mount -t vfat $TargetPart $InstallDir
262 fi
263 if [[ $? != 0 ]] ; then
264 echo "Couldn't mount $TargetPart ! Aborting!"
265 rmdir $InstallDir
266 exit 1
267 fi
268 UnmountEsp=1
269 } # MountDefaultTarget()
270
271 #
272 # A series of OS X support functions....
273 #
274
275 # Mount the ESP at /Volumes/ESP or determine its current mount
276 # point.
277 # Sets InstallDir to the ESP mount point
278 # Sets UnmountEsp if we mounted it
279 MountOSXESP() {
280 # Identify the ESP. Note: This returns the FIRST ESP found;
281 # if the system has multiple disks, this could be wrong!
282 Temp=`diskutil list | grep " EFI "`
283 Esp=/dev/`echo $Temp | cut -f 5 -d ' '`
284 # If the ESP is mounted, use its current mount point....
285 Temp=`df | grep $Esp`
286 InstallDir=`echo $Temp | cut -f 6 -d ' '`
287 if [[ $InstallDir == '' ]] ; then
288 mkdir /Volumes/ESP &> /dev/null
289 mount -t msdos $Esp /Volumes/ESP
290 if [[ $? != 0 ]] ; then
291 echo "Unable to mount ESP! Aborting!\n"
292 exit 1
293 fi
294 UnmountEsp=1
295 InstallDir="/Volumes/ESP"
296 fi
297 } # MountOSXESP()
298
299 # Control the OS X installation.
300 # Sets Problems=1 if problems found during the installation.
301 InstallOnOSX() {
302 echo "Installing rEFInd on OS X...."
303 if [[ $TargetDir == "/EFI/BOOT" ]] ; then
304 MountDefaultTarget
305 elif [[ $InstallToEspOnMac == "1" ]] ; then
306 MountOSXESP
307 else
308 InstallDir="/"
309 fi
310 echo "Installing rEFInd to the partition mounted at '$InstallDir'"
311 Platform=`ioreg -l -p IODeviceTree | grep firmware-abi | cut -d "\"" -f 4`
312 CopyRefindFiles
313 if [[ $InstallToEspOnMac == "1" ]] ; then
314 bless --mount $InstallDir --setBoot --file $InstallDir/$TargetDir/$Refind
315 elif [[ $TargetDir != "/EFI/BOOT" ]] ; then
316 bless --setBoot --folder $InstallDir/$TargetDir --file $InstallDir/$TargetDir/$Refind
317 fi
318 if [[ $? != 0 ]] ; then
319 Problems=1
320 fi
321 if [[ -f /Library/StartupItems/rEFItBlesser || -d /Library/StartupItems/rEFItBlesser ]] ; then
322 echo
323 echo "/Library/StartupItems/rEFItBlesser found!"
324 echo "This program is part of rEFIt, and will cause rEFInd to fail to work after"
325 echo -n "its first boot. Do you want to remove rEFItBlesser (Y/N)? "
326 read YesNo
327 if [[ $YesNo == "Y" || $YesNo == "y" ]] ; then
328 echo "Deleting /Library/StartupItems/rEFItBlesser..."
329 rm -r /Library/StartupItems/rEFItBlesser
330 else
331 echo "Not deleting rEFItBlesser."
332 fi
333 fi
334 echo
335 echo "WARNING: If you have an Advanced Format disk, *DO NOT* attempt to check the"
336 echo "bless status with 'bless --info', since this is known to cause disk corruption"
337 echo "on some systems!!"
338 echo
339 } # InstallOnOSX()
340
341
342 #
343 # Now a series of Linux support functions....
344 #
345
346 # Check for evidence that we're running in Secure Boot mode. If so, and if
347 # appropriate options haven't been set, warn the user and offer to abort.
348 # If we're NOT in Secure Boot mode but the user HAS specified the --shim
349 # or --localkeys option, warn the user and offer to abort.
350 CheckSecureBoot() {
351 VarFile=`ls -d /sys/firmware/efi/vars/SecureBoot* 2> /dev/null`
352 if [[ -n $VarFile && $TargetDir != '/EFI/BOOT' && $ShimSource == "none" ]] ; then
353 echo ""
354 echo "CAUTION: The computer seems to have been booted with Secure Boot active, but"
355 echo "you haven't specified a valid shim.efi file source. The resulting installation"
356 echo "will not boot unless you disable Secure Boot. You may continue, but you should"
357 echo "consider using --shim to specify a working shim.efi file. You can read more"
358 echo "about this topic at http://www.rodsbooks.com/refind/secureboot.html."
359 echo ""
360 echo -n "Do you want to proceed with installation (Y/N)? "
361 read ContYN
362 if [[ $ContYN == "Y" || $ContYN == "y" ]] ; then
363 echo "OK; continuing with the installation..."
364 else
365 exit 0
366 fi
367 fi
368
369 if [[ $ShimSource != "none" && ! -n $VarFile ]] ; then
370 echo ""
371 echo "You've specified installing using a shim.efi file, but your computer does not"
372 echo "appear to be running in Secure Boot mode. Although installing in this way"
373 echo "should work, it's unnecessarily complex. You may continue, but unless you"
374 echo "plan to enable Secure Boot, you should consider stopping and omitting the"
375 echo "--shim option. You can read more about this topic at"
376 echo "http://www.rodsbooks.com/refind/secureboot.html."
377 echo ""
378 echo -n "Do you want to proceed with installation (Y/N)? "
379 read ContYN
380 if [[ $ContYN == "Y" || $ContYN == "y" ]] ; then
381 echo "OK; continuing with the installation..."
382 else
383 exit 0
384 fi
385 fi
386
387 if [[ $LocalKeys != 0 && ! -n $VarFile ]] ; then
388 echo ""
389 echo "You've specified re-signing your rEFInd binaries with locally-generated keys,"
390 echo "but your computer does not appear to be running in Secure Boot mode. The"
391 echo "keys you generate will be useless unless you enable Secure Boot. You may"
392 echo "proceed with this installation, but before you do so, you may want to read"
393 echo "more about it at http://www.rodsbooks.com/refind/secureboot.html."
394 echo ""
395 echo -n "Do you want to proceed with installation (Y/N)? "
396 read ContYN
397 if [[ $ContYN == "Y" || $ContYN == "y" ]] ; then
398 echo "OK; continuing with the installation..."
399 else
400 exit 0
401 fi
402 fi
403
404 } # CheckSecureBoot()
405
406 # Check for the presence of locally-generated keys from a previous installation in
407 # $EtcKeysDir (/etc/refind.d/keys). If they're not present, generate them using
408 # openssl.
409 GenerateKeys() {
410 PrivateKey=$EtcKeysDir/$LocalKeysBase.key
411 CertKey=$EtcKeysDir/$LocalKeysBase.crt
412 DerKey=$EtcKeysDir/$LocalKeysBase.cer
413 OpenSSL=`which openssl 2> /dev/null`
414
415 # Do the work only if one or more of the necessary keys is missing
416 # TODO: Technically, we don't need the DerKey; but if it's missing and openssl
417 # is also missing, this will fail. This could be improved.
418 if [[ ! -f $PrivateKey || ! -f $CertKey || ! -f $DerKey ]] ; then
419 echo "Generating a fresh set of local keys...."
420 mkdir -p $EtcKeysDir
421 chmod 0700 $EtcKeysDir
422 if [[ ! -x $OpenSSL ]] ; then
423 echo "Can't find openssl, which is required to create your private signing keys!"
424 echo "Aborting!"
425 exit 1
426 fi
427 if [[ -f $PrivateKey ]] ; then
428 echo "Backing up existing $PrivateKey"
429 cp -f $PrivateKey $PrivateKey.backup 2> /dev/null
430 fi
431 if [[ -f $CertKey ]] ; then
432 echo "Backing up existing $CertKey"
433 cp -f $CertKey $CertKey.backup 2> /dev/null
434 fi
435 if [[ -f $DerKey ]] ; then
436 echo "Backing up existing $DerKey"
437 cp -f $DerKey $DerKey.backup 2> /dev/null
438 fi
439 $OpenSSL req -new -x509 -newkey rsa:2048 -keyout $PrivateKey -out $CertKey \
440 -nodes -days 3650 -subj "/CN=Locally-generated rEFInd key/"
441 $OpenSSL x509 -in $CertKey -out $DerKey -outform DER
442 chmod 0600 $PrivateKey
443 else
444 echo "Using existing local keys...."
445 fi
446 }
447
448 # Sign a single binary. Requires parameters:
449 # $1 = source file
450 # $2 = destination file
451 # Also assumes that the SBSign, PESign, UseSBSign, UsePESign, and various key variables are set
452 # appropriately.
453 # Aborts script on error
454 SignOneBinary() {
455 $SBSign --key $PrivateKey --cert $CertKey --output $2 $1
456 if [[ $? != 0 ]] ; then
457 echo "Problem signing the binary $1! Aborting!"
458 exit 1
459 fi
460 }
461
462 # Re-sign the x86-64 binaries with a locally-generated key, First look for appropriate
463 # key files in $EtcKeysDir. If they're present, use them to re-sign the binaries. If
464 # not, try to generate new keys and store them in $EtcKeysDir.
465 ReSignBinaries() {
466 SBSign=`which sbsign 2> /dev/null`
467 echo "Found sbsign at $SBSign"
468 TempDir="/tmp/refind_local"
469 if [[ ! -x $SBSign ]] ; then
470 echo "Can't find sbsign, which is required to sign rEFInd with your own keys!"
471 echo "Aborting!"
472 exit 1
473 fi
474 GenerateKeys
475 mkdir -p $TempDir/drivers_x64
476 cp $RefindDir/refind.conf-sample $TempDir 2> /dev/null
477 cp $ThisDir/refind.conf-sample $TempDir 2> /dev/null
478 cp $RefindDir/refind_ia32.efi $TempDir
479 cp -a $RefindDir/drivers_ia32 $TempDir 2> /dev/null
480 cp -a $ThisDir/drivers_ia32 $TempDir 2> /dev/null
481 SignOneBinary $RefindDir/refind_x64.efi $ThisDir/refind_x64.efi
482 for Driver in `ls $RefindDir/drivers_x64/*.efi $ThisDir/drivers_x64/*.efi 2> /dev/null` ; do
483 TempName=`basename $Driver`
484 SignOneBinary $Driver $TempDir/drivers_x64/$TempName
485 done
486 RefindDir=$TempDir
487 DeleteRefindDir=1
488 }
489
490 # Identifies the ESP's location (/boot or /boot/efi); aborts if
491 # the ESP isn't mounted at either location.
492 # Sets InstallDir to the ESP mount point.
493 FindLinuxESP() {
494 EspLine=`df /boot/efi | grep boot`
495 InstallDir=`echo $EspLine | cut -d " " -f 6`
496 EspFilesystem=`grep $InstallDir /etc/mtab | cut -d " " -f 3`
497 if [[ $EspFilesystem != 'vfat' ]] ; then
498 echo "/boot/efi doesn't seem to be on a VFAT filesystem. The ESP must be mounted at"
499 echo "/boot or /boot/efi and it must be VFAT! Aborting!"
500 exit 1
501 fi
502 echo "ESP was found at $InstallDir using $EspFilesystem"
503 } # MountLinuxESP
504
505 # Uses efibootmgr to add an entry for rEFInd to the EFI's NVRAM.
506 # If this fails, sets Problems=1
507 AddBootEntry() {
508 InstallIt="0"
509 Efibootmgr=`which efibootmgr 2> /dev/null`
510 if [[ $Efibootmgr ]] ; then
511 modprobe efivars &> /dev/null
512 InstallDisk=`grep $InstallDir /etc/mtab | cut -d " " -f 1 | cut -c 1-8`
513 PartNum=`grep $InstallDir /etc/mtab | cut -d " " -f 1 | cut -c 9-10`
514 EntryFilename=$TargetDir/$Refind
515 EfiEntryFilename=`echo ${EntryFilename//\//\\\}`
516 EfiEntryFilename2=`echo ${EfiEntryFilename} | sed s/\\\\\\\\/\\\\\\\\\\\\\\\\/g`
517 ExistingEntry=`$Efibootmgr -v | grep $EfiEntryFilename2`
518 # NOTE: Below protects against duplicate entries, but only for non-Secure Boot
519 # installations.
520 # TODO: Improve to detect & protect against duplicating a Secure Boot entry.
521 if [[ $ExistingEntry && $ShimSource == "none" ]] ; then
522 ExistingEntryBootNum=`echo $ExistingEntry | cut -c 5-8`
523 FirstBoot=`$Efibootmgr | grep BootOrder | cut -c 12-15`
524 if [[ $ExistingEntryBootNum != $FirstBoot ]] ; then
525 echo "An existing rEFInd boot entry exists, but isn't set as the default boot"
526 echo "manager. The boot order is being adjusted to make rEFInd the default boot"
527 echo "manager. If this is NOT what you want, you should use efibootmgr to"
528 echo "manually adjust your EFI's boot order."
529 $Efibootmgr -b $ExistingEntryBootNum -B &> /dev/null
530 InstallIt="1"
531 fi
532 else
533 InstallIt="1"
534 fi
535 if [[ $InstallIt == "1" ]] ; then
536 echo "Installing it!"
537 $Efibootmgr -c -l $EfiEntryFilename -L rEFInd -d $InstallDisk -p $PartNum &> /dev/null
538 if [[ $? != 0 ]] ; then
539 EfibootmgrProblems=1
540 Problems=1
541 fi
542 fi
543 else
544 EfibootmgrProblems=1
545 Problems=1
546 fi
547 if [[ $EfibootmgrProblems ]] ; then
548 echo
549 echo "ALERT: There were problems running the efibootmgr program! You may need to"
550 echo "rename the $Refind binary to the default name (EFI/boot/bootx64.efi"
551 echo "on x86-64 systems or EFI/boot/bootia32.efi on x86 systems) to have it run!"
552 echo
553 fi
554 } # AddBootEntry()
555
556 # Controls rEFInd installation under Linux.
557 # Sets Problems=1 if something goes wrong.
558 InstallOnLinux() {
559 echo "Installing rEFInd on Linux...."
560 if [[ $TargetDir == "/EFI/BOOT" ]] ; then
561 MountDefaultTarget
562 else
563 FindLinuxESP
564 fi
565 CpuType=`uname -m`
566 if [[ $CpuType == 'x86_64' ]] ; then
567 Platform="EFI64"
568 if [[ $LocalKeys == 1 ]] ; then
569 ReSignBinaries
570 fi
571 elif [[ $CpuType == 'i386' || $CpuType == 'i486' || $CpuType == 'i586' || $CpuType == 'i686' ]] ; then
572 if [[ $ShimSource != "none" && $TargetDir != "/BOOT/EFI" ]] ; then
573 echo ""
574 echo "CAUTION: Neither rEFInd nor shim currently supports 32-bit systems, so you"
575 echo "should not use the --shim option to install on such systems. Aborting!"
576 echo ""
577 exit 1
578 fi
579 Platform="EFI32"
580 echo
581 echo "CAUTION: This Linux installation uses a 32-bit kernel. 32-bit EFI-based"
582 echo "computers are VERY RARE. If you've installed a 32-bit version of Linux"
583 echo "on a 64-bit computer, you should manually install the 64-bit version of"
584 echo "rEFInd. If you're installing on a Mac, you should do so from OS X. If"
585 echo "you're positive you want to continue with this installation, answer 'Y'"
586 echo "to the following question..."
587 echo
588 echo -n "Are you sure you want to continue (Y/N)? "
589 read ContYN
590 if [[ $ContYN == "Y" || $ContYN == "y" ]] ; then
591 echo "OK; continuing with the installation..."
592 else
593 exit 0
594 fi
595 else
596 echo "Unknown CPU type '$CpuType'; aborting!"
597 exit 1
598 fi
599 CheckSecureBoot
600 CopyRefindFiles
601 if [[ $TargetDir != "/EFI/BOOT" ]] ; then
602 AddBootEntry
603 fi
604 } # InstallOnLinux()
605
606 #
607 # The main part of the script. Sets a few environment variables,
608 # performs a few startup checks, and then calls functions to
609 # install under OS X or Linux, depending on the detected platform.
610 #
611
612 GetParams $@
613 OSName=`uname -s`
614 ThisDir="$( cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
615 RefindDir="$ThisDir/refind"
616 ThisScript="$ThisDir/`basename $0`"
617 if [[ `whoami` != "root" ]] ; then
618 echo "Not running as root; attempting to elevate privileges via sudo...."
619 sudo $ThisScript $1 $2 $3 $4 $5 $6
620 if [[ $? != 0 ]] ; then
621 echo "This script must be run as root (or using sudo). Exiting!"
622 exit 1
623 else
624 exit 0
625 fi
626 fi
627 CheckForFiles
628 if [[ $OSName == 'Darwin' ]] ; then
629 if [[ $ShimDir != "none" ]] ; then
630 echo "The --shim option is not supported on OS X! Exiting!"
631 exit 1
632 fi
633 if [[ $LocalKeys != 0 ]] ; then
634 echo "The --localkeys option is not supported on OS X! Exiting!"
635 exit 1
636 fi
637 InstallOnOSX $1
638 elif [[ $OSName == 'Linux' ]] ; then
639 InstallOnLinux
640 else
641 echo "Running on unknown OS; aborting!"
642 fi
643
644 if [[ $Problems ]] ; then
645 echo
646 echo "ALERT:"
647 echo "Installation has completed, but problems were detected. Review the output for"
648 echo "error messages and take corrective measures as necessary. You may need to"
649 echo "re-run this script or install manually before rEFInd will work."
650 echo
651 else
652 echo
653 echo "Installation has completed successfully."
654 echo
655 fi
656
657 if [[ $UnmountEsp ]] ; then
658 echo "Unmounting install dir"
659 umount $InstallDir
660 fi
661
662 if [[ $InstallDir == /tmp/refind_install ]] ; then
663 # sleep 5
664 rmdir $InstallDir
665 fi