Mercurial > hg > aboriginal
annotate sources/utility_functions.sh @ 1469:9a3f7ada5cb1
Pass through more/record-commands.sh wrapper variables in enviroment variable whitelisting.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 03 Dec 2011 17:51:38 -0600 |
parents | e26390768b3c |
children | 06c06aeaf547 |
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 |
1175
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
5 # Unset all environment variables that we don't know about, in case some crazy |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
6 # person already exported $CROSS_COMPILE, $ARCH, $CDPATH, or who knows what |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
7 # else. It's hard to know what might drive some package crazy, so use a |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
8 # whitelist. |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
9 |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
10 sanitize_environment() |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
11 { |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
12 # Which variables are set in config? |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
13 |
1179
c364e01dcdc6
Make the environment sanitize logic slightly more robust in the face of multi-line environment variable values.
Rob Landley <rob@landley.net>
parents:
1175
diff
changeset
|
14 TEMP=$(echo $(sed -n 's/.*export[ \t]*\([^=]*\)=.*/\1/p' config) | sed 's/ /,/g') |
1175
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
15 |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
16 # What other variables should we keep? |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
17 |
1211
e0c2ba5cc233
If environment sanitizing lets TOOLCHAIN_PREFIX through, it should let HOST_ARCH through too. And while we're at it, separate inherited variables from locally defined ones.
Rob Landley <rob@landley.net>
parents:
1207
diff
changeset
|
18 TEMP="$TEMP,LANG,PATH,SHELL,TERM,USER,USERNAME,LOGNAME,PWD,EDITOR,HOME,DISPLAY,_" |
1469
9a3f7ada5cb1
Pass through more/record-commands.sh wrapper variables in enviroment variable whitelisting.
Rob Landley <rob@landley.net>
parents:
1388
diff
changeset
|
19 TEMP="$TEMP,TOPSHELL,START_TIME,STAGE_NAME,TOOLCHAIN_PREFIX,HOST_ARCH,WRAPPY_LOGPATH,OLDPATH" |
1388
e26390768b3c
Avoid sanitizing useful *_proxy environment variables
Alessio Igor Bogani <alessiogirobogani@gmail.com>
parents:
1358
diff
changeset
|
20 TEMP="$TEMP,http_proxy,ftp_proxy,https_proxy,no_proxy" |
1175
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
21 |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
22 # Unset any variable we don't recognize. It can screw up the build. |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
23 |
1179
c364e01dcdc6
Make the environment sanitize logic slightly more robust in the face of multi-line environment variable values.
Rob Landley <rob@landley.net>
parents:
1175
diff
changeset
|
24 for i in $(env | sed -n 's/=.*//p') |
1175
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
25 do |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
26 is_in_list $i "$TEMP" && continue |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
27 [ "${i:0:7}" == "DISTCC_" ] && continue |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
28 [ "${i:0:7}" == "CCACHE_" ] && continue |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
29 |
1179
c364e01dcdc6
Make the environment sanitize logic slightly more robust in the face of multi-line environment variable values.
Rob Landley <rob@landley.net>
parents:
1175
diff
changeset
|
30 unset $i 2>/dev/null |
1175
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
31 done |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
32 } |
886a2ea90bc1
Add sanitize_environment to unset unrecognized environment variables.
Rob Landley <rob@landley.net>
parents:
1172
diff
changeset
|
33 |
984
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
34 # 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
|
35 |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
36 export_if_blank() |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
37 { |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
38 [ -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
|
39 } |
9840847885e8
Add export_if_blank and make lots of build paths overrideable.
Rob Landley <rob@landley.net>
parents:
944
diff
changeset
|
40 |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
41 # 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
|
42 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
43 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
|
44 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
45 # 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
|
46 [ -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
|
47 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
|
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 # Delete old directory, create new one. |
1035
a3716680a825
NO_CLEANUP should prevent blank_tempdir from deleting stuff.
Rob Landley <rob@landley.net>
parents:
984
diff
changeset
|
50 [ -z "$NO_CLEANUP" ] && rm -rf "$1" |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
51 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
|
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 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
54 # 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
|
55 |
1081
e992bc65b048
Remove unnecessary "function" label from shell functions.
Rob Landley <rob@landley.net>
parents:
1035
diff
changeset
|
56 sha1file() |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
57 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
58 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
|
59 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
60 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
61 # 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
|
62 # (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
|
63 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
64 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
|
65 { |
1161
eec0d43778cc
Output dienow's error message to stderr.
Rob Landley <rob@landley.net>
parents:
1113
diff
changeset
|
66 echo -e "\n\e[31mExiting due to errors ($ARCH_NAME $STAGE_NAME $PACKAGE)\e[0m" >&2 |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
67 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
|
68 } |
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 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
|
71 TOPSHELL=$$ |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
72 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
73 dienow() |
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 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
|
76 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
|
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 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
79 # 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
|
80 # 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
|
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 dotprogress() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
83 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
84 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
|
85 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
|
86 do |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
87 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
|
88 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
|
89 then |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
90 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
|
91 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
|
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 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
94 echo |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
95 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
96 |
1358
9252453c40d0
Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents:
1224
diff
changeset
|
97 # Announce an action to the world |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
98 |
1358
9252453c40d0
Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents:
1224
diff
changeset
|
99 announce() |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
100 { |
1358
9252453c40d0
Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents:
1224
diff
changeset
|
101 # Write a line to the log file with easily greppable header |
9252453c40d0
Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents:
1224
diff
changeset
|
102 echo "=== $1 ($ARCH_NAME $STAGE_NAME)" |
9252453c40d0
Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents:
1224
diff
changeset
|
103 |
9252453c40d0
Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents:
1224
diff
changeset
|
104 # Set the title bar of the current xterm |
9252453c40d0
Combine set_titlebar and "echo ===" stuff into announce() function. Consistently output target/stage info, and yank redundant instances.
Rob Landley <rob@landley.net>
parents:
1224
diff
changeset
|
105 [ -z "$NO_TITLE_BAR" ] && echo -en "\033]2;$ARCH_NAME $STAGE_NAME $1\007" |
919
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 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
108 # 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
|
109 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
110 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
|
111 { |
1113
e5ace7f9f4d4
More trouble than its worth for FORK and QUIET to be separate knobs.
Rob Landley <rob@landley.net>
parents:
1083
diff
changeset
|
112 [ -z "$FORK" ] && cat || grep "^===" |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
113 } |
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 # 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
|
116 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
117 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
|
118 { |
1172
6766f92a6c61
Make BUILD_VERBOSE a little more verbose.
Rob Landley <rob@landley.net>
parents:
1161
diff
changeset
|
119 [ -z "$BUILD_VERBOSE" ] || echo "$*" |
6766f92a6c61
Make BUILD_VERBOSE a little more verbose.
Rob Landley <rob@landley.net>
parents:
1161
diff
changeset
|
120 |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
121 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
|
122 then |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
123 eval "$*" |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
124 else |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
125 eval "$*" & |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
126 fi |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
127 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
128 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
129 # 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
|
130 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
131 killtree() |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
132 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
133 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
|
134 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
135 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
|
136 do |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
137 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
|
138 shift |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
139 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
140 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
141 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
|
142 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
|
143 then |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
144 # 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
|
145 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
|
146 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
|
147 fi |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
148 } |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
149 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
150 # 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
|
151 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
152 # 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
|
153 # 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
|
154 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
155 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
|
156 { |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
157 # 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
|
158 # 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
|
159 # 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
|
160 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
161 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
|
162 do |
1224
f0d7f84ec51a
Dereference symlink path segments in record-commands.sh.
Rob Landley <rob@landley.net>
parents:
1211
diff
changeset
|
163 find "$DIR/" -maxdepth 1 -mindepth 1 -name "$2" | sed 's@.*/@@' | \ |
919
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
164 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
|
165 do |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
166 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
|
167 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
168 # 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
|
169 |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
170 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
|
171 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
172 done |
8b69eeb17ebf
Break up sources/functions.sh starting with some of the more obviously independent ones.
Rob Landley <rob@landley.net>
parents:
diff
changeset
|
173 } |
941
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
174 |
944
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
175 # 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
|
176 |
941
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
177 check_prerequisite() |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
178 { |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
179 if [ -z "$(which "$1")" ] |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
180 then |
944
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
181 [ -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
|
182 dienow |
941
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
183 fi |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
184 } |
7dd3fb4dd333
Minor cleanups and comments, introduce check_prerequisite function.
Rob Landley <rob@landley.net>
parents:
919
diff
changeset
|
185 |
944
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
186 # 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
|
187 # identical files into hardlinks |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
188 |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
189 collapse_hardlinks() |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
190 { |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
191 SHA1LIST="" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
192 find "$1" -type f | while read FILE |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
193 do |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
194 echo "$FILE" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
195 SHA1=$(sha1file "$FILE") |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
196 MATCH=$(echo "$SHA1LIST" | grep "^$SHA1") |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
197 if [ -z "$MATCH" ] |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
198 then |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
199 # 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
|
200 SHA1LIST="$SHA1LIST |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
201 $SHA1 $FILE" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
202 else |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
203 FILE2="$(echo "$MATCH" | sed 's/[^ ]* //')" |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
204 cmp -s "$FILE" "$FILE2" || continue |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
205 ln -f "$FILE" "$FILE2" || dienow |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
206 fi |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
207 done |
fc134a13357e
Largeish refactoring and cleanup of compiler build:
Rob Landley <rob@landley.net>
parents:
941
diff
changeset
|
208 } |
1082
255488af0bbb
Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents:
1081
diff
changeset
|
209 |
255488af0bbb
Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents:
1081
diff
changeset
|
210 # Check if $1 is in the comma separated list $2 |
255488af0bbb
Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents:
1081
diff
changeset
|
211 |
255488af0bbb
Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents:
1081
diff
changeset
|
212 is_in_list() |
255488af0bbb
Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents:
1081
diff
changeset
|
213 { |
1083
cb4dbdb7f2cd
Make BUILD_STATIC take comma separated list of packages, or "all" or "none". Default behavior should remain the same.
Rob Landley <rob@landley.net>
parents:
1082
diff
changeset
|
214 [ "$2" == all ] || [ ! -z "$(echo ,"$2", | grep ,"$1",)" ] |
1082
255488af0bbb
Convert unstable() to is_in_list() taking the list to check as the second argument.
Rob Landley <rob@landley.net>
parents:
1081
diff
changeset
|
215 } |