New commits:
commit dcaf96986b54ba37eeff3fe0b5642f67700581f0
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>
Avoid eval of AWK output, and improve AWK code
commit b30979fb7c8b52aaf52e0898cff76dc7ba5360bf
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>
cleanse: Optimize pass three, merge second sed command into the first
commit 48b21f2eb9df2a0558a981530135e11d48dc32db
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>
Improve some AWK code
commit 9d04280be54f1ca1af55a06696696f38e22d56fb
Author: Ismael Luceno <ismael AT sourcemage.org>
Commit: Ismael Luceno <ismael AT sourcemage.org>
cast: Simplify pass_two process killing step
diff --git a/usr/sbin/cabal b/usr/sbin/cabal
index c056a7b..0e6973b 100755
--- a/usr/sbin/cabal
+++ b/usr/sbin/cabal
@@ -1,7 +1,7 @@
#!/bin/bash
#---------------------------------------------------------------------
## @Synopsis A set of functions for the Cabal distributed administration
system.
-## @Copyright Copyright 2002 by the Source Mage Team. Some parts Copyright
2001 by Kyle Sallee
+## @Copyright Copyright 2002, 2014 by the Source Mage Team. Some parts
Copyright 2001 by Kyle Sallee
## Control a set of SourceMage boxes on a network. This documentation was
## written by someone who never used cabal or looked at this code before.
##
@@ -17,11 +17,12 @@ function read_cabal_names() {
+ awk '{ print n++, $0 }' "$CABAL_NAMES" |
+ while read v name; do
+ CABALS[$v]="$name"
+ done
}
#--------------------
diff --git a/usr/sbin/cast b/usr/sbin/cast
index 44a656b..36ce894 100755
--- a/usr/sbin/cast
+++ b/usr/sbin/cast
@@ -3,7 +3,7 @@
## @Synopsis cast is the spell installation utility. It can be called by the
user or by sorcery
## @Copyright Original version Copyright 2001 by Kyle Sallee
## @Copyright Some parts copyright 2002 Anders Bruun Olsen et al
-## @Copyright Other additions/corrections Copyright 2002 by the Source Mage
Team
+## @Copyright Other additions/corrections Copyright 2002, 2014 by the Source
Mage Team
## Script to cast spells.
#---------------------------------------------------------------------
@@ -474,14 +474,13 @@ function pass_two() {
let i+=5
if [[ $i -gt 60 ]] ; then
message "Download pass did not finish, killing it off."
- # this is rather violent, but job control in bash lame and theres
+ # this is rather violent, but job control in bash lame and there's
# no other way to kill everything off effectively :-(
- ps x|grep $TMP_DIR|awk '{print $1}'|grep -v $$|xargs kill &>/dev/null
- echo -n .; sleep 1
- ps x|grep $TMP_DIR|awk '{print $1}'|grep -v $$|xargs kill &>/dev/null
- echo -n .; sleep 1
- ps x|grep $TMP_DIR|awk '{print $1}'|grep -v $$|xargs kill -9
&>/dev/null
- echo -n .; sleep 1
+ pids="`ps x | awk -v t="$TMP_DIR" -v p=$$ -- '$0 ~ t && $1 != p {print
$1}'`"
+ for i in '' '' -9; do
+ kill $i $pids >/dev/null 2>&1
+ echo -n .; sleep 1
+ done
echo
break
fi
diff --git a/usr/sbin/cleanse b/usr/sbin/cleanse
index 5a4cff6..77954a5 100755
--- a/usr/sbin/cleanse
+++ b/usr/sbin/cleanse
@@ -6,6 +6,7 @@
## remove corrupted lines, and ensure the information all agrees
## with itself. It is also to clean out unused lines and files.
##
+## @Copyright Copyright 2014 by Ismael Luceno for Source Mage
## @Copyright Copyright 2004 by Paul Mahon for Source Mage
## @Licence Relased under the GNU GPL version 2
##
@@ -227,13 +228,16 @@ function delint()
generic_remove_stale "$DEPENDS_STATUS" depends two
message "Pass three (duplicate depends entries)"
- for LINE in $( sed -n 's/^\([^:]*\):\([^:]*\):.*$/\1:\2/p' $DEPENDS_STATUS
| sed 's/+/\\+/' | sort | uniq -d ) ; do
+ for LINE in $( sed 's/^\([^:]*\):\([^:]*\):.*$/\1:\2/;tp;d;:p;s/+/\\+/}'
$DEPENDS_STATUS | sort | uniq -d ) ; do
message
options=()
- eval $(awk '/^'$LINE':/{
- if(!ENTRIES[$0]) {
- printf("options[%d]=\"%s\"\n", count++, $0); ENTRIES[$0]=1;
- } }' $DEPENDS_STATUS)
+ awk -v line="^$LINE:" -- '
+ $0 ~ line && !($0 in seen) {print count++, $0; seen[$0]}
+ ' $DEPENDS_STATUS |
+ while read v opt; do
+ options[$v]="$opt"
+ done
+
if [ ${#options[@]} -gt 1 ] ; then
select_list choice "" "${options[@]}"
message "Removing other entries and keeping selected entry"
@@ -281,16 +285,16 @@ function generic_remove_stale() {
message "Pass $3 (stale $2 entries)"
local tmp=$TMP_DIR/delint.$2.stale
local t
- awk -F: '
+ awk -F: -v status="$SPELL_STATUS" '
BEGIN {
- while (getline < "'$SPELL_STATUS'")
- Installed[$1] = 1;
+ while (getline < status)
+ Installed[$1]
}
{
- if ( ! Installed[$1])
- print $0;
+ if (!($1 in Installed))
+ print $0
}' "$1" |tee $tmp
- t=$(wc -l $tmp | awk '{print $1;}')
+ t=$(wc -l $tmp | awk '{print $1}')
message "\t$t bad lines, $(( $(wc -l $1| cut -f1 -d' ') - t))" \
"good lines in your $2 file."
if [[ $t -gt 0 ]] ; then
@@ -328,18 +332,17 @@ function prune_depends()
# Get a list of bad dependencies
# Output is in the form "SPELL DEPENDENCY optional/reqired PROVIDER"
- bad=( $( awk -F: '
+ bad=( $( awk -F: -v status="$SPELL_STATUS" '
BEGIN {
- while (getline < "'$SPELL_STATUS'")
- Installed[$1] = 1;
+ while (getline < status)
+ Installed[$1]
}
- $3=="on"{
- if($2 ~ "[(].*[)]")
- prov=gensub("^.*\\((.*)\\).*$", "\\1", 1, $2);
- else
- prov="__BLANK__";
+ $3 == "on" {
+ prov = ($2 ~ "[(].*[)]") ?
+ gensub("^.*\\((.*)\\).*$", "\\1", 1, $2) :
+ "__BLANK__"
gsub("\\(.*\\)", "", $2)
- if ( Installed[$1] && ! Installed[$2] && $2!="")
+ if ($1 in Installed && !($2 in Installed) && $2 != "")
printf("%s %s %s %s\n", $1, $2, $4, prov);
}' $DEPENDS_STATUS ) )
@@ -487,7 +490,7 @@ function packages()
done
)
if [[ $t ]] && query "\tRemove all but one of each set of duplicates?" "n"
; then
- awk -F: '{if(!LINES[$1]) { LINES[$1]=1; print $0; } }' $SPELL_STATUS >
$TMP_DIR/packages.3
+ awk -F: '!($1 in LINES){LINES[$1]; print}' $SPELL_STATUS >
$TMP_DIR/packages.3
message "\tRemoving bad entries"
mv $TMP_DIR/packages.3 $SPELL_STATUS
fi
diff --git a/usr/sbin/gaze b/usr/sbin/gaze
index 1329f2b..d90ac2d 100755
--- a/usr/sbin/gaze
+++ b/usr/sbin/gaze
@@ -592,7 +592,7 @@ function newer() {
local COMPUTE
@@ -1773,7 +1773,11 @@ function gaze_show_size_all () {
done <<< "$installed_spells"
clear_line
echo $spell_count $total_size $total_files | awk \
- 'END { print $1" spells -> "$2" bytes ("int($2/1024+0.5)" K,
"int($2/1024/1024+0.5)" M, "int($2/1024/1024/1024+0.5)" G) in "$3" files." }'
+ 'END {
+ print $1, "spells ->", $2, "bytes ("int($2/1024+0.5), "K,",
+ int($2/1024/1024+0.5), "M,", int($2/1024/1024/1024+0.5),
+ "G) in", $3, "files."
+ }'
echo
echo "Largest spell:"
gaze_show_size $max_spell
@@ -1812,8 +1816,12 @@ function gaze_show_size () {
while read each; do
test -f "$each" && echo $each
done < $file | xargs du -b |
- awk '{ x += $1 }
- END { print "'$spell' -> " x " bytes ("int(x/1024+0.5)" K,
"int(x/1024/1024+0.5)" M) in " NR " files." }'
+ awk -v spell="$spell" '
+ { x += $1 }
+ END {
+ print spell, "->", x, "bytes (" int(x/1024+0.5), "K,",
+ int(x/1024/1024+0.5), "M) in", NR, "files."
+ }'
done
}
diff --git a/usr/sbin/sorcery b/usr/sbin/sorcery
index c58f921..28965e0 100755
--- a/usr/sbin/sorcery
+++ b/usr/sbin/sorcery
@@ -92,7 +92,7 @@ mirror_list() {
local mirror_list
for mirror_list in $MIRRORS; do
[[ -f $mirror_list/$1 ]] || continue
- sort $mirror_list/$1 | awk '{ print "\""$NF"\""; NF--; print $0; }'
+ sort $mirror_list/$1 | awk '{ print "\"" $NF "\""; NF--; print $0 }'
break # only list duplicate mirror lists once
done
}
diff --git a/var/lib/sorcery/modules/libcast b/var/lib/sorcery/modules/libcast
index bd47f8e..df23ff1 100755
--- a/var/lib/sorcery/modules/libcast
+++ b/var/lib/sorcery/modules/libcast
@@ -98,7 +98,7 @@ function query_conflicts() {
local output=${2:-$CONFLICT_LIST}
# skip if the spell was already processed (avoids a double query for
in-cast resurrects)
- [[ -s $output ]] && awk -v s=$SPELL '{ if ($1 == s) {rc=1} } END {exit
!rc}' $output && return 0
+ [[ -s $output ]] && awk -v s=$SPELL '{ if ($1 == s) {rc=1; exit} } END
{exit !rc}' $output && return 0
if [[ -x $SCRIPT_DIRECTORY/CONFLICTS ]]; then
local CONFLICTS=$(run_spell_file CONFLICTS conflicts) || return 1
diff --git a/var/lib/sorcery/modules/libcodex
b/var/lib/sorcery/modules/libcodex
index 176225a..d6abe64 100755
--- a/var/lib/sorcery/modules/libcodex
+++ b/var/lib/sorcery/modules/libcodex
@@ -548,7 +548,7 @@ function codex_get_spells_in_section() {
message "${PROBLEM_COLOR}${section:-<null>} is not a section
directory!${DEFAULT_COLOR}"
return 1
fi
- grep "/$section$" < $index | awk '{ printf("%s/%s\n",$2,$1); }'
+ grep "/$section$" < $index | awk '{ print $2 "/" $1 }'
}
@@ -729,7 +729,7 @@ function codex_set_current_spell_by_name() {
#---------------------------------------------------------------------
## @param spell name
-## Returns the features a spell is a provider off.
+## Returns the features a spell is a provider of.
## Example, firefox: GECKO, GRAPHICAL-WEB-BROWSER, WEB-BROWSER,
## NS-PLUGIN-COMPATIBLE
##
@@ -739,7 +739,7 @@ function codex_find_spell_provides() {
local feature grimoire
local features=$(
for grimoire in $(codex_get_all_grimoires); do
- gawk '/\/'$spell'$/ { print $1 }' \
+ awk -v re="/$spell\$" -- '$0 ~ re { print $1 }' \
"$grimoire/$PROVIDE_INDEX_FILE"
done | sort -u)
@@ -773,7 +773,7 @@ function find_providers() {
local provider GRIMOIRE spell_path
local providers=$(
for GRIMOIRE in $(codex_get_all_grimoires); do
- gawk '/^'"$feature"'[[:blank:]]/ { print $2 }' \
+ gawk -v re="^$feature[[:blank:]]" -- '$0 ~ re { print $2 }' \
"$GRIMOIRE/$PROVIDE_INDEX_FILE"
done | get_basenames|sort -u)
@@ -879,24 +879,22 @@ function codex_create_in_memory_cache() {
eval $(
for each in "$@"; do
cat $each/$SPELL_INDEX_FILE
- done | awk -v i=$list -v hash=$hash '{
- if ( ! ($1 in map)) {
- map[$1]=$2;
- }
- } END {
- if (i) {
- FS=":";
- while (getline < i) {
- if( $3=="installed" || $3=="held") {
- printf("hash_put %s %s \"%s/%s\";\n",hash,$1,map[$1],$1);
- }
- }
- } else {
- for (spell in map) {
- printf("hash_put %s %s \"%s/%s\";\n",hash,spell,map[spell],spell);
- }
- }
- }'
+ done | awk -v i="$list" -v hash="$hash" '
+ { if (!($1 in map)) map[$1] = $2 }
+ function phash(hash, spell) {
+ printf("hash_put %s %s \"%s/%s\";\n", hash, spell,
map[spell], spell)
+ }
+ END {
+ if (i) {
+ FS=":"
+ while (getline < i)
+ if ($3 == "installed" || $3 == "held")
+ phash(hash, $1)
+ } else {
+ for (spell in map)
+ phash(hash, spell)
+ }
+ }'
)
}
@@ -935,10 +933,7 @@ function codex_list_provides () {
for file in $(codex_find_in_grimoire $grimoire "PROVIDES"); do
smgl_dirname "$file" spell
- for provides in $(gawk '{if (/provides/) { print $2 }
- else { print $1 }}' $file); do
- echo "$provides $spell"
- done
+ awk -v s="$spell" '/provides/{$1 = $2} {print $1, s}' $file
done | sort
}