Skip to content
Draft
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
/.bicycledata
/.env/
/*.log
/config.json
/sensors/
/sessions/
/temp/

__pycache__/

/.lgd-nfy0
/.no-shutdown
/bicycleinit.json
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2024 bicycledata
Copyright (c) 2024-2025 bicycledata

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
73 changes: 2 additions & 71 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,76 +1,7 @@
# BicycleInit

This repository contains the `bicycleinit.sh` script, which is used
for managing and configuring a bicycledata box. The script performs
the following tasks:

1. **Update the script**: Checks for updates to the repository and
applies them.
2. **Device registration**: Registers the device with a server if it
hasn't been registered before.
3. **Configuration update**: Retrieves and updates the configuration
file (`config.json`) based on the device's registration
information.

## Prerequisites

Before using the script, ensure that the following dependencies are
installed on your Raspberry Pi:

- **Git**: For fetching and pulling updates from the repository.
- **jq**: A lightweight command-line JSON processor for parsing JSON
responses from the server.
- **curl**: For sending HTTP requests to the REST API.

You can install these dependencies using the following commands:

```bash
sudo apt-get update
sudo apt-get install git jq curl
```

## Clone the Repository

Prior to running `bicycleinit.sh`, make sure you clone this repository
and run the script from within the cloned directory. The script
assumes that it is located inside a Git repository with the `origin`
remote set to
[`https://github.com/bicycledata/bicycleinit.git`](https://github.com/bicycledata/bicycleinit.git).

## Usage

The `bicycleinit.sh` script accepts two optional arguments:

1. **Branch name**: The Git branch to check for updates. Defaults to
`'main'`.
2. **Server REST API URL**: The base URL for the server's REST API.
Defaults to `'https://bicycledata.vti.se/api'`.

### Running the Script

To run the script with default parameters, use:

```bash
./bicycleinit.sh
```

To specify a different branch or API URL, you can pass them as
arguments:

```bash
./bicycleinit.sh [branch_name] [server_rest_api_url]
```

### Example:

```bash
./bicycleinit.sh develop 127.0.0.1:5000
```

This command will check for updates on the `develop` branch and use
the specified REST API URL.
This repository contains the `bicycleinit.py` script and supporting modules for managing and configuring a bicycledata box.

## License

This project is licensed under the MIT License - see the
[LICENSE](LICENSE) file for details.
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
6 changes: 6 additions & 0 deletions bicycleinit-default.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"server": "https://bicycledata.vti.se",
"wifi": {
"bicycledata": "bicycledata"
}
}
24 changes: 24 additions & 0 deletions bicycleinit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import logging
import os
import traceback

from bicycleinit.device import BicycleDevice

def main():
device = BicycleDevice()
try:
device.main()
except Exception as e:
logging.error(f"An unexpected error occurred: {e}")
logging.error(traceback.format_exc())
finally:
logging.shutdown()
if device._restart:
return
if os.path.exists('.no-shutdown'):
logging.info("'.no-shutdown' file found, skipping shutdown.")
return
os.system("sudo shutdown now")

if __name__ == '__main__':
main()
185 changes: 0 additions & 185 deletions bicycleinit.sh

This file was deleted.

Loading