Mercurial > hg > aboriginal
annotate sources/utility_functions.sh @ 984:9840847885e8
Add export_if_blank and make lots of build paths overrideable.
author | Rob Landley <rob@landley.net> |
---|---|
date | Wed, 24 Feb 2010 10:08:38 -0600 |
parents | fc134a13357e |
children | a3716680a825 |
rev | line source |
---|---|
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
1 #!/bin/echo "This file is sourced, not run" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
2 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
3 # This file contains generic functions, presumably reusable in other contexts. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
4 |
984
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
5 # Assign (export) a variable only if current value is blank |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
6 |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
7 export_if_blank() |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
8 { |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
9 [ -z "$(eval "echo \"\${${1/=*/}}\"")" ] && export "$1" |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
10 } |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
11 |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
12 # Create a blank directory at first argument, deleting existing contents if any |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
13 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
14 blank_tempdir() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
15 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
16 # sanity test: never rm -rf something we don't own. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
17 [ -z "$1" ] && dienow |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
18 touch -c "$1" || dienow |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
19 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
20 # Delete old directory, create new one. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
21 rm -rf "$1" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
22 mkdir -p "$1" || dienow |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
23 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
24 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
25 # output the sha1sum of a file |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
26 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
27 function sha1file() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
28 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
29 sha1sum "$@" | awk '{print $1}' |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
30 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
31 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
32 # dienow() is an exit function that works properly even from a subshell. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
33 # (actually_dienow is run in the parent shell via signal handler.) |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
34 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
35 actually_dienow() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
36 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
37 echo -e "\n\e[31mExiting due to errors ($ARCH_NAME $STAGE_NAME $PACKAGE)\e[0m" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
38 exit 1 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
39 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
40 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 trap actually_dienow SIGUSR1 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
42 TOPSHELL=$$ |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
44 dienow() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
46 kill -USR1 $TOPSHELL |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
47 exit 1 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
48 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
49 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
50 # Turn a bunch of output lines into a much quieter series of periods, |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 # roughly one per screenfull |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
52 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
53 dotprogress() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
55 x=0 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
56 while read i |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 do |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 x=$[$x + 1] |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
59 if [[ "$x" -eq 25 ]] |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 then |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 x=0 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
62 echo -n . |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
63 fi |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
65 echo |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
66 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
68 # Set the title bar of the current xterm |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
69 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
70 set_titlebar() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
71 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 [ -z "$NO_TITLE_BAR" ] && |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 echo -en "\033]2;$1\007" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
74 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
75 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
76 # Filter out unnecessary noise, keeping just lines starting with "===" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
77 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
78 maybe_quiet() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
80 [ -z "$QUIET" ] && cat || grep "^===" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
81 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
82 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 # Run a command background if FORK is set, in foreground otherwise |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
85 maybe_fork() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
86 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 if [ -z "$FORK" ] |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
88 then |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
89 eval "$*" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 else |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
91 eval "$*" & |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
92 fi |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
93 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 # Kill a process and all its decendants |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
97 killtree() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
98 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
99 local KIDS="" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
101 while [ $# -ne 0 ] |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
102 do |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
103 KIDS="$KIDS $(pgrep -P$1)" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
104 shift |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
105 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
106 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
107 KIDS="$(echo -n $KIDS)" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 if [ ! -z "$KIDS" ] |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
109 then |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 # Depth first kill avoids reparent_to_init hiding stuff. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
111 killtree $KIDS |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
112 kill $KIDS 2>/dev/null |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 fi |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
114 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
115 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
116 # Search a colon-separated path for files matching a pattern. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
118 # Arguments are 1) path to search, 2) pattern, 3) command to run on each file. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
119 # During command, $DIR/$FILE points to file found. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
120 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 path_search() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
122 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 # For each each $PATH element, loop through each file in that directory, |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 # and create a symlink to the wrapper with that name. In the case of |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 # duplicates, keep the first one. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 echo "$1" | sed 's/:/\n/g' | while read DIR |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 do |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 find "$DIR" -maxdepth 1 -mindepth 1 -name "$2" | sed 's@.*/@@' | \ |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
130 while read FILE |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 do |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 eval "$3" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
134 # Output is verbose. Pipe it to dotprogress. |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
136 echo $FILE |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
138 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 } |
941
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
140 |
944
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
141 # Abort if we haven't got a prerequisite in the $PATH |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
142 |
941
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
143 check_prerequisite() |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
144 { |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
145 if [ -z "$(which "$1")" ] |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
146 then |
944
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
147 [ -z "$FAIL_QUIET" ] && echo No "$1" in '$PATH'. >&2 |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
148 dienow |
941
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
149 fi |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
150 } |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
151 |
944
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
152 # Search through all the files under a directory and collapse together |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
153 # identical files into hardlinks |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
154 |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
155 collapse_hardlinks() |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
156 { |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
157 SHA1LIST="" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
158 find "$1" -type f | while read FILE |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
159 do |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
160 echo "$FILE" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
161 SHA1=$(sha1file "$FILE") |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
162 MATCH=$(echo "$SHA1LIST" | grep "^$SHA1") |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
163 if [ -z "$MATCH" ] |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
164 then |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
165 # Yes, the quote spanning two lines here is intentional |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
166 SHA1LIST="$SHA1LIST |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
167 $SHA1 $FILE" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
168 else |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
169 FILE2="$(echo "$MATCH" | sed 's/[^ ]* //')" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
170 cmp -s "$FILE" "$FILE2" || continue |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
171 ln -f "$FILE" "$FILE2" || dienow |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
172 fi |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
173 done |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
174 } |