3 # This defines some general, useful functions.
5 # test whether we've been here before or not.
7 function_sentinel &>/dev/null
9 # there was no error, so we can skip the inits.
10 if [ ! -z "$SHELL_DEBUG" ]; then
11 echo skipping functions.sh because already defined.
16 if [ -z "$skip_all" ]; then
17 if [ ! -z "$SHELL_DEBUG" ]; then
18 echo function definitions begin...
21 # a handy little method that can be used for date strings. it was getting
22 # really tiresome how many different ways the script did the date formatting.
23 function date_stringer() {
24 date +"%Y_%m_%d_%H%M_%S" | tr -d '/\n/'
27 # makes a directory of the name specified and then tries to change the
28 # current directory to that directory.
30 if [ ! -d "$1" ]; then mkdir -p "$1"; fi
34 # locates a process given a search pattern to match in the process list.
36 local PID_DUMP="$(mktemp "$TMP/zz_pidlist.XXXXXX")"
39 if [ "$OS" == "Windows_NT" ]; then
40 # needs to be a windows format filename for 'type' to work.
41 if [ ! -d c:/tmp ]; then
44 # windows7 magical mystery tour lets us create a file c:\\tmp_pids.txt, but then it's not really there
45 # in the root of drive c: when we look for it later. hoping to fix that problem by using a subdir, which
46 # also might be magical thinking from windows perspective.
47 tmppid=c:\\tmp\\pids.txt
48 # we have abandoned all hope of relying on ps on windows. instead
49 # we use wmic to get full command lines for processes.
50 # this does not exist on windows home edition. we are hosed if that's
51 # what they insist on testing on.
52 wmic /locale:ms_409 PROCESS get processid,commandline </dev/null >"$tmppid"
54 if [ ! -z "$(uname -a | grep "^MING" )" ]; then
57 # we 'type' the file to get rid of the unicode result from wmic.
58 cmd $flag type "$tmppid" >$PID_DUMP
60 local CR='
\r' # embedded carriage return.
61 local appropriate_pattern="s/^.* *\([0-9][0-9]*\)[ $CR]*\$/\1/p"
62 for i in "${patterns[@]}"; do
63 PIDS_SOUGHT+=$(cat $PID_DUMP \
65 | sed -n -e "$appropriate_pattern")
66 if [ ${#PIDS_SOUGHT[*]} -ne 0 ]; then
67 # we want to bail as soon as we get matches, because on the same
68 # platform, the same set of patterns should work to find all
69 # occurrences of the genesis java.
74 /bin/ps $extra_flags wuax >$PID_DUMP
75 # pattern to use for peeling off the process numbers.
76 local appropriate_pattern='s/^[-a-zA-Z_0-9][-a-zA-Z_0-9]* *\([0-9][0-9]*\).*$/\1/p'
77 # remove the first line of the file, search for the pattern the
78 # user wants to find, and just pluck the process ids out of the
80 for i in "${patterns[@]}"; do
81 PIDS_SOUGHT=$(cat $PID_DUMP \
84 | sed -n -e "$appropriate_pattern")
85 if [ ${#PIDS_SOUGHT[*]} -ne 0 ]; then
86 # we want to bail as soon as we get matches, because on the same
87 # platform, the same set of patterns should work to find all
88 # occurrences of the genesis java.
93 if [ ! -z "$PIDS_SOUGHT" ]; then echo "$PIDS_SOUGHT"; fi
97 # finds all processes matching the pattern specified and shows their full
98 # process listing (whereas psfind just lists process ids).
101 if [ ! -z "$p" ]; then
103 echo "Processes containing \"$1\"..."
105 if [ -n "$IS_DARWIN" ]; then
108 # only print the header the first time.
109 if [ -z "$fuzil_sentinel" ]; then
112 ps $i -w -u | sed -e '1d'
117 # cases besides mac os x's darwin.
119 if [ "$OS" = "Windows_NT" ]; then
120 # special case for windows.
124 ps $extra_flags | grep "$curr"
127 # normal OSes can handle a nice simple query.
134 # an unfortunately similarly named function to the above 'ps' as in process
135 # methods, but this 'ps' stands for postscript. this takes a postscript file
136 # and converts it into pcl3 printer language and then ships it to the printer.
137 # this mostly makes sense for an environment where one's default printer is
138 # pcl. if the input postscript causes ghostscript to bomb out, there has been
139 # some good success running ps2ps on the input file and using the cleaned
140 # postscript file for printing.
141 function ps2pcl2lpr() {
143 gs -sDEVICE=pcl3 -sOutputFile=- -sPAPERSIZE=letter "$i" | lpr -l
147 function fix_alsa() {
148 sudo /etc/init.d/alsasound restart
151 # switches from a /X/path form to an X:/ form.
152 function msys_to_dos_path() {
153 # we always remove dos slashes in favor of forward slashes.
154 echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\/\([a-zA-Z]\)\/\(.*\)/\1:\/\2/'
157 # switches from an X:/ form to an /X/path form.
158 function dos_to_msys_path() {
159 # we always remove dos slashes in favor of forward slashes.
160 echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\([a-zA-Z]\):\/\(.*\)/\/\1\/\2/'
163 # su function: makes su perform a login.
164 # for some OSes, this transfers the X authority information to the new login.
166 # decide if we think this is debian or ubuntu or a variant.
167 DEBIAN_LIKE=$(if [ ! -z "$(grep -i debian /etc/issue)" \
168 -o ! -z "$(grep -i ubuntu /etc/issue)" ]; then echo 1; else echo 0; fi)
170 if [ $DEBIAN_LIKE -eq 1 ]; then
171 # debian currently requires the full version which imports X authority
172 # information for su.
174 # get the x authority info for our current user.
175 source $FEISTY_MEOW_SCRIPTS/x_win/get_x_auth.sh
177 if [ -z "$X_auth_info" ]; then
178 # if there's no authentication info to pass along, we just do a normal su.
181 # under X, we update the new login's authority info with the previous
183 (unset XAUTHORITY; /bin/su -l $* -c "$X_auth_info ; export DISPLAY=$DISPLAY ; bash")
186 # non-debian supposedly doesn't need the extra overhead any more.
187 # or at least suse doesn't, which is the other one we've tested on.
191 # relabel the console after returning.
192 bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
195 # sudo function wraps the normal sudo by ensuring we replace the terminal
196 # label if they're doing an su with the sudo.
198 local first_command="$1"
200 if [ "$first_command" == "su" ]; then
201 # yep, they were doing an su, but they're back now.
202 bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
206 # buntar is a long needed uncompressing macro that feeds into tar -x.
207 # it takes a list of bz2 file names and extracts their contents into
208 # sequentially numbered directories.
213 pushd buntar_$index &>/dev/null
215 # if the filename has no directory component, we will assume it used to
216 # be above our unzipping directory here.
217 if [ "$(basename $file)" = $file ]; then
220 bunzip2 -d -c $file | tar -xf -
222 index=$(expr $index + 1)
226 # trashes the .#blah files that cvs and svn leave behind when finding conflicts.
227 # this kind of assumes you've already checked them for any salient facts.
228 function clean_cvs_junk() {
230 find $i -follow -type f -iname ".#*" -exec perl $FEISTY_MEOW_SCRIPTS/files/safedel.pl {} ";"
234 # recreates all the generated files that the feisty meow scripts use.
235 function regenerate() {
236 bash $FEISTY_MEOW_SCRIPTS/core/bootstrap_shells.sh
238 local wheres_nechung=$(which nechung 2>/dev/null)
239 if [ -z "$wheres_nechung" ]; then
240 echo "The nechung oracle program cannot be found. You may want to consider"
241 echo "rebuilding the feisty meow applications with this command:"
242 echo " bash $FEISTY_MEOW_DIR/scripts/generator/bootstrap_build.sh"
248 function function_sentinel() { return 0; }
250 if [ ! -z "$SHELL_DEBUG" ]; then echo function definitions end....; fi