diff options
author | Slack Coder <slackcoder@server.ky> | 2024-08-13 05:22:44 -0500 |
---|---|---|
committer | Slack Coder <slackcoder@server.ky> | 2024-08-13 05:22:44 -0500 |
commit | 27d76eb7791934482984b61e497d80f2d7516d11 (patch) | |
tree | 4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
parent | 01e0d1d94118738db00e55995d471595b6f4ca76 (diff) | |
download | efi-sync-27d76eb7791934482984b61e497d80f2d7516d11.tar.xz |
Set To Do branch
-rw-r--r-- | ChangeLog.md | 18 | ||||
-rw-r--r-- | LICENSE.txt | 19 | ||||
-rw-r--r-- | README.md | 72 | ||||
-rw-r--r-- | efi-sync | 162 |
4 files changed, 0 insertions, 271 deletions
diff --git a/ChangeLog.md b/ChangeLog.md deleted file mode 100644 index 777eee4..0000000 --- a/ChangeLog.md +++ /dev/null @@ -1,18 +0,0 @@ -# Change Log - -All notable changes to this project will be documented in this file. - -## [0.2.0-alpha] - 2024-04-29 - -### Added - - - Added configuration for source and destination initrd paths. - -### Changed - - - No longer expect mkinitrd to have the destination initrd configured for the EFI. - -### Fixed - - - Avoid using the 'USER' environment variable which is not set by SysVInit. - - Avoid emitting successful install messages on error. diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index debfdcb..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,19 +0,0 @@ -Copyright 2024 Slack Coder - -Permission is hereby granted, free of charge, to any person obtaining a copy of -this software and associated documentation files (the “Software”), to deal in -the Software without restriction, including without limitation the rights to -use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies -of the Software, and to permit persons to whom the Software is furnished to do -so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index ba6b28f..0000000 --- a/README.md +++ /dev/null @@ -1,72 +0,0 @@ -# EFI Sync - -Automatically install your kernel and initrd into the EFI when your Slackware system is updated. - -``` -Usage: ./efi-sync {install|watch} - - - install: install the kernel and initrd into your EFI. - - watch: install on updates to your kernel - -``` - -`efi-sync watch` watches your kernel path for updates. Your EFI will be updated once -one is detected and the package commands have completed. - -For systems using an initial ram disk (initrd), `efi-sync watch` watches -/lib/modules and /lib/firmware for updates. Your system is assumed to use one -if '/etc/mkinitrd.conf' is present on start. Once changes are detected, the -initrd file is recreated using 'mkinitrd' and with the result installed into -the EFI. - -You will need to manually install the initrd if it was recreated outside of -this program. - -## Installation - -Run the following are root to install this command: -``` -cp efi-sync /usr/local/sbin/efi-sync -chown root:root /usr/local/sbin/efi-sync -chmod +x /usr/local/sbin/efi-sync -``` - -The efi-sync will need to be integrated to start automatically on your system. - -## Configuration - -The command looks for configuration at /etc/efi-sync.conf. - -Here is an example with the default values: -``` -# The kernel path to watch. -KERNEL=/boot/vmlinuz -# The path to the EFI kernel. -EFI_KERNEL=/boot/efi/Slackware/vmlinuz -# The path for the initial ram disk to install. -INITRD=/boot/initrd.gz -# The path to the EFI's initial ram disk. -EFI_INITRD=/boot/efi/Slackware/initrd.gz -``` - -If you want the initial ram disk updated, ensure /etc/mkinitrd.conf exists and -is configured correctly. - -### Testing - -To test everything is working correctly: - -``` -slackpkg -batch=on -default_answer=y upgrade --reinstall kernel-huge - -# You should confirm the recent update with this output. -date -r /boot/efi/EFI/Slackware/vmlinuz -``` - -For initrd updates: -``` -slackpkg -batch=on -default_answer=y upgrade --reinstall kernel-firmware - -# You should confirm the recent update with this output. -date -r /boot/efi/EFI/Slackware/initrd.gz -``` diff --git a/efi-sync b/efi-sync deleted file mode 100644 index f8be4f4..0000000 --- a/efi-sync +++ /dev/null @@ -1,162 +0,0 @@ -#!/bin/bash - -trap graceful_exit INT TERM - -# Inofity events which signal something changed. -MODIFICATION_EVENTS="CREATE,CLOSE_WRITE,MOVED_TO,MOVED_FROM,MOVE" - -# Signals if the watcher should stop. -STOP=false - -graceful_exit () { - STOP=true - - if [[ ! -z "$KPID" ]]; then - kill -TERM $KPID >/dev/null 2>/dev/null - fi - if [[ ! -z "$MPID" ]]; then - kill -TERM $MPID >/dev/null 2>/dev/null - fi -} - -load_config() { - KERNEL=/boot/vmlinuz - EFI_KERNEL=/boot/efi/EFI/Slackware/vmlinuz - INITRD=/boot/initrd.gz - EFI_INITRD=/boot/efi/EFI/Slackware/initrd.gz - - if [[ -f /etc/efi-sync.conf ]]; then - source /etc/efi-sync.conf || exit 1 - fi - - INSTALL_PROGRAMS="slackpkg,upgradepkg,installpkg,removepkg" - WAIT_TIME=1 -} - -log () { - echo "$(date --rfc-3339=seconds) $@" -} - -require_efi () { - if ! mount | grep vfat >/dev/null; then - log "the efi partition must be mounted" - exit 1 - fi -} - -require_root () { - if [[ "$(id --user --name)" != "root" ]]; then - log "command must be run as root" - exit 1 - fi -} - -efi_install () { - require_root - require_efi - load_config - - KERNEL_VERSION="$(basename $(realpath "$KERNEL") | sed -E 's/vmlinuz-(.*)-(.*)/\2/')" - - if ! cp -H "$KERNEL" "${EFI_KERNEL}"; then - log "Failed to copy '${KERNEL}' into your EFI at '${EFI_KERNEL}'." - return 1 - fi - log "Installed $(realpath "$KERNEL")." - - if [[ -f /etc/mkinitrd.conf ]]; then - if ! mkinitrd -F -c -k "${KERNEL_VERSION}" >/dev/null 2>&1; then - log "mkinitrd.conf detected but failed to build your initial ramdisk for '${KERNEL_VERSION}'." - return 1 - fi - log "mkinitrd.conf detected and successfully built your initial ramdisk for '${KERNEL_VERSION}'." - fi - - if [[ -f "$INITRD" ]] && [[ "$INITRD" != "$EFI_INITRD" ]]; then - if [[ "$INITRD" != "$EFI_INITRD" ]] && ! cp -H "$INITRD" "${EFI_INITRD}"; then - log "Failed to copy '${INITRD}' into your EFI at '${EFI_INITRD}'." - return 1 - fi - log "Installed the initial RAM disk '${INITRD}'." - fi -} - -efi_watch () { - require_root - require_efi - load_config - - while ! $STOP; do - log "Watching ${KERNEL} for updates." - - >/dev/null inotifywait "$(dirname "$KERNEL")" --include "./$(basename $KERNEL)$" \ - --event "$MODIFICATION_EVENTS" \ - --quiet & - KPID="$!" - - # Watching for directory updates is enough and helps avoid the system's watch limit. - readarray -d '' INITRD_FILES < <(find /lib/firmware /lib/modules -type d -print0) - >/dev/null inotifywait \ - --event "$MODIFICATION_EVENTS" \ - --quiet \ - --recursive \ - "${INITRD_FILES[@]}" & - MPID="$!" - - if ! wait -n "$KPID" "$MPID" || $STOP; then - kill -TERM $KPID $MPID >/dev/null 2>/dev/null - continue - fi - kill -TERM $KPID $MPID >/dev/null 2>/dev/null - unset KPID MPID - - # Be safe and consider changes to the kernel system which happen during - # installation. - # - # Use file creation time to check if re-installation is needed. - TIMESTAMP_FILE="$(mktemp -t "efi-sync.XXXXXXX")" - - while true; do - touch "$TIMESTAMP_FILE" - - let "count = 0" - while [[ $count -lt $WAIT_TIME ]]; do - if ps -C "$INSTALL_PROGRAMS" >/dev/null; then - let "count = 0" - sleep 1 - - continue - fi - - let "count = $count + 1" - sleep 1 - done - - efi_install - - NEW_FILES="$(find "$KERNEL" /lib/firmware /lib/modules -newer "$TIMESTAMP_FILE")" - if [[ -z "$NEW_FILES" ]]; then - break - fi - done - - rm "$TIMESTAMP_FILE" - done - - log "Stopped watching ${KERNEL} for updates." -} - -case "$1" in - 'install') - efi_install - ;; - 'watch') - efi_watch - ;; - *) - echo "Usage: $0 [install|watch]" - echo "" - echo -e "\t- install: install the kernel and initrd into your EFI." - echo -e "\t- watch: install on updates to your kernel" - echo "" -esac |