update shcompile
This commit is contained in:
parent
9046aade85
commit
30f089d3ca
2 changed files with 26 additions and 16 deletions
|
|
@ -9,7 +9,14 @@ Resolves '%include' lines with shell capacity"
|
||||||
}
|
}
|
||||||
|
|
||||||
# no arg
|
# no arg
|
||||||
[ $# -lt 1 ] && usage && exit 1
|
unset infile
|
||||||
|
if [ $# -lt 1 ]
|
||||||
|
then
|
||||||
|
if ! [ -t 0 ]
|
||||||
|
then infile=/dev/stdin
|
||||||
|
else usage && exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
[ -z "$TMPDIR" ] && TMPDIR=/tmp
|
[ -z "$TMPDIR" ] && TMPDIR=/tmp
|
||||||
tmpdir="$TMPDIR/shcompile_$(tr -dc '[:alnum:]' < /dev/urandom | head -c10)"
|
tmpdir="$TMPDIR/shcompile_$(tr -dc '[:alnum:]' < /dev/urandom | head -c10)"
|
||||||
|
|
@ -25,23 +32,28 @@ stop()
|
||||||
exit $1
|
exit $1
|
||||||
}
|
}
|
||||||
|
|
||||||
infile=$1
|
[ -z "$infile" ] && infile=$1
|
||||||
|
dirname=$()
|
||||||
[ "$infile" = '-' ] && infile=/dev/stdin
|
[ "$infile" = '-' ] && infile=/dev/stdin
|
||||||
|
|
||||||
cat "$infile" >/dev/null 2>&1 || { echo "Error: cannot read '$infile'" >&2 && stop 2; }
|
# create copy
|
||||||
|
cat "$infile" > "$tmpfile" 2>&1 || { echo "Error: cannot read '$infile'" >&2 && stop 2; }
|
||||||
|
|
||||||
|
# env when file
|
||||||
|
[ "$infile" != "/dev/stdin" ] && {
|
||||||
|
echo "$(readlink -f "$infile")" > "$filelist"
|
||||||
|
cd "$(dirname "$infile")"
|
||||||
|
}
|
||||||
|
|
||||||
|
firstline=$(head -n1 "$tmpfile" | grep '^#!/')
|
||||||
|
|
||||||
firstline=$(head -n1 "$infile" | grep '^#!/')
|
|
||||||
[ -z "$firstline" ] && firstline='#!/bin/sh'
|
[ -z "$firstline" ] && firstline='#!/bin/sh'
|
||||||
|
|
||||||
cp "$infile" "$tmpfile"
|
|
||||||
|
|
||||||
get_include_line()
|
get_include_line()
|
||||||
{
|
{
|
||||||
grep -m1 -n '^%include ' "$1" | cut -d':' -f1
|
grep -m1 -n '^%include ' "$1" | cut -d':' -f1
|
||||||
}
|
}
|
||||||
|
|
||||||
echo "$1" > "$filelist"
|
|
||||||
|
|
||||||
n=$(get_include_line "$tmpfile")
|
n=$(get_include_line "$tmpfile")
|
||||||
while [ -n "$n" ]
|
while [ -n "$n" ]
|
||||||
do
|
do
|
||||||
|
|
@ -53,12 +65,13 @@ do
|
||||||
cp "$headfile" "$tmpfile"
|
cp "$headfile" "$tmpfile"
|
||||||
echo "$inc" | while read -r file
|
echo "$inc" | while read -r file
|
||||||
do
|
do
|
||||||
cat "$file" >/dev/null 2>&1 || { echo "Error when trying to include '$incarg': '$ln' could not be read" >&2 && stop 10; }
|
cat "$file" >/dev/null 2>&1 || { echo "Error when trying to include '$incarg': '$file' could not be read" >&2 && stop 10; }
|
||||||
if ! grep -q "^$file\$" "$filelist"
|
if ! grep -q "^$(readlink -f "$file")\$" "$filelist"
|
||||||
then # not already included
|
then # not already included
|
||||||
cat "$file" >> "$tmpfile"
|
cat "$file" >> "$tmpfile"
|
||||||
echo "$file" >> "$filelist"
|
echo "$(readlink -f "$file")" >> "$filelist"
|
||||||
fi
|
fi
|
||||||
|
cd "$pwd"
|
||||||
done
|
done
|
||||||
cat "$tailfile" >> "$tmpfile"
|
cat "$tailfile" >> "$tmpfile"
|
||||||
# get next include line
|
# get next include line
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,10 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
# ordered requirements
|
# ordered requirements
|
||||||
%include src/util.sh
|
%include util.sh env.sh options.sh config.sh
|
||||||
%include src/env.sh
|
|
||||||
%include src/options.sh
|
|
||||||
%include src/config.sh
|
|
||||||
|
|
||||||
# everything else
|
# everything else
|
||||||
%include src/*.sh
|
%include *.sh
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
list) awk '{print $1}' "$PKG_PATH/installed" 2>/dev/null | sort ;;
|
list) awk '{print $1}' "$PKG_PATH/installed" 2>/dev/null | sort ;;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue