## Getting files

An example client to access files from this package server is available
as bash script (using curl).

See deployment project <https://git-repo.iml.unibe.ch/iml-open-source/imldeployment-client>

The download script is bin/getfile.sh.

```text
wget -O getfile.sh "https://git-repo.iml.unibe.ch/iml-open-source/imldeployment-client/-/raw/master/bin/getfile.sh?ref_type=heads"
chmod 755 getfile.sh
```

## How does it work?

TODO: needs to be completed.

Each request to localhost/packages/ is secured.

A request will be rejected in the following cases:

* no authentication was used
* a wrong authentication was used
* an old timestamp was used (maybe the time on client or server are not synced)
* a hashed key was used twice

If a request was OK the file will be delivered.

Possible GET requests are:

* show names of phases (preview|stage|live) (1)
* show products (1)
* show files of a product (1)
* get a single file

(1) only if *showdircontent* is set to true.

If a valid request came in then the hash will be written to `[approot]/tmp/used_hashes.txt`.
This file will be cleaned up if reaching the defined file size with value of *maxlockfilesize*.

## Test package download

If you use the docker environment for development:

In your app root you there is a folder "example-packages". Inside the docker container it is available as /var/www/ci-pkg/example-packages/.

* Below the package folder folders are subfolders for phases (preview, stage, live and "test").
* below a phase are the folders with the project id
* inside the project folder are the files per project

```text
example-packages/
├── live
├── preview
├── stage
└── test
    └── example-prj
        └── hello.txt
```

In your app root go to the the "tests" folder.
This will download the "hello.txt" into the current folder:

```txt
./getfile.sh -u http://localhost:8001 -s myapikey -e test -p example-prj -f hello.txt
-rw-r--r-- 1 axel axel 1152 Sep 15 14:34 hello.txt
```

For less params with getfile.sh there is a config:

```txt
cat getfile.sh.cfg
# for less params with getfile.sh
IMLCI_PKG_SECRET=myapikey
IMLCI_URL=http://localhost:8001
IMLCI_PHASE=test
```

With it you can execute ``./getfile.sh -p example-prj -f hello.txt`` too.

If you enabled the file listing you get a list of files:

```txt
./getfile.sh -p example-prj
file:hello.txt
```

## Troubleshooting

To have more output you have these possibilities:

* in the command with ./getfile.sh add the flag ``-d`` to enable debugging for this script
* in public_html/inc_config.php set the key debug to enable the debugging on server (disable it as soon you can)