summaryrefslogtreecommitdiff
path: root/src/util.sh
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2022-02-20 00:40:00 +0000
committerdavidovski <david@davidovski.xyz>2022-02-20 00:40:00 +0000
commit65940c0cc719311fbac5e11c81cce34563ea3f21 (patch)
tree96a3aae8d7ef396720e41a64091b8c333ab28f18 /src/util.sh
parent290a33eacff1ed98d0e571cc1d5550cac3d9f276 (diff)
all works with posix shell
Diffstat (limited to 'src/util.sh')
-rw-r--r--src/util.sh46
1 files changed, 27 insertions, 19 deletions
diff --git a/src/util.sh b/src/util.sh
index d20db86..82d26ca 100644
--- a/src/util.sh
+++ b/src/util.sh
@@ -4,31 +4,39 @@ download_file() {
curl ${CURL_OPTS} -o $1 -w "%{http_code}" $2 2> /dev/null
}
+# this function is broken
wait_for_jobs () {
+ local text=$1
+ local end=$2
+ shift 2
+ joblist="-e $(echo $@ | sed "s/ / -e /g")"
+
+ echo "$joblist"
+
if ! $QUIET; then
- local total=$(jobs -r | wc -l)
+ local total=$#
local completed=0
while [ "$completed" != "$total" ]; do
- completed=$(( $total - $(jobs -r | wc -l)))
- hbar -T "$1" $completed $total
+ running=$(ps aux | grep $joblist | wc -l)
+
+ completed=$(( $total - $running + 1))
+ hbar -T "$text" $completed $total
done
- hbar -t ${HBAR_COMPLETE} -T "$2" $completed $total
+ hbar -t ${HBAR_COMPLETE} -T "$end" $completed $total
fi
wait
}
wait_for_download () {
- if ! $QUIET && [ "$(jobs -r | wc -l)" != "0" ]; then
+ if ! $QUIET; then
local total_download=$1
shift
- local files=($@)
- unset downloaded
- while [ "$(jobs -r | wc -l)" != "0" ]; do
- local downloaded=0
+ local downloaded=0
+ while [ "$downloaded" -lt "$total_download" ]; do
- for output in ${files[*]}; do
+ for output in $@; do
size=$(stat -c %s $output)
downloaded=$((downloaded+size))
done
@@ -42,18 +50,19 @@ wait_for_download () {
}
wait_for_extract () {
- if ! $QUIET && [ "$(jobs -r | wc -l)" != "0" ]; then
+ if ! $QUIET; then
local total_filecount=$1
+ local extracted=0
shift
- local files=($@)
- unset extracted
- while [ "$(jobs -r | wc -l)" != "0" ]; do
+ while [ "$extracted" -lt "$total_filecount" ]; do
local extracted=0
- for output in ${files[*]}; do
- size=$(cat $output | wc -l)
- extracted=$((extracted+size))
+ for output in $@; do
+ if [ -f $output ]; then
+ size=$(cat $output | wc -l)
+ extracted=$((extracted+size))
+ fi
done
hbar -T " extracting files" $extracted $total_filecount
@@ -64,7 +73,6 @@ wait_for_extract () {
wait
}
-
format_bytes () {
echo $@ | numfmt --to iec
@@ -74,5 +82,5 @@ prompt_question () {
$NOCONFIRM && return 0
printf "$1 [Y/n] "
read response
- [ "${response:0}" != "n" ]
+ [ "${var%${var#?}}"x != 'nx' ]
}