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_%e_%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 local tmppid=c:\\tmp_pids.txt
42 # we have abandoned all hope of relying on ps on windows. instead
43 # we use wmic to get full command lines for processes.
44 # this does not exist on windows home edition. we are hosed if that's
45 # what they insist on testing on.
46 wmic /locale:ms_409 PROCESS get processid,commandline </dev/null >"$tmppid"
48 if [ ! -z "$(uname -a | grep "^MING" )" ]; then
51 # we 'type' the file to get rid of the unicode result from wmic.
52 cmd $flag type "$tmppid" >$PID_DUMP
54 local appropriate_pattern='s/^.* *\([0-9][0-9]*\) *$/\1/p'
55 for i in "${patterns[@]}"; do
56 #echo "pattern $i seek" >>~/crap.txt
57 PIDS_SOUGHT+=$(cat $PID_DUMP \
59 | sed -n -e "$appropriate_pattern")
61 #echo heres the dump after grep >>~/crap.txt
62 #cat $PID_DUMP | grep -i "$i" >>~/crap.txt
63 if [ ${#PIDS_SOUGHT[*]} -ne 0 ]; then
64 # we want to bail as soon as we get matches, because on the same
65 # platform, the same set of patterns should work to find all
66 # occurrences of the genesis java.
71 /bin/ps $extra_flags wuax >$PID_DUMP
72 # pattern to use for peeling off the process numbers.
73 local appropriate_pattern='s/^[-a-zA-Z_0-9][-a-zA-Z_0-9]* *\([0-9][0-9]*\).*$/\1/p'
74 # remove the first line of the file, search for the pattern the
75 # user wants to find, and just pluck the process ids out of the
77 for i in "${patterns[@]}"; do
78 PIDS_SOUGHT=$(cat $PID_DUMP \
81 | sed -n -e "$appropriate_pattern")
82 if [ ${#PIDS_SOUGHT[*]} -ne 0 ]; then
83 # we want to bail as soon as we get matches, because on the same
84 # platform, the same set of patterns should work to find all
85 # occurrences of the genesis java.
90 if [ ! -z "$PIDS_SOUGHT" ]; then echo "$PIDS_SOUGHT"; fi
94 # finds all processes matching the pattern specified and shows their full
95 # process listing (whereas psfind just lists process ids).
98 if [ ! -z "$p" ]; then
100 echo "Processes containing \"$1\"..."
102 if [ -n "$IS_DARWIN" ]; then
105 # only print the header the first time.
106 if [ -z "$fuzil_sentinel" ]; then
109 ps $i -w -u | sed -e '1d'
114 # cases besides darwin OS (for macs).
116 if [ "$OS" = "Windows_NT" ]; then
117 # special case for windows.
121 ps $extra_flags | grep "^ *$curr"
124 # normal OSes can handle a nice simple query.
131 # an unfortunately similarly named function to the above 'ps' as in process
132 # methods, but this 'ps' stands for postscript. this takes a postscript file
133 # and converts it into pcl3 printer language and then ships it to the printer.
134 # this mostly makes sense for an environment where one's default printer is
135 # pcl. if the input postscript causes ghostscript to bomb out, there has been
136 # some good success running ps2ps on the input file and using the cleaned
137 # postscript file for printing.
138 function ps2pcl2lpr() {
140 gs -sDEVICE=pcl3 -sOutputFile=- -sPAPERSIZE=letter "$i" | lpr -l
144 function fix_alsa() {
145 sudo /etc/init.d/alsasound restart
148 # switches from a /X/path form to an X:/ form.
149 function msys_to_dos_path() {
150 # we always remove dos slashes in favor of forward slashes.
151 echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\/\([a-zA-Z]\)\/\(.*\)/\1:\/\2/'
154 # switches from an X:/ form to an /X/path form.
155 function dos_to_msys_path() {
156 # we always remove dos slashes in favor of forward slashes.
157 echo "$1" | sed -e 's/\\/\//g' | sed -e 's/\([a-zA-Z]\):\/\(.*\)/\/\1\/\2/'
160 # su function: makes su perform a login.
161 # for some OSes, this transfers the X authority information to the new login.
163 # decide if we think this is debian or ubuntu or a variant.
164 DEBIAN_LIKE=$(if [ ! -z "$(grep -i debian /etc/issue)" \
165 -o ! -z "$(grep -i ubuntu /etc/issue)" ]; then echo 1; else echo 0; fi)
167 if [ $DEBIAN_LIKE -eq 1 ]; then
168 # debian currently requires the full version which imports X authority
169 # information for su.
171 # get the x authority info for our current user.
172 source $FEISTY_MEOW_SCRIPTS/x_win/get_x_auth.sh
174 if [ -z "$X_auth_info" ]; then
175 # if there's no authentication info to pass along, we just do a normal su.
178 # under X, we update the new login's authority info with the previous
180 (unset XAUTHORITY; /bin/su -l $* -c "$X_auth_info ; export DISPLAY=$DISPLAY ; bash")
183 # non-debian supposedly doesn't need the extra overhead any more.
184 # or at least suse doesn't, which is the other one we've tested on.
188 # relabel the console after returning.
189 bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
192 # sudo function wraps the normal sudo by ensuring we replace the terminal
193 # label if they're doing an su with the sudo.
195 local first_command="$1"
197 if [ "$first_command" == "su" ]; then
198 # yep, they were doing an su, but they're back now.
199 bash $FEISTY_MEOW_SCRIPTS/tty/label_terminal_with_infos.sh
203 # buntar is a long needed uncompressing macro that feeds into tar -x.
204 # it takes a list of bz2 file names and extracts their contents into
205 # sequentially numbered directories.
210 pushd buntar_$index &>/dev/null
212 # if the filename has no directory component, we will assume it used to
213 # be above our unzipping directory here.
214 if [ "$(basename $file)" = $file ]; then
217 bunzip2 -d -c $file | tar -xf -
219 index=$(expr $index + 1)
223 # trashes the .#blah files that cvs and svn leave behind when finding conflicts.
224 # this kind of assumes you've already checked them for any salient facts.
225 function clean_cvs_junk() {
227 find $i -follow -type f -iname ".#*" -exec perl $FEISTY_MEOW_SCRIPTS/files/safedel.pl {} ";"
231 # recreates all the generated files that the feisty meow scripts use.
232 function regenerate() {
233 bash $FEISTY_MEOW_SCRIPTS/core/bootstrap_shells.sh
235 local wheres_nechung=$(which nechung 2>/dev/null)
236 if [ -z "$wheres_nechung" ]; then
237 echo "The nechung oracle program cannot be found. You may want to consider"
238 echo "rebuilding the feisty meow applications with this command:"
239 echo " bash $FEISTY_MEOW_DIR/scripts/generator/bootstrap_build.sh"
245 function function_sentinel() { return 0; }
247 if [ ! -z "$SHELL_DEBUG" ]; then echo function definitions end....; fi