Skip to content

Commit

Permalink
src/winusb: Support distros which uses grub2 as prefix name, fixes #94
Browse files Browse the repository at this point in the history
Refer: use grub2-install when possible by aaptel · Pull Request #99 · slacka/WinUSB <#99>
Original-patch-by: aaptel <https://github.com/aaptel>
Signed-off-by: 林博仁 <[email protected]>
  • Loading branch information
brlin-tw committed Jun 8, 2017
1 parent e207820 commit 0295b95
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions src/winusb
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,17 @@ init(){
source_fs_mountpoint="/media/winusb_source_$(date +%s)_$$"
target_fs_mountpoint="/media/winusb_target_$(date +%s)_$$"

# Commands that needs to be determined in runtime
# Parameters that needs to be determined in runtime
# due to different names in distributions
declare\
command_mkdosfs\
command_grubinstall
command_grubinstall\
name_grub_prefix

if ! check_runtime_dependencies\
command_mkdosfs\
command_grubinstall; then
command_grubinstall\
name_grub_prefix; then
exit 1
fi

Expand Down Expand Up @@ -191,7 +193,8 @@ init(){
install_bootloader_grub\
"${target_fs_mountpoint}"\
"${target_device}"\
"${command_grubinstall}"
"${command_grubinstall}"\
"${name_grub_prefix}"

current_state="finished"

Expand Down Expand Up @@ -312,9 +315,10 @@ process_commandline_parameters(){
}; declare -fr process_commandline_parameters;

check_runtime_dependencies(){
util_check_function_parameters_quantity 2 $#
util_check_function_parameters_quantity 3 $#
local -n command_mkdosfs_ref="$1"; shift
local -n command_grubinstall_ref="$1"
local -n command_grubinstall_ref="$1"; shift
local -n name_grub_prefix_ref="$1"

local result="unknown"

Expand Down Expand Up @@ -357,8 +361,10 @@ check_runtime_dependencies(){

if command -v 'grub-install' &> /dev/null; then
command_grubinstall_ref='grub-install'
name_grub_prefix_ref="grub"
elif command -v 'grub2-install' &> /dev/null; then
command_grubinstall_ref='grub2-install'
name_grub_prefix_ref="grub2"
else
echo_with_color red "${FUNCNAME[0]}: Error: grub-install or grub2-install command not found!" >&2
echo_with_color red "${FUNCNAME[0]}: Error: Please make sure that GNU GRUB is properly installed!" >&2
Expand Down Expand Up @@ -795,10 +801,11 @@ workaround_support_windows_7_uefi_boot(){
}; declare -fr workaround_support_windows_7_uefi_boot

install_bootloader_grub(){
util_check_function_parameters_quantity 3 "${#}"
util_check_function_parameters_quantity 4 "${#}"
local -r target_fs_mountpoint="${1}"; shift 1
local -r target_device="${1}"; shift 1
local -r command_grubinstall="${1}"
local -r command_grubinstall="${1}"; shift 1
local -r name_grub_prefix="${1}"

echo_with_color blue "Installing GRUB bootloader for legacy boot support..."
"${command_grubinstall}"\
Expand All @@ -807,7 +814,7 @@ install_bootloader_grub(){
--force "${target_device}"

echo_with_color blue "Installing grub.cfg..."
local -r grub_cfg="${target_fs_mountpoint}/grub/grub.cfg"
local -r grub_cfg="${target_fs_mountpoint}/${name_grub_prefix}/grub.cfg"
local -r target_fs_uuid=$(\
lsblk\
--output UUID\
Expand Down

0 comments on commit 0295b95

Please sign in to comment.