Add overlay script

`overlay` does the tedious work of setting up and tearing down the
environment required for overlay filesystems. Example use:

```
root@bmc:~# touch /usr/share/vpd/foo
touch: /usr/share/vpd/foo: Read-only file system
root@bmc:~# ./overlay add /usr/share/vpd
[53864.956641] overlayfs: upper fs does not support xattr, falling back to index=off and metacopy=off.
root@bmc:~# touch /usr/share/vpd/foo
root@bmc:~# ls -l /usr/share/vpd/foo
-rw-r--r--    1 root     root             0 Sep  6 23:55 /usr/share/vpd/foo
root@bmc:~# rm /usr/share/vpd/foo
root@bmc:~# ls -l /usr/share/vpd/foo
ls: /usr/share/vpd/foo: No such file or directory
root@bmc:~# ./overlay remove /usr/share/vpd
root@bmc:~# touch /usr/share/vpd/foo
touch: /usr/share/vpd/foo: Read-only file system
```

The `rm -rf` specifically removes the temporary directories specified
in the mount options:

```
root@bmc:~# ./overlay add /usr/share/vpd
root@bmc:~# sh -x ./overlay remove /usr/share/vpd
+ set -eu
+ '[' 2 -lt 2 ']'
+ case $1 in
+ o_lowerdir=/usr/share/vpd
++ fstab_fs_mntopt /usr/share/vpd
++ awk '"overlay" == $1 && "/usr/share/vpd" == $2 { printf("%s\n", $4)
}'
+
o_options=rw,relatime,lowerdir=/usr/share/vpd,upperdir=/tmp/tmp.v8vJ35,workdir=/tmp/tmp.6v1YJY
+ umount /usr/share/vpd
+ '[' -z
rw,relatime,lowerdir=/usr/share/vpd,upperdir=/tmp/tmp.v8vJ35,workdir=/tmp/tmp.6v1YJY
']'
+ fstab_option_iter
+ tr , '\n'
+ echo
rw,relatime,lowerdir=/usr/share/vpd,upperdir=/tmp/tmp.v8vJ35,workdir=/tmp/tmp.6v1YJY
+ read FS_MNTOPT
+ case $FS_MNTOPT in
+ read FS_MNTOPT
+ case $FS_MNTOPT in
+ read FS_MNTOPT
+ case $FS_MNTOPT in
+ read FS_MNTOPT
+ case $FS_MNTOPT in
++ echo upperdir=/tmp/tmp.v8vJ35
++ fstab_option_value
++ cut -d= -f2
+ rm -rf /tmp/tmp.v8vJ35
+ read FS_MNTOPT
+ case $FS_MNTOPT in
++ fstab_option_value
++ cut -d= -f2
++ echo workdir=/tmp/tmp.6v1YJY
+ rm -rf /tmp/tmp.6v1YJY
+ read FS_MNTOPT
root@bmc:~#
```

It also safely handles bad remove invocations:

```
root@bmc:~# sh -x ./overlay remove /asdf
+ set -eu
+ '[' 2 -lt 2 ']'
+ case $1 in
+ o_lowerdir=/asdf
++ fstab_fs_mntopt /asdf
++ awk '"overlay" == $1 && "/asdf" == $2 { printf("%s\n", $4) }'
+ o_options=
+ umount /asdf
umount: /asdf: no mount point specified.
root@bmc:~# sh -x ./overlay remove /
+ set -eu
+ '[' 2 -lt 2 ']'
+ case $1 in
+ o_lowerdir=/
++ fstab_fs_mntopt /
++ awk '"overlay" == $1 && "/" == $2 { printf("%s\n", $4) }'
+ o_options=
+ umount /
+ '[' -z '' ']'
+ echo / is not an overlay
/ is not an overlay
+ exit 1
root@bmc:~#
```

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: I0118c645d9edf391d9670aacc889f31d1e1b2f5f
1 file changed
tree: bb37a32b3613982842ca49e56de2bdbc9ce59df9
  1. adcapp/
  2. altitude/
  3. autojson/
  4. bi2cp/
  5. cla-signers/
  6. dbus-pcap/
  7. dbusView/
  8. ddconvnotrunc/
  9. expectedJsonChecker/
  10. format-yaml/
  11. maintainers/
  12. netboot/
  13. openbmc-autobump/
  14. openbmc-events/
  15. openbmctool/
  16. overlay/
  17. pldm/
  18. pretty-journal/
  19. pwmtachtool/
  20. reboot/
  21. reboot-ping-pong/
  22. rootfs_size/
  23. sensor_yaml_config/
  24. tracing/
  25. upload_and_update/
  26. witherspoon-debug/
  27. LICENSE
  28. MAINTAINERS
  29. README.md
README.md

The OpenBMC Tools Collection

The goal of this repository is to collect the two-minute hacks you write to automate interactions with OpenBMC systems.

It's highly likely the scripts don't meet your needs - they could be undocumented, dysfunctional or utterly broken. Please help us improve!

Repository Rules

  • Always inspect what you will be executing
  • Some hacking on your part is to be expected

If you're still with us

Then this repository aims to be the default destination for your otherwise un-homed scripts. As such we are setting the bar for submission pretty low, and we aim to make the process as easy as possible.

Sending patches

Please use gerrit for all patches to this repository:

Do note that you will need to be party to the OpenBMC CLA before your contributions can be accepted. See Gerrit Setup and CLA for more information.

What we will do once we have your patches

So long as your patches look sane with a cursory glance you can expect them to be applied. We may push back in the event that similar tools already exist or there are egregious issues.

What you must have in your patches

We don't ask for much, but you need to give us at least a Signed-off-by, use SPDX markers in your source files and put your work under an Apache 2.0 compatible license.

How you consume the repository

There's no standard way to install the scripts housed here, and adding parts of the repository to your PATH might be a bit of a dice-roll. We may also move or remove scripts from time to time as part of housekeeping. It's probably best to copy things out if you need stability.