add more info to index page

This commit is contained in:
b1ek 2024-06-04 10:00:50 +10:00
parent e191afbf1f
commit c5d38c663f
Signed by: blek
GPG Key ID: 14546221E3595D0C
1 changed files with 42 additions and 2 deletions

View File

@ -14,6 +14,8 @@ the problem here is that `curl` might not be installed on second line, but the d
it will result in `data.json` being irreparably deleted and no way to reinstall it
## solution
so generally, you would want to check if the dependencies of your bash script are installed, right?
you could write up something like this and put it in the start:
```sh
@ -23,12 +25,11 @@ if ! command -v curl; then
fi
```
but that's just not reliable and barely maintainable. so that's why i made this thing.
but that's just not reliable and barely maintainable. so that's why i made this thing. it parses your script, and then appends a small snippet at the earliest place in your program that would check if all deps are installed.
you can use it like this:
```sh
# program.sh
#!/usr/bin/env bash
curl https://url.com
```
@ -36,3 +37,42 @@ curl https://url.com
then compile it like that: `bshchk program.sh dist.sh`.
also you can read the script from stdin: `cat program.sh | bshchk - dist.sh`, or get the output to stdout: `bshchk program.sh > dist.sh`
it would output something like this:
```sh
#!/usr/bin/env bash
# This is the runtime dependency checker
# Please do not remove the following lines.
deps=('curl')
non_ok=()
for d in $deps
do
if ! command -v $d > /dev/null 2>&1; then
non_ok+=$d
fi
done
if (( ${#non_ok[@]} != 0 )); then
>&2 echo "RDC Failed!"
>&2 echo " This program requires these commands:"
>&2 echo " > $deps"
>&2 echo " --- "
>&2 echo " From which, these are missing:"
>&2 echo " > $non_ok"
>&2 echo "Make sure that those are installed and are present in \$PATH."
fi
unset non_ok
unset deps
# Dependencies are OK at this point
curl https://url.com
```
---
[website's source code available here](https://git.blek.codes/blek/bshchk.web)