Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootloader switcher script added and consequential change to tab TOML file. #447

Closed
wants to merge 1 commit into from
Closed

Bootloader switcher script added and consequential change to tab TOML file. #447

wants to merge 1 commit into from

Conversation

fam007e
Copy link

@fam007e fam007e commented Sep 17, 2024

Type of Change

  • New feature
  • Bug fix
  • Documentation Update
  • Refactoring
  • Hotfix
  • Security patch
  • UI/UX improvement

Description

The Bootloader Switcher script provides functionality to switch between GRUB and systemd-boot bootloaders, offering automatic detection of the current bootloader, creating backups of the configurations, and restoring them when needed.

Key Features:

  • Detects current bootloader (GRUB or systemd-boot).
  • Switch between GRUB and systemd-boot with backups of current configurations.
  • Provides backup and restore options for both GRUB and systemd-boot.
  • User-friendly interactive menu for selecting actions (switching or restoring).
  • Handles bootloader installation for multiple distributions (Debian, Ubuntu, Arch, Fedora).

Consequential Change:

  • The tab_data TOML file has been updated to accommodate this new functionality and ensure seamless integration with the system.

Testing

  • Tested on Arch Linux for switching between GRUB and systemd-boot.
  • Verified backup and restore processes by restoring from previously created backups.
  • Ran script in interactive mode and tested all menu options (switching bootloaders, restoring backups).

Impact

This script simplifies managing bootloaders, reducing manual steps for installation, backup, and restoration. The impact includes better flexibility for users on multi-boot systems or those who want to switch between bootloaders easily.

Issue related to PR

Additional Information

No additional information at this time.

Checklist

  • My code adheres to the coding and style guidelines of the project.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no errors/warnings/merge conflicts.

@fam007e fam007e changed the title Bootloader switcher script added and consequential change to tab Bootloader switcher script added and consequential change to tab TOML file. Sep 17, 2024
@adamperkowski
Copy link
Collaborator

@fam007e I think you should rewrite the script yourself. Without using LLMs.

Comment on lines +17 to +25
detect_bootloader() {
if [ -d /boot/grub ]; then
printf "GRUB\n"
elif [ -d /boot/loader ]; then
printf "systemd-boot\n"
else
printf "Unknown\n"
fi
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be rewritten not to use printfs or echos.

Comment on lines +6 to +7
BACKUP_DIR="/boot/backup/bootloader"
TIMESTAMP=$(date +%Y%m%d-%H%M%S)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be in /boot/backup/bootloader. BOOT partitions are usually somewhat small.

Also not the best idea to have commands running here. Move this.

Comment on lines +44 to +66
restore_grub() {
if [ -z "$1" ]; then
printf "${RED}Please provide the backup file for GRUB restore.${RC}\n"
exit 1
fi

printf "${YELLOW}Restoring GRUB configuration from %s...${RC}\n" "$1"
$ESCALATION_TOOL tar -xzf "$1" -C /
grub-mkconfig -o /boot/grub/grub.cfg
printf "${GREEN}GRUB configuration restored.${RC}\n"
}

# Restore systemd-boot configuration
restore_systemd_boot() {
if [ -z "$1" ]; then
printf "${RED}Please provide the backup file for systemd-boot restore.${RC}\n"
exit 1
fi

printf "${YELLOW}Restoring systemd-boot configuration from %s...${RC}\n" "$1"
$ESCALATION_TOOL tar -xzf "$1" -C /
printf "${GREEN}systemd-boot configuration restored.${RC}\n"
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The script is not supposed to be ran manually. No need for func arguments.

Comment on lines +73 to +93
case "$DTYPE" in
debian | ubuntu)
$ESCALATION_TOOL apt-get install -y grub-efi
grub-install
grub-mkconfig -o /boot/grub/grub.cfg
;;
arch)
$ESCALATION_TOOL pacman -S --noconfirm grub
grub-install --target=x86_64-efi --efi-directory=/boot
grub-mkconfig -o /boot/grub/grub.cfg
;;
fedora)
$ESCALATION_TOOL dnf install -y grub2-efi
grub2-install
grub2-mkconfig -o /boot/grub2/grub.cfg
;;
*)
printf "${RED}Unsupported distribution for GRUB installation.${RC}\n"
exit 1
;;
esac
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use $PACKAGER .
  2. The installation should be separated and config merged into one.

Comment on lines +101 to +109
case "$DTYPE" in
debian | ubuntu | arch | fedora)
$ESCALATION_TOOL bootctl install
;;
*)
printf "${RED}Unsupported distribution for systemd-boot installation.${RC}\n"
exit 1
;;
esac
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
case "$DTYPE" in
debian | ubuntu | arch | fedora)
$ESCALATION_TOOL bootctl install
;;
*)
printf "${RED}Unsupported distribution for systemd-boot installation.${RC}\n"
exit 1
;;
esac
if ! command_exists "systemctl"; then
printf "%b\n" "${RED}systemd-boot only works on systemd distros.${RC}"
exit 1
fi
$ESCALATION_TOOL bootctl install

Comment on lines +113 to +116
display_backup_list() {
printf "${YELLOW}Available backups:${RC}\n"
ls -1 "$BACKUP_DIR" | grep -E 'grub-backup|systemd-boot-backup'
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is used only once. No need for a function.

Comment on lines +155 to +158
3)
printf "${GREEN}Exiting.${RC}\n"
exit 0
;;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this.

printf "${YELLOW}1) Switch to GRUB${RC}\n"
fi
printf "${YELLOW}2) Restore backup${RC}\n"
printf "${YELLOW}3) Exit${RC}\n"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for this.

@adamperkowski
Copy link
Collaborator

You should use "%b\n" with every printf here. Draft this for now.

@Real-MullaC
Copy link
Contributor

You have conflicts that need fixing.

@fam007e fam007e closed this Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature request] Seamless Conversion Between GRUB and systemd-boot
3 participants