bearing / dosenet-raspberrypi

Raspberry Pi specific software for dosimeters.
MIT License
7 stars 21 forks source link

better shell scripts - closes #24 #36

Closed bplimley closed 8 years ago

bplimley commented 8 years ago

dosenet.py

  1. no longer checks the default config file and publickey every time. These paths are coded in globalvalues.py and manager.py's argparse looks for them when manager.py is run in normal mode (not --test). Instead of raising an error in the bash script, manager.py will raise an IOError (with description) if you try to start manager.py in normal mode without these files.
    • This also means that you can run manager.py --test without needing a config file or publickey. Closes bearing/dosenet/#70
    • dosenet.sh --test still checks for config and publickey, because if you don't supply them explicitly to manager.py --test, they will not be loaded.
  2. Status messages are logged to /var/log/messages as well as stderr in the same call (logger --stderr)

    git-pull-reboot.sh

  3. Station ID is read out of /home/pi/config/config.csv
  4. Current git branch is read from git status (although currently not used)
  5. The intended git branch is defined based on the station ID. So you can leave different stations on different branches. Default is master.
  6. Exit codes from git checkout and git pull are checked. Although there isn't very much to use them for right now, since the pi does not have a method of reporting info to the server.
  7. There is a FORCE_GIT option which will git checkout -f, discarding local changes. It is currently turned off. This may be superfluous because our deployed stations should not be on random branches with local changes.
  8. Calls system-update.sh after the git checkout/git pull, before the reboot. The station ID is an argument to system-update.sh. See below.

    system-update.sh

  9. Here is where we can update system files, like /etc/network/interfaces, or /var/www/ stuff.
  10. Currently this is an empty case statement that checks station ID. There is an example set up for test station 10005.
  11. We need to be careful with system updates, obviously, because failures could break system functionality. System update code must include exit code checking and graceful error handling.
bplimley commented 8 years ago

I talked to Joey and we realized that if there are any local changes, there should be a git stash and then checkout/pull. So, don't merge yet.

See also new issue #37 which is related (but will be implemented at a later time).

bplimley commented 8 years ago

Added features:

git-pull-reboot.sh

  1. Checks for local changes via git status.
    • If there are local commits not in origin, then they are moved to a temporary branch named like localchanges-May-12, and the current branch is reset to origin/$CURRENT_BRANCH where it should be.
    • If there are local changes, staged or unstaged, they are put into a git stash.
    • In the current version of the pi, the git stash will fail because git is not configured with user.name and user.email. So...

system-update.sh

  1. First system update! Checks to see if user.name and user.email are set in the repo. If not, they are set to "Anonymous Pi" and "dosenet.pi@radwatch.berkeley.edu" (this email address is recorded in git, but doesn't have to be a real address)

Note that if any of the deployed devices actually have local changes, then the existing git pull --ff-only call in git-pull-reboot.sh, as it exists on the old master branch, will fail. And that means that this updated script will never get on there, until we go fix it by hand (or have a local student do it). So really, the git stash and git branch stuff is for the future.

In addition, as discussed, the branch configuration should really not be part of the same code repo, but be somewhere else (a different repo, or something else downloadable). That will be a different PR though.

I believe I've tested everything pretty carefully. So I am going to merge this now, so that everything can update tonight. The system update or branch changes won't occur until tomorrow night, because the existing copy of git-pull-reboot.sh doesn't have them.