How to: Automatic Install with helper script (Recommended For less techy people)
> [!IMPORTANT]
> This script is for initial setup only. if you already have used it or followed the manual setup to deploy this project, you should not run this again once the garminconnect OAuth tokens are saved (first successful data fetch). Please check the `update to new versions` section for upgrading the container(s).

> [!TIP]
> If you are getting some errors you can't figure out, give the almighty [ChatGPT](https://chat.openai.com/) a try, it's often known to be helpful troubleshooting issues with this project and script.

This script requires a linux environment. If Docker is not installed on your Linux/MacOS system, follow the instructions to [install docker manually](https://docs.docker.com/engine/install/) on Linux. There is also an [automated docker installation script](https://github.com/docker/docker-install) available using the one-liner command `curl -fsSL https://get.docker.com -o get-docker.sh && sh get-docker.sh`.

If you are on `Windows` you should consider using [WSL](https://learn.microsoft.com/en-us/windows/wsl/install) to get a linux sub-system up and running.

#### Detailed steps for Windows users are as follows:

- [Install docker desktop](https://docs.docker.com/get-started/introduction/get-docker-desktop/)
- Install `WSL` and `Ubuntu` from the Microsoft Store
- Start -> Run -> type `WSL.exe`, Follow the prompts to create your Linux sudo (admin) user and password. This password will be required for later steps.
- Open docker desktop and agree to the EULA
- Reboot your machine (important)
- Once back up, WSL and Docker should be installed and linked together.
- Start -> Run -> type `WSL.exe`, then run the below bash command in the terminal window.

For Linux or MacOS, simply run the following bash command from your linux command line (terminal).

> [!NOTE]
> If you get the error that `git : command not found` then you need to install `git` with the command `sudo apt install git` for Ubuntu/Debian/WSL(windows) based systems. For Mac, you need to use `brew install git`. If you are on a non-debian linux distribution, please use your OS specific package manager replacing `apt`.

Use the following command to clone this repository to your local machine

```bash
cd ~ && git clone https://github.com/arpanghosh8453/garmin-grafana.git garmin-grafana
```
Use the command next to install it automatically using the easy-install script. If it fails because docker was not installed, retry the command again after installing docker. 

```bash
cd garmin-grafana && sudo bash ./easy-install.sh
```

Enter the Garmin Connect credentials when prompted and you should be all up and running (you will be prompted for 2FA code as well if you have that set up). Once the data keeps coming, you can check out the `http://localhost:3000` to reach Grafana (by default), do the initial setup with the default username `admin` and password `admin`. Check out the dashboards link on the left sidebar. you should have a dashboard auto-configured as `Garmin-Stats` under the dashboards section. There you should see the data added. It will **keep updating automatically** as soon as new data syncs with your Garmin Connect account.

> [!NOTE]
> When you run this for the first time, it will only automatically fetch the data for **last 7 days** only and keep pulling new data that syncs with Garmin Connect moving forward. if you want to sync your older data, that is super easy to do. You just need to run the following command in the terminal (`WSL` for windows) replacing the YYYY-MM-DD with appropriate start and end dates (MANUAL_START_DATE value must be older than MANUAL_END_DATE value)
>
> ```bash
> cd ~/garmin-grafana && docker compose run --rm -e MANUAL_START_DATE=YYYY-MM-DD -e MANUAL_END_DATE=YYYY-MM-DD garmin-fetch-data
> ```

That should be everything you need for now! The script will be running in the background as long as your machine is up. After a restart, make sure to open docker desktop if you are on windows (if it does not start automatically) so that the containers get booted up as well. For Linux, everything should restart reliably after a reboot. If you are having issues, make sure the docker daemon is running and check the container status with `docker ps` command