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

Major rewrite of pico_setup.sh #20

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

michaelstoops
Copy link

This is a complete overhaul of pico-setup. I'd like to specifically point out my appreciation for the first version, which was very helpful to understand the requirements. Thank you, @liamfraser. I have also incorporated changes are in others' pull requests, but have not yet been merged. Thank you to those authors as well.

Design

The setup actions are grouped into phases. There's a fair bit going on in this script, and I think it's easier to understand with some sensible structure. The phases approximately follow the Getting Started documentation, adjusted for the non-interactive use case.

  1. Preflight check
  2. Setup minimum dev environment
  3. Setup the tutorials
  4. Setup recommended tools

This code is factored into functions, where the previous version was a straight-through script. This code certainly is longer, but should be very easy to read, understand, and modify.

Testing

This version adds some automation for testing. See test/ for details.

Documentation

This version adds README.md and LICENSE.txt. The license is copied from the pico-examples, including the American spelling of "license". :)

Compatibility

This update works with a number of OS and hardware platforms (see README.md). It should work on all up-to-date derivatives of Debian, as the key prerequisite is APT. I've tested it on a number of combinations and left notes (see test/README.md). I have have not exhaustively tested since the last modification, so it's possible that I broke something. Still, it's fair to say it supports lots of platforms.

This should resolve these issues:

Fixes for known issues

.bashrc

This version puts the environment variables in .z?profile, correctly handling both bash and zsh, which is particularly relevant as it's the default shell on macOS. #13, #14

Additionally, the new code handles the case where the file didn't end in a newline. #12

Idempotence

This version is idempotent with regard to mkdir specifically (#10, #11) and generally picks up where it left off when rerun (#6). If interrupted with signal or transient failure, it's fine to rerun.

Visual Studio Code

The script installs VS Code when it looks like there's a local XWindows server. #7

But--the features around Visual Studio Code only work on Raspberry Pi OS, not Debian, Ubuntu or macOS. This is mostly because the Raspberry Pi OS repos already have VS Code and it installs nicely.

Paths with spaces

I think this version handles paths with spaces correctly, but it does download all git submodules, and one of openocd's submodules doesn't handle spaces. #17, #18

Features not added

UI

The design of the code should lend itself nicely to adding an interactive interface or otherwise de/selecting features, but I haven't implemented this and removed the SKIP* method because I didn't like it. I think if it's important, a better mechanism would be command line switches.

Your review is appreciated

Feedback welcome, as always. :)

@michaelstoops michaelstoops mentioned this pull request Apr 5, 2021
@michaelstoops
Copy link
Author

I'm questioning whether I should have submitted this PR. If I could get a clear ruling on whether or not the Raspberry Pi organization wants it, I'd appreciate that. If Raspberry Pi doesn't want it, please close the PR.

To be clear: I'm not meaning to be dramatic or sour-grapes about the decision. I'm just looking to keep moving forward. So please let me know. :)

Thanks,
Michael

@bablokb
Copy link

bablokb commented Apr 5, 2021

Very nice rewrite, I will test it soon. I'm usually working on OpenSuse, and I think the clear structure and encapsulation of features makes it easy to port the script to this slightly different flavor of Linux.
I do have some additional feature requests (e.g. I don't like the automated build of the examples), but I will open an issue for that in your repo.

@michaelstoops
Copy link
Author

Very nice rewrite, I will test it soon. I'm usually working on OpenSuse, and I think the clear structure and encapsulation of features makes it easy to port the script to this slightly different flavor of Linux.
I do have some additional feature requests (e.g. I don't like the automated build of the examples), but I will open an issue for that in your repo.

Thank you for the kind words and encouragement. 😊

What package manager are you using?

@bablokb
Copy link

bablokb commented Apr 5, 2021

OpenSuse uses its own manager called zypper (this is rpm based). There is a wrapper for apt on the system, this should not be a problem. But package names are usually slightly different.

@liamfraser
Copy link
Contributor

@michaelstoops this looks really good. Thanks for your hard work. The original was just something I whipped up to stop mistakes when people were following the written instructions. From our point of view, if it's the same as our current script on a Raspbian install (so the documentation doesn't change) then I'm happy to accept it. I would just like to confirm that myself before doing so.

README.md Outdated Show resolved Hide resolved
This script works on most Debian-derived Linux distros and macOS, running on common Raspberry Pi, PC, and Mac hardware. This ***DOESN'T*** mean that all of the pico tools work properly on these platforms. It just means that this script runs and passes its own tests.

Operating systems:
* Raspberry Pi OS (32-bit)
Copy link
Contributor

Choose a reason for hiding this comment

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

FYI I did test the "previous" pico_setup.sh on Raspberry Pi OS (64-bit) too, so it would be nice if that still worked (I'll do some testing myself later).

Copy link
Author

Choose a reason for hiding this comment

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

It really should work. I think the only explicit consideration to 32-bit vs 64-bit was part of the old VSCode installation. That's been refactored to rely on APT to get the right build.

I'm leaving this conversation open pending confirmation.

README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
test/README.md Outdated
| | Raspberry Pi | x86_64 | AArch64 |
|-|-|-|-|
| Raspberry Pi OS (32-bit) | ✅ | Not tested | Not tested |
| Raspberry Pi OS (64-bit) | ✅ | Not tested | Not tested |
Copy link
Contributor

Choose a reason for hiding this comment

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

Technically speaking, Raspberry Pi OS (64-bit) is AArch64 😉

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, yeah. I looked for a way to write that in, but didn't find anything that was more helpful than distracting.

pico_setup.sh Outdated Show resolved Hide resolved
pico_setup.sh Outdated
Comment on lines 180 to 181
# Restore working directory
popd >> /dev/null
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice to do this pushd / popd thing in the other functions too :)

pico_setup.sh Outdated
@@ -24,13 +24,19 @@
set -e
# Show all commands
set -x

# Trying to use an non-existent variable is an error
Copy link

Choose a reason for hiding this comment

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

"an" -> "a"

@lurch
Copy link
Contributor

lurch commented Apr 7, 2021

I just tried running this in a Debian docker image, and it got as far as:

Entering phase 0: Preflight check
+ echo 'Verifying sudo access'
Verifying sudo access
+ sudo -v
./pico_setup.sh: line 87: sudo: command not found

I dunno if that's a standard Debian thing, or just a Debian-in-Docker thing? 🤷 I guess at the very least it's probably worth checking if the sudo command is available, and exiting with an appropriate error-message if not?

@aallan
Copy link

aallan commented Apr 7, 2021

I dunno if that's a standard Debian thing, or just a Debian-in-Docker thing? 🤷 I guess at the very least it's probably worth checking if the sudo command is available, and exiting with an appropriate error-message if not?

If sudo isn't available then we have bigger problems and should probably just stop?

@lurch
Copy link
Contributor

lurch commented Apr 7, 2021

I side-stepped that problem by doing apt install sudo (Docker images run with the root user by default), and ran the script again, and it ran to completion 👍

pico_setup.sh Outdated Show resolved Hide resolved
@michaelstoops
Copy link
Author

I just tried running this in a Debian docker image, and it got as far as:

Entering phase 0: Preflight check
+ echo 'Verifying sudo access'
Verifying sudo access
+ sudo -v
./pico_setup.sh: line 87: sudo: command not found

I dunno if that's a standard Debian thing, or just a Debian-in-Docker thing? 🤷 I guess at the very least it's probably worth checking if the sudo command is available, and exiting with an appropriate error-message if not?

I think Docker images tend to contain as little as possible. What image were you using?

@lurch
Copy link
Contributor

lurch commented Apr 7, 2021

I think Docker images tend to contain as little as possible. What image were you using?

sudo docker run -it debian on my Ubuntu 18.04 x64 laptop.

@lurch
Copy link
Contributor

lurch commented Apr 7, 2021

@michaelstoops
Copy link
Author

FYI @michaelstoops msteveb/jimtcl#199

Good guy @lurch to the rescue!

Thanks. :)

@michaelstoops
Copy link
Author

I think we could support the Debian Docker image, sans sudo, by invoking sudo only if we aren't already root.

I would ask whether we want to go to such trouble to support this image, but it would enable Docker as a platform for automated builds, and I like that idea.

@michaelstoops
Copy link
Author

michaelstoops commented Apr 7, 2021 via email

@michaelstoops
Copy link
Author

michaelstoops commented Apr 7, 2021 via email

@michaelstoops
Copy link
Author

Status update, FYI:

This work is in a testing and test-development phase, which has some long cycles and may take a bit of wall-clock time to complete. I think the core functionality of the setup script is about where it needs to be, so moving on to testing is good progress.

I've re-framed the code that used to be called test/test as a validation process, and have integrated it into the main setup script. I did this because it really was validation of the one build, rather than a test of the code under different circumstances. I figure there's really no reason not to validate every time. Better to know if it's broken.

Testing is critical for a piece of software like this: meant to be run by end-users, working on lots of different platforms, with varying assumptions, and dependent on distinct repos that may or may not have what we expect. Not only do I need to make sure my code works this time, but it will need to be tested again after the next bug fix, the one after that, etc.

In summary, if I don't automate testing, this work will go to waste. Therefore, I'm investing effort in writing a new test suite, which runs this code through all of the supported circumstances for the host it's running on. For example, the setup script should work on bash and zsh, both on the first installation and later updates, etc. The test suite tests those scenarios.

I may or may not automate testing across host types. I am comfortable with spreading these tests out to EC2 instances, but I suspect that most members of this community aren't comfortable with EC2. If there's a more appropriate tool among the potential developers of this code, that might be better. VirtualBox comes to mind, although that isn't particularly convenient for me, running on a MacBook Air M1. None of the virtual host technologies work on M1 as far as I know.

This is all a bit more work than I meant to do, but I think it's a good cause and will make a difference to people. Probably a good piece of work for my portfolio too.

🙂 Michael

@ndabas
Copy link

ndabas commented Apr 8, 2021

Regarding testing, GitHub Actions might be worth considering, because they give us access to Windows, Ubuntu, and macOS hosts, and all for free -- plus, the testing can be fully integrated into the GitHub workflow itself -- when somebody submits a PR, their code will be tested on these platforms automatically. The downside is that the machines are not clean -- they have lots of dev tools preinstalled, but that will still give us some level of validation.

The only platform not covered there would be Raspberry Pi hardware itself. Another option that covers that somewhat would be Docker, which can be used to test Windows, Ubuntu, and Raspbian x86-64 (not sure how close that is to the Pi distros though.) Docker leaves out macOS though.

Personally I'd be happy with an EC2-based solution -- even though the macOS bit is a pain to manage because of the 24-hour minimum -- it's really up to the Pi folks to figure out what would work for them in the long term in terms of maintaining this code, reviewing PRs, and so on.

@ndabas
Copy link

ndabas commented Apr 8, 2021

This is all a bit more work than I meant to do, but I think it's a good cause and will make a difference to people. Probably a good piece of work for my portfolio too.

I think what you're doing is fantastic.

I was thinking about making some radical changes to the setup process myself, but you actually put in the hard work and produced something usable right now. Which is worth a lot more than just ideas.

What were those ideas?

  • Ditch the setup completely, instead produce "buildpacks" for the supported platforms. These would be self-contained binary distributions with all the tools you need, packaged along with a snapshot of the relevant SDK & co. repos.
  • A Makefile to run the setup, since we're essentially just checking if stuff exists and pulling it down if it doesn't.
  • Rewrite the script in PowerShell, so it could run on Windows native, Windows WSL, Linux, macOS, and the Raspberry Pi distros.

@bablokb
Copy link

bablokb commented Apr 10, 2021

Instead of using pushd/popd, you could just run the relevant commands in a subshell (enclose commands in parenthesis ( ... )). This also has the advantage that the commands don't have any unwanted side-effects, e.g. manipulating variables.

But my suggestion is: just merge the pull request. It has been polished more than most of the other stuff for pico. And once that is done, we can have incremental pull-requests for the missing functions/cleanups/etc.

@michaelstoops
Copy link
Author

I spent a couple days away from this code. I'm back but I would like to wrap it up.

As discussed, I have moved the validation code into the setup script. test/test_local.sh is now the primary test. I have tested it on Raspberry Pi OS on a Raspberry Pi 4, and Debian and Ubuntu on x85 and Graviton2. I have not tested the current state against macOS because it's expensive and I'd like to do it just once more.

The installer hasn't changed much from earlier revisions, but the testing code is new and I suspect I'll get some feedback on it. Let's do one more round of review, then do the final tests on all the platforms, and then merge the change.

@aallan
Copy link

aallan commented Apr 13, 2021

But my suggestion is: just merge the pull request.

I think we were waiting for @liamfraser to run a clean room test to confirm that it performed the same as his original script.

@lurch
Copy link
Contributor

lurch commented Apr 15, 2021

Sorry I disappeared off the radar on this after all my earlier feedback - I had other stuff to work on.
I've just tested this on a fresh Raspberry Pi OS (32-bit) SD-card (running on a Pi400), and it gets as far as:

You must run sudo reboot to finish UART setup
+ validate_uart
+ dpkg-query -s minicom
+ grep -q enable_uart=1 /boot/config.txt
+ grep -q console=serial0 /boot/cmdline.txt

and I only get a pico-sdk directory in ~/pico, with no pico-examples directory. I ran the script again, and it stopped at the same place, and when I cat ~/.profile the export "PICO_SDK_PATH=/home/pi/pico/pico-sdk" line is in there twice! 😕

@ndabas
Copy link

ndabas commented Apr 18, 2021

Perhaps we can use this for testing on macOS? At least for a quick smoke test? https://github.com/sickcodes/Docker-OSX/

@aallan
Copy link

aallan commented May 21, 2021

@michaelstoops Did you see @lurch's comment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment