linuxboot / linuxboot/heads

Improvements to scripts under initrd

Open
#885 11 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Makefile
Stars
1.6k
Forks
211
Avg merge
4d 21h
Merged PRs (30d)
6

Description

During the course of debugging #872, correcting [shellcheck](https://github.com/koalaman/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](https://github.com/osresearch/heads/pull/872/commits/85ce46435991396648a3ba1ca6e7176eeeee6946) 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:

- [X] [enable CONFIG_BASH_IS_ASH](https://github.com/osresearch/heads/pull/872/commits/4802f713455aae88497d25d0d80cb59d59605c48) - Done in #909 and #945
- [ ] [Give all script files `.sh` exetension](https://github.com/osresearch/heads/pull/872/commits/6a81b16942dadb4ab239ec6bf1cc2f5634e2d813). Be sure to add [`.sh` extension to references in the script](https://github.com/osresearch/heads/pull/872/commits/4c3a8d891835c3309c7424fba7e3c16078178ce0).
- [ ] [Replace sheband with `#!/bin/bash`](https://github.com/osresearch/heads/pull/872/commits/7740f5328632ce966c95cbcbcbdf1de933f496e0)
- [ ] Use function to generate/normalize y/n menus
- [ ] use environmental variables via `/etc/profile` instead of `/tmp/config` (is there a reason?)
- [ ] Pass shellcheck without any no ignore statements
- [ ] No global variables. Either are defined or documented as an environmental variable.
- [ ] Functions much return value or return true.
- [ ] Remove .ash_history, replace examples in ash_history with alias or bash scripts
- [ ] Ensure all user facing bash scripts have usage menus.
- [ ] (?) Abstract out logic into functions.sh or other function files. Leaving scripts found in `/initrd/bin` to be user facing end points to deal with usage menus, basic input validation and proper calling of the appropriate file.
- [ ] Add unit testing. I have used [shellspec](https://github.com/shellspec/shellspec) and would recommend it.
- [ ] (?) Break each function into individual files. Sourcing would be more complicated but will allow tracking function usage and explicitly define a function's source.
- [ ] (?) Include documentation annotations such as [shdoc(]https://github.com/reconquest/shdoc)

Test cases/issues to correct:
- [] If a fully encrypted drive or other drive that cannot be mounted is used in a configured Heads device, it will result in an error loop printing `mount: mounting /dev/sda1 on /boot failed: invalid argument` infinitely. Reported in #911 .

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by inventorying the scripts under initrd and the user-facing entry points in /initrd/bin, then review the shellcheck findings and the existing /tmp/config and /etc/profile handling. Use the listed #911 mount-loop case as a regression target and consider shellspec for unit tests. Done means the agreed script cleanup, documentation, validation, and testing scope is completed without reintroducing initrd failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, shell
Domain
operating-systems
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.