-
-
Notifications
You must be signed in to change notification settings - Fork 188
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
Improvements to scripts under initrd #885
Comments
@Thrilleratplay I agree with all your planning but precedent point! Inversely, I believe Heads is currently filled with functions duplicates, that since common, should all be under |
So in short, init merges configs and then exports environement variables by cbfs files are measured under PCR7 prior of the merging by done by |
@tlaurion I think my main issue has been trying to determine from the source where this was coming from. Within the past few days realized it is concatenated using the build config and a few other items. Its name suggested it was used to change and update parameters in various scripts. It is was called Seeing that making the shellcheck related updates look like they will cause a number of possible issues despite being supposedly benign, I am shelving the PR to focus on IFD/GBE blob generation. This was to document the things I wanted to tackle when returning the I noticed this issue when looking into #447, # mock code
is_boot_mounted() {
return [-z $BOOT_DIR ]
}
mount_boot_dir_rw() {
if is_boot_mounted; then
return $BOOT_DIR;
elif mount -o rw /boot; then
BOOT_DIR= "/boot"
#if boot is not a separate partition, set the boot directory to prevent scanning of entire partition
if [ -d "/boot/boot/" ]; then
BOOT_DIR= "/boot/boot"
fi
export BOOT_DIR
return $BOOT_DIR
fi
unset BOOT_DIR
#SOMETHING WENT WRONG!!! ABANDON SHIP!
return "SOME ERROR"
} Instead of passing in
Obviously better error handling can be implemented but the idea is that how the boot directory can be changed (different partitions, user parameters, different drives, etc) without modifying any of the dependent functions it if it adheres to the just setting an known and documented environmental variable. Breaking down other functionality like HOTP, where the function would contain seal, unseal, check, etc would be more complicated as they would share many TOPT functionality. This break down should also make removing dead code easier, unit testing easier and theoretically cut down on nuance bugs where someone didn't listen to Egon and decided to cross the streams. |
Any news on this? |
@danielp96 A lot of side improvements have happened, but I think I know what you mean. The main issue here, and linked @Thrilleratplay (sorry if I misinterpret), is that current version of busybox offers poor compatibility with bash. It improved under latest version, which I experimented a bit trying to modify wyng-extract.sh script to realize even with latest version, CONFIG_BASH_IS_ASH is misleading. So one trying to move things forward here are better testing code as if it was DASH then BASH, which shellcheck cannot know. But knowing that busybox is more compliant with DASH then BASH explains why @Thrilleratplay had some issues with 7740f53 I have to admit I didn't revisited this issue for a while, outside of the recent work that was done to move more into /etc/functions and reduce deduplication of functions, but that work is not over yet. Basically, prior of going forward in this path, it would be advisable to update busybox to latest version and restart where 7740f53 was left, but trying to have scripts more posix compliant then bash compliant. Otherwise, things will break. We are getting a bit closer with #1188. So I guess it would make sense to test this PR first @danielp96 and then move formward into testing local changes with QEMU instead of bricking machine (and external flashing to get a machine working). |
@danielp96, that is a good summary and like @tlaurion, I have not taken a look a look at this in a while. I was distracted by reproducible builds for Heads, other projects and life in general (sorry @tlaurion, I didn't mean to just disappear and do plan on continuing the reproducible build environment when I can devote the necessary time to it). When I last took a look, the various scripts were written in different styles, function inputs were not always obvious and passed in different formats, and there were redundancies that could have been streamlined. What I had envisioned was a core script framework that could be extended, minified and unit tested. I bit off more than I could chew where just linting with shellcheck caused potential problems if merged. I was thinking about how to approach this in a safer manner, but then was distracted. I think a script framework for Heads would make development easier with fewer bugs but the it will be a balancing act of how/where to restructure while not breaking anything existing or adding too much redundancy while migrating. |
Together with @JonathonHall-Purism and Tray we are willing to work on this. So as starting would be updating busybox and making sure everything is compatible with it, if I understood correctly? Then I was thinking about adding the .sh extension to all the scripts (to avoid the confusion of script vs function) and separating the menu navigation and functions into separate scripts, that way the menus are more flexible and the functions are free to be sorced whenever they're needed without risk of running something else. After that, solving the other tasks on the list. Any thoughts/corrections/recommendations? |
If following a similar path I had originally laid out, I am not sure what to recommend. There are a lot of script quirks that exist and it is difficult to know what is using used by different users. As I kept running into "I don't know who is using this and if I change it will it break the platform for them", a better first step may be:
|
Well, the last iteration on better splitting things up if I recall well happened under 1f27dea
I will try to be clearer from last personal experiments:
The challenge here is to go in as many little steps needed
As for all other recommendations from OP, I agree with all of them. Comments:
|
Sorry I didn't pick up on the ASH (posix) approach (#862) vs BASH compatibility problems (#872) where #862 was the desired approach. (Banged my head like I said previously on bash-isms that people will think supported by having scripts declaring bash vs ash, and where ash is now supported from shellcheck. Having posix compliant scripts is the case under Heads right now and should be the way to go.) Closed #872 and reopened #862 while updating the later with #862 (comment) |
During the course of debugging #872, correcting shellcheck errors and warnings, a number of issues presented that made verifying the changes difficult. Examples of this were errors that existed in the master branch (although these may have been unique to using
qemu-coreboot-fwwhiptail
), needing to unquote variables used as whiptail parameters then adding shellcheck exceptions, as many scripts do not have.sh
extensions there stances where it is difficult to determine if a function or script is being invoked, and not owning a Librem/Nitro Key to be able to test and of those scripts. Given how fragile the existing initrd script is, I believe a different approach is needed.The original plan was to correct shellcheck errors and warning then progress to cleaning up and tightening the scripts. At this time, it seems that these should be done together; focusing on improving, cleaning up, documenting, normalizing individual functionality to minimize the amount of testing and reduce the potential for introducing bugs.
A few suggestions:
.sh
exetension. Be sure to add.sh
extension to references in the script.#!/bin/bash
/etc/profile
instead of/tmp/config
(is there a reason?)/initrd/bin
to be user facing end points to deal with usage menus, basic input validation and proper calling of the appropriate file.Test cases/issues to correct:
mount: mounting /dev/sda1 on /boot failed: invalid argument
infinitely. Reported in Error loop if Heads is configured and hard drive is missing or replaced #911 .The text was updated successfully, but these errors were encountered: