Skip to content

Commit

Permalink
os_prober code Added
Browse files Browse the repository at this point in the history
- Addresses #266
  • Loading branch information
Xmetalfanx committed Sep 6, 2023
1 parent e285472 commit d34dc42
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
2 changes: 1 addition & 1 deletion functions/menus/f_mainMenus.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ main_menu_items=(
8 '[Sub-Menu] Cleanup Linux System'
C 'Install Multimedia Codecs'
I 'Display Info about current install'
O '[Sub-menu] Default Grub related Submenu'
O '[Sub-Menu] Default Grub related Submenu'
R "Check/Install Third Party Repositories"
S '[Sub-Menu] Install Software'
T '[Sub-Menu] Install Theming'
Expand Down
55 changes: 41 additions & 14 deletions functions/universal/f_osprober.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,63 @@ function backupDefaultGrubConfig() {
# Backs up any original backup file ... maybe overkill but just in case it's there and BECAUSE this deals with the boot loader... I want to back it up
backupOriginalGrubBackup

# should i put a check for an existing backup file?
fancy_message action "Backing up default grub config file" && sudo cp ${defaultGrubConfig} ${defaultGrubConfigBackup} && fancy_message info "Default grub config file backed up" || fancy_message warn "Issue occured backing up default grub config file"
[ -f ${defaultGrubConfig} ] && fancy_message action "Backing up default grub config file" && sudo cp ${defaultGrubConfig} ${defaultGrubConfigBackup} && fancy_message info "Default grub config file backed up" || fancy_message warn "Issue occured backing up default grub config file"

## pass or fail there should be a pause... no need to have two, above
userPrompt
}

# Main Restore function
function restoreDefaultGrubConfig() {

[ -f "${defaultGrubConfigBackup}" ] && fancy_message action "Restoring default grub config file" && userPrompt && cp ${defaultGrubConfigBackup} ${defaultGrubConfig} && fancy_message info "Default Grub config file is now restored" || fancy_message warn "Default Grub config backup file was not found; therefore, can not be restored"
fancy_message action "Restoring default grub config file" && userPrompt

}
[ -f "${defaultGrubConfigBackup}" ] && echo -e "Restoring ${defaultGrubConfigBackup} ${defaultGrubConfig}" && sudo cp ${defaultGrubConfigBackup} ${defaultGrubConfig} && fancy_message info "Default Grub config file is now restored" || fancy_message warn "Default Grub config backup file was not found; therefore, can not be restored"

userPrompt

}

# End of Backup and Restore functions
##########################################################################
function displayGrubFileContent() {
# debugging
grubfileContent=$(grep "GRUB_DISABLE_OS_PROBER" /etc/default/grub)

function detectOSProberStatus() {
unset osProberStatus

fancy_message action "Detecting status of OS_PROBER"
# idea: if it starts with GRUB_DISABLE_OS_PROBER (shouldn't match "#GRUB_DISABLE_OS_PROBER") and contains the word true
grep -E "^GRUB_DISABLE_OS_PROBER\|TRUE" ${defaultGrubConfig}
echo -e "Default Grub file content:\t ${grubfileContent}"
echo -e "\n Remember if a line with False OR there is no output then os_prober IS enabled"
echo -e "If this is empty that may mean there is NO GRUB_DISABLE_OS_PROBER line of any sort in the default grub file"
userPrompt
# end debugging

# 0 = disabled
osProberResult=$?
}

if [ "${osProberResult}" -eq "0" ]; then
function displayOSProberStatus() {
if [[ ${osproberLine} == GRUB_DISABLE_OS_PROBER* ]] && [[ ${osproberLine} == *"true"* ]]; then
fancy_message info "os-prober is disabled"
osProberStatus="disabled"
else
fancy_message info "os-prober is enabled"
osProberStatus="enabled"

fi

#displayGrubFileContent
}

function detectOSProberStatus() {
unset osProberStatus

fancy_message action "Detecting status of OS_PROBER"

# idea: if it starts with GRUB_DISABLE_OS_PROBER (shouldn't match "#GRUB_DISABLE_OS_PROBER") and contains the word true
osproberLine=$(grep -E "^GRUB_DISABLE_OS_PROBER" ${defaultGrubConfig} )

# debugging
# echo -e "osproberLine:\t${osproberLine}" && userPrompt
# end debugging

displayOSProberStatus

userPrompt
}
Expand All @@ -66,5 +88,10 @@ function enableosProber() {
# sed '/xmetal/c\THIS WAS A XMETAL LINE' test.txt;

detectOSProberStatus
[ ${osProberStatus} == "disabled" ] && fancy_message action "Enabling os-prober to detect other OSs" && backupDefaultGrubConfig && sed 'GRUB_DISABLE_OS_PROBER=true/c\GRUB_DISABLE_OSPROBER=false' ${defaultGrubConfig} && "os-prober successfully enabled" || fancy_message warn "not able to enable, os-prober"

# if disabled
# 1. Backup Grub config file in /etc/defaults
[ ${osProberStatus} == "disabled" ] && fancy_message action "Enabling os-prober to detect other OSs" && backupDefaultGrubConfig && sudo sed -i '/GRUB_DISABLE_OS_PROBER/s/^/#/' ${defaultGrubConfig} && fancy_message info "os-prober successfully enabled" || fancy_message warn "not able to enable, os-prober"

userPrompt
}

0 comments on commit d34dc42

Please sign in to comment.