Add a number of common bash functions to use across scripts. Including log, which is under development.
This commit is contained in:
parent
ea86049947
commit
f541a2d2db
46
common.sh
46
common.sh
|
@ -1,5 +1,31 @@
|
|||
#!/bin/bash
|
||||
|
||||
if [ -f ".env" ]; then
|
||||
source .env
|
||||
fi
|
||||
|
||||
if [[ "${DB_FILE}" != "" ]]; then
|
||||
FULL_DATABASE=`realpath "${DB_FILE}"`
|
||||
else
|
||||
FULL_DATABASE=`realpath "./draw.sqlite"`
|
||||
fi
|
||||
|
||||
db () {
|
||||
sqlite3 "${FULL_DATABASE}" "${1}"
|
||||
}
|
||||
|
||||
dbSetup () {
|
||||
cat "./sql/setup.sql" | sqlite3 "${FULL_DATABASE}"
|
||||
}
|
||||
|
||||
hashStr () {
|
||||
echo -n "${1}" | sha256sum | awk '{print $1}'
|
||||
}
|
||||
|
||||
uuid () {
|
||||
uuidgen | tr "[:upper:]" "[:lower:]"
|
||||
}
|
||||
|
||||
askContinue () {
|
||||
echo "${1}"
|
||||
echo "Are you ready to continue? (yes/no)"
|
||||
|
@ -10,4 +36,24 @@ askContinue () {
|
|||
else
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
log () {
|
||||
read loglines
|
||||
file=$(echo "${loglines}" | grep 'FILE:' | awk -F'FILE:' '{print $2}')
|
||||
drawn=$(echo "${loglines}" | grep 'Length of path drawn' | awk -F': ' '{print $2}' | awk '{print $1}')
|
||||
moved=$(echo "${loglines}" | grep 'Total distance moved' | awk -F': ' '{print $2}' | awk '{print $1}')
|
||||
#echo "${loglines}"
|
||||
echo "$file,$drawn,$moved"
|
||||
}
|
||||
|
||||
axdraw () {
|
||||
file=$(realpath "${1}")
|
||||
echo "FILE:${file}"
|
||||
if [[ "${PEN}" != "" ]]; then
|
||||
echo "PEN:${PEN}"
|
||||
fi
|
||||
echo "START:$(date '+%s')"
|
||||
ax "${1}"
|
||||
echo "END:$(date '+%s')"
|
||||
}
|
Loading…
Reference in New Issue