Fix setup.py: use download-then-run instead of pipe to avoid EOF error
This commit is contained in:
parent
30e47bddb7
commit
59aa5544e9
15
Readme.md
15
Readme.md
@ -26,20 +26,11 @@ Open Termux and run:
|
|||||||
# Grant storage access
|
# Grant storage access
|
||||||
termux-setup-storage
|
termux-setup-storage
|
||||||
|
|
||||||
# Install Python
|
# Install Python and download setup
|
||||||
pkg update -y && pkg install -y python
|
pkg update -y && pkg install -y python
|
||||||
|
mkdir -p ~/scripts && curl -sL https://git.olli.info/Oliver/GadgetbridgeMqtt/raw/branch/main/setup.py -o ~/scripts/setup.py
|
||||||
|
|
||||||
# Download and run setup
|
# Run setup (interactive)
|
||||||
curl -sL https://git.olli.info/Oliver/GadgetbridgeMqtt/raw/branch/main/setup.py | python
|
|
||||||
```
|
|
||||||
|
|
||||||
Or step-by-step:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
termux-setup-storage
|
|
||||||
pkg update -y && pkg install -y python wget
|
|
||||||
mkdir -p ~/scripts
|
|
||||||
wget -O ~/scripts/setup.py https://git.olli.info/Oliver/GadgetbridgeMqtt/raw/branch/main/setup.py
|
|
||||||
python ~/scripts/setup.py
|
python ~/scripts/setup.py
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
32
setup.py
32
setup.py
@ -31,19 +31,7 @@ def get_input(prompt, default=None, required=True):
|
|||||||
else:
|
else:
|
||||||
prompt = f"{prompt}: "
|
prompt = f"{prompt}: "
|
||||||
|
|
||||||
try:
|
|
||||||
value = input(prompt).strip()
|
value = input(prompt).strip()
|
||||||
except EOFError:
|
|
||||||
# Non-interactive environment (e.g. piped via curl | python)
|
|
||||||
# Return default when provided, otherwise raise a clear error
|
|
||||||
if default is not None:
|
|
||||||
return default
|
|
||||||
raise RuntimeError(
|
|
||||||
"No stdin available for interactive input.\n"
|
|
||||||
"Provide configuration via environment variables or run setup.py interactively.\n"
|
|
||||||
"Example (non-interactive):\n"
|
|
||||||
" MQTT_BROKER=1.2.3.4 MQTT_PORT=1883 \\n+ MQTT_USERNAME=user MQTT_PASSWORD=pass \\n+ EXPORT_DIR=/storage/emulated/0/Documents/GB_Export \\n+ PUBLISH_INTERVAL=300 \\n+ curl -sL https://git.olli.info/Oliver/GadgetbridgeMqtt/raw/branch/main/setup.py | python"
|
|
||||||
)
|
|
||||||
|
|
||||||
if not value and default:
|
if not value and default:
|
||||||
return default
|
return default
|
||||||
@ -73,26 +61,6 @@ def setup_mqtt():
|
|||||||
return config
|
return config
|
||||||
|
|
||||||
|
|
||||||
def load_noninteractive_config_from_env():
|
|
||||||
"""Load configuration from environment variables when stdin is not a TTY.
|
|
||||||
|
|
||||||
Required: MQTT_BROKER
|
|
||||||
Optional: MQTT_PORT, MQTT_USERNAME, MQTT_PASSWORD, EXPORT_DIR, PUBLISH_INTERVAL
|
|
||||||
"""
|
|
||||||
cfg = {}
|
|
||||||
broker = os.environ.get("MQTT_BROKER")
|
|
||||||
if not broker:
|
|
||||||
return None
|
|
||||||
|
|
||||||
cfg["mqtt_broker"] = broker
|
|
||||||
cfg["mqtt_port"] = int(os.environ.get("MQTT_PORT", "1883"))
|
|
||||||
cfg["mqtt_username"] = os.environ.get("MQTT_USERNAME", "")
|
|
||||||
cfg["mqtt_password"] = os.environ.get("MQTT_PASSWORD", "")
|
|
||||||
cfg["export_dir"] = os.environ.get("EXPORT_DIR", DEFAULT_EXPORT_DIR)
|
|
||||||
cfg["publish_interval"] = int(os.environ.get("PUBLISH_INTERVAL", str(DEFAULT_INTERVAL)))
|
|
||||||
return cfg
|
|
||||||
|
|
||||||
|
|
||||||
def save_config(config):
|
def save_config(config):
|
||||||
"""Save configuration to file"""
|
"""Save configuration to file"""
|
||||||
os.makedirs(CONFIG_DIR, exist_ok=True)
|
os.makedirs(CONFIG_DIR, exist_ok=True)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user