touch ctl.sh
chmod +x ctl.sh
./ctl.sh
# asdf would be file in data dir
./ctl.sh run:file asdf
-
-
Save suiluj/a1fa0df9e80e1a685112a2c7f5407a8a to your computer and use it in GitHub Desktop.
ctl.sh simple version
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NOTUSED=1234 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NOTUSED=1234 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.env |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# get env vars from .env file: https://stackoverflow.com/a/30969768 | |
# use check for .env file first | |
FILE=".env" | |
if [ -f "$FILE" ]; then | |
### Take action if $DIR exists ### | |
# echo "Found file: ${FILE}. Will add environment variables." | |
set -o allexport; source .env; set +o allexport | |
else | |
### Control will jump here if $FILE does NOT exists ### | |
echo -e "Error: ${FILE} not found. Can not continue.\ncreate some .env file with environment variables next to this bash file ctl.sh\nIn case you do not use any env just copy .env.sample or create a file .env with NOTUSED=1234" | |
exit 1 | |
fi | |
set -eo pipefail | |
DC="${DC:-exec}" | |
# old env method not used because better method above | |
## set env vars from .env file (like SSH_HOST) | |
#export $(grep -v '^#' .env | xargs -d '\n') | |
# If we're running in CI we need to disable TTY allocation for docker-compose | |
# commands that enable it by default, such as exec and run. | |
TTY="" | |
if [[ ! -t 1 ]]; then | |
TTY="-T" | |
fi | |
function run:file { | |
if [ ! -f data/$1 ] | |
then | |
echo "File does not exist in Bash" | |
exit 1 | |
fi | |
export FILE_PATH=/data/$1 | |
cargo run | |
} | |
function help { | |
printf "%s <task> [args]\n\nTasks:\n" "${0}" | |
compgen -A function | grep -v "^_" | cat -n | |
printf "\nExtended help:\n Each task has comments for general usage\n" | |
} | |
# This idea is heavily inspired by: https://github.com/adriancooney/Taskfile | |
TIMEFORMAT=$'\nTask completed in %3lR' | |
time "${@:-help}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment