Require --install and print help when install.sh is run with no arguments.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-14 23:18:34 +08:00
co-authored by Cursor
parent 6c73f3e706
commit 8010cd9045
2 changed files with 63 additions and 15 deletions
+4 -3
View File
@@ -12,7 +12,8 @@ From a clone of this repository on the Raspberry Pi:
```bash ```bash
cd rpi-temp-humid-monitor cd rpi-temp-humid-monitor
sudo ./install.sh ./install.sh # show help
sudo ./install.sh --install
``` ```
This will: This will:
@@ -39,13 +40,13 @@ thmonitor-single # one-off read (uses venv)
Cron-based single-shot mode instead of the loop daemon: Cron-based single-shot mode instead of the loop daemon:
```bash ```bash
sudo ./install.sh --cron sudo ./install.sh --install --cron
``` ```
Install without starting the service: Install without starting the service:
```bash ```bash
sudo ./install.sh --no-start sudo ./install.sh --install --no-start
``` ```
Uninstall: Uninstall:
+59 -12
View File
@@ -2,12 +2,6 @@
# #
# Install rpi-temp-humid-monitor as a system app with a Python venv. # Install rpi-temp-humid-monitor as a system app with a Python venv.
# #
# Usage:
# sudo ./install.sh # systemd loop daemon (default)
# sudo ./install.sh --cron # cron single-shot mode instead
# sudo ./install.sh --no-start # install only, do not enable/start
# sudo ./install.sh --uninstall # remove installed app files
#
set -euo pipefail set -euo pipefail
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
@@ -25,6 +19,7 @@ LEGACY_DIR="/usr/local/bin/thMonitor"
RUN_MODE="systemd" RUN_MODE="systemd"
DO_START=1 DO_START=1
DO_INSTALL=0
DO_UNINSTALL=0 DO_UNINSTALL=0
APT_PACKAGES=( APT_PACKAGES=(
@@ -46,11 +41,36 @@ PYTHON_MODULES=(
) )
usage() { usage() {
sed -n '3,10p' "$0" | sed 's/^# \?//' local cmd
echo cmd="$(basename "$0")"
echo "Environment overrides:" cat <<EOF
echo " INSTALL_ROOT Install directory (default: ${INSTALL_ROOT})" Install rpi-temp-humid-monitor as a system app with a Python venv.
echo " CONFIG_FILE Config file path (default: ${CONFIG_FILE})"
Usage:
sudo ./$cmd --install [options]
sudo ./$cmd --uninstall
./$cmd --help
Actions:
--install Install the monitor (venv, app files, wrappers, systemd by default)
--uninstall Remove installed app files, wrappers, and services
-h, --help Show this help
Install options:
--cron Use a cron job for single-shot reads instead of the systemd loop
--no-start Install files and unit, but do not enable or start the service
Environment overrides:
INSTALL_ROOT Install directory (default: ${INSTALL_ROOT})
CONFIG_FILE Config file path (default: ${CONFIG_FILE})
LOG_FILE Log file path (default: ${LOG_FILE})
Examples:
sudo ./$cmd --install
sudo ./$cmd --install --cron
sudo ./$cmd --install --no-start
sudo ./$cmd --uninstall
EOF
} }
log() { log() {
@@ -69,8 +89,17 @@ need_root() {
} }
parse_args() { parse_args() {
if [[ $# -eq 0 ]]; then
usage
exit 0
fi
while [[ $# -gt 0 ]]; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--install)
DO_INSTALL=1
shift
;;
--cron) --cron)
RUN_MODE="cron" RUN_MODE="cron"
shift shift
@@ -92,6 +121,21 @@ parse_args() {
;; ;;
esac esac
done done
if [[ "$DO_INSTALL" -eq 1 && "$DO_UNINSTALL" -eq 1 ]]; then
die "Choose either --install or --uninstall"
fi
if [[ "$DO_UNINSTALL" -eq 1 ]]; then
if [[ "$RUN_MODE" == "cron" || "$DO_START" -eq 0 ]]; then
die "--cron and --no-start apply only with --install"
fi
return
fi
if [[ "$DO_INSTALL" -ne 1 ]]; then
die "Specify --install or --uninstall (try --help)"
fi
} }
install_apt_deps() { install_apt_deps() {
@@ -338,6 +382,9 @@ parse_args "$@"
if [[ "$DO_UNINSTALL" -eq 1 ]]; then if [[ "$DO_UNINSTALL" -eq 1 ]]; then
do_uninstall do_uninstall
else elif [[ "$DO_INSTALL" -eq 1 ]]; then
do_install do_install
else
usage
exit 0
fi fi