123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- #!/bin/bash
- # ~/bin/example
- . <(ffoom init)
-
-
- ##
- ## pretty.sh - make output pretty and pretty useful
- ##
-
- ffoo import pretty
-
-
- # three levels should be enough for everyone
- #
- think "about saying something..." # thinks loud if FFOO_VERBOSE
- warn "this is just an example" # obvious :)
- true || die "true was false!" # Perlism :)
-
-
- # several ways of debugging
- #
- x=1; y=2; z=3
- debug -v x y z # debug:example.sh:x='1' ...
- echo "hello" | debug_pipe mypipe # debug|mypipe|: hello
- warn -f should_be_empty # warns with name+content
- # unless the file is empty
- myfun() {
- num=42
- debug -v num # reveals context!
- } # vvv
- myfun # debug:myfun: num='42'
-
-
- # but you can throw more at yourself
- #
- debug -c ps aux # when more is more
- debug -f /etc/hosts
-
- # output can be whatever you think is pretty:
- #
- FFOO_PRETTY=color
- FFOO_PRETTY=html
- #...
- FFOO_PRETTY=your_own_format
-
-
-
- ##
- ## config.sh -- config file grepping
- ##
-
- ffoo import config
-
- # a sample INI file
- #
- mkdir $HOME/.demo
- cat >$HOME/.demo/foo.ini <<EOF
- # a sample INI file
- [foo]
- multiline = also possible
- multiline = like this :)
- [foo.bar]
- # spaces after equal sign are trimmed by default
- baz = qux
- baz2 = public qux
- [foo.script]
- # but can be preserved using -S|--strict mode
- s1 =#!/usr/bin/python
- s1 =def main():
- s1 = print "will work!"
- EOF
-
- # read as you need
- #
- FFOO_CONFIG_PATH=$HOME/.demo # just tell us the path
- cfgrep -s foo.bar -k baz foo.ini # prints "qux"
- cfgrep -p foo.bar.baz foo.ini # ...short for above
- cfgrep -p foo.bar.baz # ...even shorter (foo hints foo.ini)
-
- # store even indented text
- #
- cfgrep -S -p foo.script python >s1.py # the -S will preserve spaces on RHS
- python s1.py # so this will work
-
-
- # merge INIs on runtime
- #
- mkdir $HOME/.demo/private
- cat >$HOME/.demo/private/foo.ini <<EOF
- [foo.bar]
- baz2 = secret qux
- EOF
-
- # this works similar to PATH
- #
- FFOO_CONFIG_PATH=$HOME/.demo-private:$HOME/.demo
- cfgrep -p foo.bar.baz2 # the private file wins -- "secret qux!"
- cfgrep -j -p foo.bar.baz2 # but -j causes them to be joined:
- # secret qux
- # public qux
-
- #
- # recon.sh -- common tasks to "look around"
- #
-
- ffoo import recon
-
- # wait for better times
- #
- wait_until -e ! test -f badfile # -e means use eval (make "!" work)
- think "the badfile is away..."
- bad_file_away() { # but you can avoid eval
- ! test -f badfile
- }
- wait_until bad_file_away
-
- # smart-match PIDs
- #
- sleep 100 &
- ./myscript-1.py
- ./myscript-2.py
- sleep 100 &
- for pid in $(pids_matching "^myscript-" "^sleep$");
- do
- kill $pid
- kill -9 $pid
- done
-
- # age querying
- #
- yum -y install something-to-usr
- sleep 10
- age_of_tree /usr # should be ~10
-
- # readiness checks, great food for wait_until
- #
- wait_until listening_on 8888 # locally!
- wait_until reachable_by_ping my_host
- wait_until reachable_by_tcp 25 my_host
- wait_until reachable_by_ssh my_host
- cat all_hosts | filter_hosts # will list those that ponged
- cat all_hosts | filter_hosts -P -s # ...no ping but SSH
- cat all_hosts | filter_hosts -t 25 # ...ping and TCP 25
-
- # cat but for URIs!
- #
- wait_until listening_on 8888
- cat_uri http://localhost:8888 | grep OK
-
-
-
- ##
- ## ... and more: types.sh, exits.sh, tmp.sh
- ##
-
- ffoo import testing
-
- register_artifact future.log # does not need to exist yet
- myprog > future.log
- collect_artifacts # will preserve tree from /
- # and produce folder called e.g.
- # artifacts-20140915-141502
|