This PR addresses two issues in the readsb-gain script:
1) A non-numeric arg is not always handled correctly, resulting in an invalid gain value being written to /etc/default/readsb
2) Attempting to set an initial gain value fails with a permission denied error for non-root users
My proposed fix for 1. validates the sanitized input against a regex to ensure it only contains either a positive number, or -10 (AGC).
(if there's a requirement to accept negative gain values besides -10, let me know and I'll update the regex and resubmit)
2. is just a missing sudo prefix for the sed command.
**Test cases:**
1.
$ readsb-gain --help && grep gain /etc/default/readsb
Error, invalid gain!
$ readsb-gain -h && grep gain /etc/default/readsb
Error, invalid gain!
$ readsb-gain .. && grep gain /etc/default/readsb
Error, invalid gain!
$ readsb-gain 1-2 && grep gain /etc/default/readsb
Error, invalid gain!
This PR addresses two issues in the readsb-gain script: 1) A non-numeric arg is not always handled correctly, resulting in an invalid gain value being written to /etc/default/readsb 2) Attempting to set an initial gain value fails with a permission denied error for non-root users
Examples: 1.
$ readsb-gain 10 sed: couldn't open temporary file /etc/default/sed4HdeAg: Permission denied
$ readsb-gain --help && grep gain /etc/default/readsb Error, invalid gain!
$ readsb-gain -h && grep gain /etc/default/readsb Error, invalid gain!
$ readsb-gain .. && grep gain /etc/default/readsb Error, invalid gain!
$ readsb-gain 1-2 && grep gain /etc/default/readsb Error, invalid gain!
$ readsb-gain +1.2 && grep gain /etc/default/readsb RECEIVER_OPTIONS="--device 0 --device-type rtlsdr --gain 1.2 --ppm 0"
$ readsb-gain -1.2 && grep gain /etc/default/readsb Error, invalid gain!
$ readsb-gain 1.2.3 && grep gain /etc/default/readsb Error, invalid gain!
$ readsb-gain 0.12 && grep gain /etc/default/readsb RECEIVER_OPTIONS="--device 0 --device-type rtlsdr --gain 0.12 --ppm 0"
$ readsb-gain -0.12 && grep gain /etc/default/readsb Error, invalid gain!
$ readsb-gain -10 && grep gain /etc/default/readsb RECEIVER_OPTIONS="--device 0 --device-type rtlsdr --gain -10 --ppm 0"
$ readsb-gain 40 && grep gain /etc/default/readsb RECEIVER_OPTIONS="--device 0 --device-type rtlsdr --gain 40 --ppm 0"
$ grep RECEIVER_OPTIONS /etc/default/readsb RECEIVER_OPTIONS="--device 0 --device-type rtlsdr --ppm 0"
$ readsb-gain 10 $ grep RECEIVER_OPTIONS /etc/default/readsb RECEIVER_OPTIONS="--gain 10 --device 0 --device-type rtlsdr --ppm 0"