summaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authordavidovski <david@davidovski.xyz>2026-10-01 10:34:33 +0100
committerdavidovski <david@davidovski.xyz>2026-10-01 10:34:33 +0100
commiteca55e60c29440c4e2e007b54ea1a1983e965954 (patch)
treea98173c09f69864cc25395bfdab67d682434854b /src/util
parentf20bd9d6369c2e1246dcdd4af26b085da99c18e0 (diff)
Add libhbar to shmkHEADmaster
Diffstat (limited to 'src/util')
-rwxr-xr-xsrc/util/hbar.sh104
-rw-r--r--src/util/parseconf.sh42
-rw-r--r--src/util/shmk/shmk.README (renamed from src/util/shmk.README)12
-rwxr-xr-xsrc/util/shmk/shmk.sh (renamed from src/util/shmk.sh)52
4 files changed, 71 insertions, 139 deletions
diff --git a/src/util/hbar.sh b/src/util/hbar.sh
index 9518e66..230ff5d 100755
--- a/src/util/hbar.sh
+++ b/src/util/hbar.sh
@@ -1,108 +1,6 @@
#!/bin/mksh -U
-#include colors
-#include xilib
-move_up () {
- [ ! "$1" = "0" ] &&
- printf "\033[%dA" "$1" "0"
-}
-
-move_down () {
- [ ! "$1" = "0" ] &&
- printf "\033[%dB" "$1"
-}
-
-count_string () {
- local c t
- $human && {
- c=$(format_bytes $completed)
- t=$(format_bytes $total)
- } || {
- c=$1
- t=$2
- }
- printf "[%s/%s]" $c $t
-}
-
-hbar () {
- local width terminate human text color reset unit line count
- width=$(tput cols)
- color="$BLACK$BG_WHITE"
- reset="$WHITE$BG_DEFAULT"
- terminate=false
- human=false
- line=0
-
- while getopts "T:c:r:u:l:ht" opt; do
- case "$opt" in
- T)
- text="$OPTARG"
- ;;
- c)
- color="$OPTARG"
- ;;
- r)
- reset="$OPTARG"
- ;;
- u)
- unit="$OPTARG"
- ;;
- t)
- terminate=true
- ;;
- h)
- human=true
- ;;
- l)
- line="$OPTARG"
- ;;
- esac
- done
-
- shift $((OPTIND-1))
-
- [ "$#" -lt 2 ] && {
- return 1
- }
-
- completed="$1"
- total="$2"
-
- move_up $line
-
- count=$(count_string $completed $total)
- #printf "\r$text"
- printf "$RESET\r"
- printf "$color"
-
- reset_at=0
- [ "$total" -gt "0" ] && reset_at=$(((completed*width)/total))
-
- i=0
- while [ "$i" -lt "$width" ]; do
- [ "$i" = "$reset_at" ] && printf "$reset"
-
- [ "${#text}" -gt 0 ] && {
- printf "%s" "${text%%${text#?}}"
- text="${text#?}"
- } || {
- [ "$((width-${#count}))" = "$i" ] && {
- printf "%s" "${count%%${count#?}}"
- count="${count#?}"
- } || {
- printf " "
- }
- }
- i=$((i+1))
- done
-
- move_down $line
-
- printf "$RESET"
- $terminate && printf "\n"
-
- exit 0
-}
+#include libhbar
[ "$#" -eq "0" ] && {
printf "$RESET\n"
diff --git a/src/util/parseconf.sh b/src/util/parseconf.sh
index d215a99..17cb0ce 100644
--- a/src/util/parseconf.sh
+++ b/src/util/parseconf.sh
@@ -1,37 +1,37 @@
#!/bin/sh
usage () {
- printf "Usage $0 "
- echo << "EOF"
+printf "Usage $0 "
+echo << "EOF"
OPTIONS... [FILTER]
Print the parsed config file filtering by the keys
Arguments:
- -f file read configuration from a file, uses /dev/sdtin otherwise
- -v only print values
- -c n print the last [n]
+-f file read configuration from a file, uses /dev/sdtin otherwise
+-v only print values
+-c n print the last [n]
EOF
}
# parse a single config file line
#
parse_line() {
- [ "$#" = 0 ] && return
-
- local line="$@"
- local key=$1
-
- shift
- local value="$@"
- value=${value%#*}
-
- case $key in
- "include")
- cat $value | parse
- return
- ;;
- "]")
- IFS=.
+[ "$#" = 0 ] && return
+
+local line="$@"
+local key=$1
+
+shift
+local value="$@"
+value=${value%#*}
+
+case $key in
+ "include")
+ cat $value | parse
+ return
+ ;;
+ "]")
+ IFS=.
set -- $list
list="${*%${!#}}"
IFS=" "
diff --git a/src/util/shmk.README b/src/util/shmk/shmk.README
index a359fbc..43671ac 100644
--- a/src/util/shmk.README
+++ b/src/util/shmk/shmk.README
@@ -116,6 +116,14 @@ This feature is intended to be used with the `shtests` tool.
## Syntax and formatting
-shmk is intended to be as portable as possible, following exclusively POSIX shell syntax. This means that unlike in bash or csh, there is no formal structure for lists, instead whitespace separated strings are used. New lines or spaces both work, however for the sake of simplicity, newlines are prefered. The "standard" shmk syntax for a list is as follows
-`
+### shell features
+
+shmk is intended to be as portable as possible, following exclusively POSIX shell syntax. This means that unlike in bash or csh, there is no formal structure for lists, instead whitespace separated strings are used. New lines or spaces both work, however for the sake of simplicity, newlines are prefered.
+
+### env vars
+
+shmk exposes a few different environment variables in the build environment (ie to be used in custom build stages):
+
+- `${DIST}` - temporary "out" directory where libraries and binaries are placed.
+- `${PREFIX}` - where things will be installed
diff --git a/src/util/shmk.sh b/src/util/shmk/shmk.sh
index b4c040d..be5f00b 100755
--- a/src/util/shmk.sh
+++ b/src/util/shmk/shmk.sh
@@ -1,8 +1,9 @@
#!/bin/sh
-#
+#
# A tool to build a single executable from a collection of shell scripts
#include colors
+#include libhbar
PREFIX=${PREFIX:-/usr}
@@ -18,13 +19,15 @@ EOF
# _find_file filename
#
_find_file () {
- for p in $search_path; do
- for f in $p/$1.sh $p/$1; do
+ for p in $search_path; do
+ for f in $p/$1.sh $p/$1; do
$verbose \
&& printf "${LIGHT_BLACK}checking: $f\n" 1>&2
[ -f "$f" ] && {
- echo "$f"
+ $verbose \
+ && printf "${LIGHT_BLACK}found: $f for $1\n" 1>&2
+ echo "$f"
return 0
}
done
@@ -50,7 +53,10 @@ _parse_lines () {
# if we have already included this file, do not parse it
case "$included" in
- *"$file"*) ;;
+ *"$file"*)
+ $verbose \
+ && printf "${LIGHT_BLACK}already included $file, won't include twice\n" 1>&2
+ ;;
*)
cat $file | _parse_lines
included="$included $file"
@@ -103,15 +109,19 @@ interpret_shmk () {
. $1
local cmdlist=""
+ ## TODO override if already set
DIST="./dist"
- PROGS="$PROGS $(sed -rn "s/^prog_(.*)\s*\(\)\s*\{/\1/p" $1)"
- LIBS="$LIBS $(sed -rn "s/^lib_(.*)\s*\(\)\s*\{/\1/p" $1)"
- CHECKS="$CHECKS $(sed -rn "s/^check_(.*)\s*\(\)\s*\{/\1/p" $1)"
+ BUILDS="$(sed -rn "s/^build_(.*)\s*\(\)\s*\{/\1/p" $1) $BUILDS"
+ PROGS="$(sed -rn "s/^prog_(.*)\s*\(\)\s*\{/\1/p" $1) $PROGS "
+ LIBS="$(sed -rn "s/^lib_(.*)\s*\(\)\s*\{/\1/p" $1) $LIBS"
+ CHECKS="$(sed -rn "s/^check_(.*)\s*\(\)\s*\{/\1/p" $1) $CHECKS"
shift
- [ -z "$1" ] && set -- clean build check install
+ [ -z "$1" ] && set -- clean build check
while [ ! -z "$1" ]; do
case "$1" in
+ # install programs and libraries to system
+ #
install)
for prog in $PROGS; do
prog=$(basename $prog)
@@ -126,6 +136,9 @@ interpret_shmk () {
install -Dm755 $DIST/$lib ${DESTDIR}/${PREFIX}/lib/$lib.sh #Install library $lib"
done
;;
+
+ # install programs and libraries to system
+ #
uninstall)
for prog in $PROGS; do
prog=$(basename $prog)
@@ -140,16 +153,19 @@ interpret_shmk () {
rm $DIST/$lib ${DESTDIR}/${PREFIX}/lib/$lib.sh #Uninstall library $lib"
done
;;
+
clean)
[ -d "$DIST" ] && cmdlist="$cmdlist
rm -r $DIST #Clean"
;;
+
check)
for check in $CHECKS; do
command -v check_$check > /dev/null 2>&1 && cmdlist="$cmdlist
check_$check #Check $check"
done
;;
+
*) # build all programs
search_path="$DIST $search_path"
@@ -185,7 +201,15 @@ interpret_shmk () {
i=-1
echo "$cmdlist" | while read -r cmd; do
i=$((i+1))
- printf "${LIGHT_BLACK}[${LIGHT_BLUE}%s${LIGHT_BLACK}/${LIGHT_BLUE}%s${LIGHT_BLACK}] ${LIGHT_WHITE}%s${RESET}%s" "$i" "$len" "${cmd#*#}" "$($verbose && printf "\n" || printf "\r")"
+ outstring="$(printf "${LIGHT_BLACK}[${LIGHT_BLUE}%s${LIGHT_BLACK}/${LIGHT_BLUE}%s${LIGHT_BLACK}] ${LIGHT_WHITE}%s" \
+ "$i" "$len" "${cmd#*#}")"
+
+ printf "\r%s\r" "${outstring}" #"$($verbose && printf "\n\n" || printf "\n")"
+ if ! $verbose && command -v hbar > /dev/null 2>&1; then
+ printf "\n"
+ hbar -l 1 -r "${RESET}" -c "${BG_BLUE}" -n "$i" "$len"
+ fi
+
${cmd%#*} 2>&1 > $out || {
printf "\n${RED}Error $?\n"
exit 1
@@ -213,7 +237,7 @@ clean=false
}
while getopts ":e:I:o:chv" opt; do
- case "${opt}" in
+ case "${opt}" in
e)
entry_function="$OPTARG"
;;
@@ -224,8 +248,10 @@ while getopts ":e:I:o:chv" opt; do
clean=true
;;
I)
- search_path="$OPTARG
- $search_path"
+ search_path="
+ $OPTARG
+ $search_path
+ "
;;
v)
verbose=true