Permalink
Browse files

mixin jason bourne lib

  • Loading branch information...
1 parent 908fc2a commit 15c10f781daa24387fa70ca05dbb0dd2fb7ffb46 @defn defn committed Oct 5, 2012
Showing with 6,389 additions and 0 deletions.
  1. +126 −0 bin/_bump
  2. +148 −0 bin/_jason
  3. +3,840 −0 bin/_log4sh
  4. +1 −0 bin/_meat
  5. +1 −0 bin/_prime
  6. +1,009 −0 bin/_shflags
  7. +1,048 −0 bin/_shunit
  8. +8 −0 bin/_treadstone
  9. +174 −0 bin/_versions
  10. +34 −0 bin/bump
View
126 bin/_bump
@@ -0,0 +1,126 @@
+#!/bin/bash
+
+function bump_version {
+ local dirty="$1"; shift
+
+ if [[ "$dirty" = "$FLAGS_FALSE" ]]; then
+ ensure_clean_git_status
+ fi
+
+ local_file=
+ if [[ -f VERSION || -L VERSION ]]; then
+ local_file=1
+ if [[ ! -e VERSION ]]; then
+ logger_fatal "cannot write to VERSION file"
+ exit 1
+ fi
+ fi
+
+ tmp_version=$(mktemp -t XXXXXXXXX)
+ if [[ -n $local_file ]]; then
+ cat VERSION | perl -ne 'm{^\s*v?(\d+)\.(\d+)\.(\d+)\s*$} && printf("%03d.%03d.%03d %d.%d.%d\n",$1,$2,$3,$1,$2,$3)' | sort -r | head -1 | awk '{print $2}' > $tmp_version
+ else
+ git tag | perl -ne 'm{^v(\d+)\.(\d+)\.(\d+)$} && printf("%03d.%03d.%03d %d.%d.%d\n",$1,$2,$3,$1,$2,$3)' | sort -r | head -1 | awk '{print $2}' > $tmp_version
+ fi
+
+ if [[ ! -s "$tmp_version" ]]; then
+ logger_fatal "need at least one git tag (in the form v0.0.0) or a version in file VERSION (in the form 0.0.0)"
+ exit 1
+ fi
+
+ case "$1" in
+ patch|minor|major)
+ bump=$1; shift
+ set -- $(cat $tmp_version | sed 's#\.# #g')
+ case "$bump" in
+ patch)
+ echo "$1.$2.$(($3 + 1))"
+ ;;
+ minor)
+ echo "$1.$(($2 + 1)).0"
+ ;;
+ major)
+ echo "$(($1 + 1)).0.0"
+ ;;
+ esac > $tmp_version
+ ;;
+ *)
+ ver_new=$1; shift
+ ver_new=${ver_new#v}
+ echo $ver_new > $tmp_version
+ ;;
+ esac
+
+ ver_new=$(cat $tmp_version)
+ set -- $(echo "$ver_new" | sed 's#\.# #g') 0
+ M=$1; shift
+ m=$1; shift
+ p=$1; shift
+
+ (echo "$(($M+0)).$(($m+0)).$(($p+0))" > $tmp_version) 2>&-
+ ver_new_same=$(cat $tmp_version)
+
+ if [[ $ver_new != $ver_new_same ]]; then
+ logger_fatal "invalid version: $ver_new"
+ exit 1
+ fi
+
+ ver_bumped="v$(cat $tmp_version)"
+ rm -f $tmp_version
+ ensure_git_tag_available $ver_bumped
+
+ if [[ -n $local_file ]]; then
+ echo ${ver_bumped#v} > VERSION
+ git add VERSION
+ if [[ -f Gemfile ]]; then
+ bundle check 2>&1 >/dev/null || { bundle --quiet install --local --path vendor/bundle || bundle check > /dev/null; }
+ git add Gemfile.lock
+ fi
+
+ git commit -m "bump: $ver_bumped"
+ git push
+ fi
+
+ git_tag "$ver_bumped"
+ echo $ver_bumped
+}
+
+function ensure_git_tag_available {
+ version=$1; shift
+ git fetch --tags
+ remote_sha=$(git ls-remote origin $version | awk '{print $1}')
+ if [[ -n $remote_sha ]]; then
+ logger_fatal "already a remote tag $version, bump again"
+ exit 1
+ fi
+
+ local_sha=$(git show-ref $version | awk '{print $1}')
+ if [[ -n $local_sha ]]; then
+ logger_fatal "already a local tag $version"
+ exit 1
+ fi
+}
+
+function git_tag {
+ local version=$1; shift
+
+ ensure_git_tag_available "$version"
+
+ git tag $version
+ git push origin tag $version
+ remote_sha=$(git ls-remote origin $version | awk '{print $1}')
+ local_sha=$(git show-ref $version | awk '{print $1}')
+ if [[ $remote_sha != $local_sha ]]; then
+ logger_fatal "remote tag $version does not match local SHA"
+ exit 1
+ fi
+}
+
+function ensure_clean_git_status {
+ local lines=$(git status -s -uno | wc -l | awk '{print $1}')
+ if [[ $lines != "0" ]]; then
+ logger_fatal "git status is not clean, cannot tag"
+ git status -s -uno
+ exit 1
+ fi
+}
View
@@ -0,0 +1,148 @@
+#!/bin/bash
+
+: ${__meat__:=x}
+if [[ "$__meat__" != 'x' ]]; then
+ return 0
+fi
+__meat__='y'
+
+if [[ -z "${shome:-}" ]]; then
+ shome="$(cd -P -- "$(dirname -- "${BASH_SOURCE}")/.." && pwd -P)"
+fi
+
+function get_started {
+ # if getting-started bootstrap is detected, put this in the path
+ # mainly useful for getopt on os x
+ if [[ -d "$HOME/.getting-started/bootstrap" ]]; then
+ PATH="$HOME/.getting-started/bootstrap:$PATH"
+ hash -r
+ fi
+}
+
+function check_help {
+ # taken from shocco
+ if expr -- "$*" : ".*--help" >/dev/null; then
+ display_help
+ exit 0
+ fi
+}
+
+function display_help {
+ # taken from shocco
+ grep '^#/' <"$shome/bin/$(basename -- "$0")" | cut -c4-
+}
+
+# Exits the script with the last error code. Servers as a marker in $0 to
+# begin ronn documentation until end of file.
+function __MAN__ {
+ exit "$!"
+}
+
+# Extracts ronn-style Markdown after __MAN__ to stdout. If a line is "MAN", it
+# is assumed that a here document is used (for syntactical reasons).
+#
+# A limitation of detecting "MAN" will truncate the Markdown if "MAN" is a
+# legimate text.
+#
+# __MAN__ << "MAN"
+# raw ronn-style Markdown
+# MAN
+function display_man {
+ awk '/^__MAN__/,/^MAN$/ {print}' <"$shome/bin/$(basename -- "$0")" | tail -n +2 | egrep -v '^MAN$'
+}
+
+function display_synopsis {
+ awk '/^#/ && !/^#!/ { print } /^[^#]/ || /^$/ { exit }' <"$shome/bin/$(basename -- "$0")" | cut -c3-
+}
+
+function which_library {
+ local library="$1"; shift
+ if [[ -r "$shome/bin/_$library" ]]; then
+ echo "$shome/bin/_$library"
+ elif [[ -r "$shome/.$library/bin/_profile" ]]; then
+ echo "$shome/.$library/bin/_profile"
+ elif [[ -r "$shome/.$library/.profile" ]]; then
+ echo "$shome/.$library/.profile"
+ else
+ local nm_library="${library%%/*}"
+ if [[ "$nm_library" != "$library" ]]; then
+ local nm_right="${library##*/}"
+ if [[ -r "$shome/.$nm_library/bin/_$nm_right" ]]; then
+ echo "$shome/.$nm_library/bin/_$nm_right"
+ fi
+ fi
+ fi
+}
+
+function require {
+ local nm_library="$1"; shift
+ local pth_lib="$(which_library "$nm_library")"
+ if [[ -r "$pth_lib" ]]; then
+ if [[ "$#" == 0 ]]; then
+ set --
+ fi
+ source "$pth_lib" "$@"
+ fi
+}
+
+function parse_command_line {
+ if ! FLAGS "$@"; then
+ if [[ "$flags_error" = "help requested" ]]; then
+ echo ""
+ display_help
+ exit 0
+ fi
+
+ return 4
+ fi
+ return 0
+}
+
+function configure_logging {
+ # load log4sh (disabling properties file warning) and clear the default
+ # configuration
+ LOG4SH_CONFIGURATION='none' require 'log4sh'
+ log4sh_resetConfiguration
+
+ # set the global logging level to INFO
+ logger_setLevel INFO
+
+ # add and configure a FileAppender that outputs to STDERR, and activate the
+ # configuration
+ logger_addAppender stderr
+ appender_setType stderr FileAppender
+ appender_file_setFile stderr STDERR
+ appender_activateOptions stderr
+}
+
+function ryaml {
+ ruby -ryaml -e 'def ps x; unless x.nil?; puts x; end; end; ps ARGV[1..-1].inject(YAML.load(File.read(ARGV[0]))) {|acc, key| acc[key] }' "$@" 2>&-
+}
+
+function random_str {
+ echo "$(date +%s).$$.$RANDOM"
+}
+
+function runmany {
+ local cpu="$1"; shift
+ local args="$1"; shift
+ if [[ "$#" = 0 ]]; then
+ cat
+ else
+ echo "$@"
+ fi | xargs -P $cpu -n $args -- bash -c "$*" ""
+}
+
+function _main {
+ if [[ -z "$shome" ]]; then
+ shome="$(cd -P -- "$(dirname -- "${BASH_SOURCE}")/.." && pwd -P)"
+ fi
+
+ require 'shflags'
+
+ configure_logging
+
+ PATH="$shome/bin:$PATH"
+}
+
+_main "$@"
Oops, something went wrong.

0 comments on commit 15c10f7

Please sign in to comment.