Permalink
Browse files

Merge branch 'master' of github.com:jpic/bashworks

  • Loading branch information...
jpic committed Dec 14, 2009
2 parents 333ddfb + 8434678 commit 6effdee6d89515e651be5f3515578e7ca1864188
Showing with 184 additions and 7 deletions.
  1. +7 −1 README.rst
  2. +19 −2 hack/functions.sh
  3. +13 −0 module/docs/examples/jpic.xinitrc
  4. +78 −0 os/xrandr/source.sh
  5. +63 −0 remote/source.sh
  6. +4 −4 vps/functions.sh
View
@@ -1,3 +1,9 @@
Will be stable as soon as the guide is rewritten, to be more interresting.
-For now, see the api documentation: http://bashworks.ocpsys.com/module.html
+For now, see:
+
+- `jpic's .bashrc`_ for an example bootstrap,
+- the `api documentation`_ updated every hour,
+
+.. _`api documentation`: http://bashworks.ocpsys.com/module.html
+.. _`jpic's .bashrc`: http://github.com/jpic/bashworks/blob/master/module/docs/examples/jpic.bashrc.sh
View
@@ -35,12 +35,29 @@ function hack_cdpath() {
# @param Path to make real
# @stdout Absolute path
function hack_realpath() {
- if which -s realpath; then
+ if hack_which realpath; then
realpath "$1"
- elif which -s readlink; then
+ elif hack_which readlink; then
readlink -f "$1"
else
mlog error "Need either realpath or readlink command"
return 1
fi
}
+
+# Cross OS `which` command implementation.
+# @param Command name
+function hack_which() {
+ local linux=""
+
+ if [[ $OSTYPE =~ bsd ]]; then
+ return which -s "$1"
+ else
+ linux="$(which $1 2>&1)"
+ if [[ $linux =~ "no $1" ]]; then
+ return 1
+ else
+ return 0
+ fi
+ fi
+}
@@ -0,0 +1,13 @@
+# i source this from xinitrc
+
+# load the framework
+source $1/module/source.sh
+
+# find modules in my repo
+module_repo $1
+
+# load os_xrandr
+module os_xrandr
+
+# set the best resolution
+os_xrandr_set_largest_output
View
@@ -0,0 +1,78 @@
+os_xrandr_displays=()
+
+# Resets xrandr variables and parses xrandr output.
+function os_xrandr_post_load() {
+ os_xrandr_reset
+ os_xrandr_parse
+}
+
+# Parses xrandr modes into bash lists.
+# It will parse the output of `xrandr` and declare one variable per screen,
+# like $xrandr_modes_VGA1. Each of this variables is an array of avalaible
+# modes for this display.
+# For example:
+## echo ${os_xrandr_modes_VGA1[@]}
+## 1280x1024 1280x1024 1024x768 832x624 800x600 640x480 720x400
+function os_xrandr_parse() {
+ local current_modes=""
+
+ # extract
+ local results="$(xrandr | grep -o -e '\([A-Z]\+[0-9]\+ connected\)\|\([0-9]\+x[0-9]\+ \)')"
+
+ # parse
+ for result in $results; do
+ if [[ $result =~ connected ]]; then
+ continue
+ fi
+
+ if [[ $result =~ [A-Z] ]]; then
+ current_modes="os_xrandr_modes_${result}"
+ eval "$current_modes=()"
+ os_xrandr_displays+=("$result")
+ else
+ eval "$current_modes+=(\"$result\")"
+ fi
+ done
+}
+
+# Reset xrandr variables
+function os_xrandr_reset() {
+ # reset
+ for display in ${os_xrandr_displays[@]}; do
+ unset "os_xrandr_modes_${display}"
+ done
+
+ os_xrandr_displays=()
+}
+
+# Given a display name, it will output the largest mode.
+# For example:
+## os_xrandr_largest_mode VGA1 # will output:
+## 1280x1024
+function os_xrandr_largest_mode() {
+ eval "echo \$os_xrandr_modes_$1"
+}
+
+# Outputs the name of the display that is capable of the largest mode.
+function os_xrandr_largest_display() {
+ local largest=""
+ local -i largest_width=0
+ local -i width=0
+ local tmp=""
+
+ for display in $os_xrandr_displays; do
+ tmp="$(os_xrandr_largest_mode $display)"
+ local -i width=${tmp%%x*}
+ if [[ $width -gt $largest_width ]]; then
+ local -i largest_width=$width
+ largest="$display"
+ fi
+ done
+
+ echo $display
+}
+
+# Uses xrandr to set the largest mode to the largest display.
+function os_xrandr_set_largest_output() {
+ xrandr --output $(os_xrandr_largest_display) --mode $(os_xrandr_largest_mode `os_xrandr_largest_display`)
+}
View
@@ -0,0 +1,63 @@
+#!/bin/bash
+# This bash module was inspired by programs like "capistrano", "fabric" ... The
+# role of this deployment tool is to make the process of running commands and
+# functions on one or several remote servers through ssh.
+#
+# Like other bashworks modules, it does not provide inversion of control, which
+# means that it is left to the user to make a script that will use functions
+# from the deploy module.
+#
+# It is recommanded that $HOME/.ssh/config is nicely configured for example:
+## Host foo
+## User bar
+## Port 1234
+## HostName 1.2.3.4
+# Will allow using "foo" with the ssh command.
+#
+# Simple example usage:
+## # configure some variables
+## deploy_from="/path/to/working/copy"
+## deploy_to="somehost:/path/to/working/copy someuser@somehost:/path/to/"
+##
+## # define a bash function which will be run on each servers
+## function your_deploy() {
+## # current directory is automatically set with $deploy_to
+## hg pull
+## sudo apache2ctl graceful
+## }
+##
+## # deployment workflow
+## cd $deploy_from
+## hg push
+## remote your_deploy $deploy_to
+
+# Runs a local function or remote command on one or several servers through ssh
+# in given paths.
+# For example, source this module and try:
+## # with a local function
+## function hello() { echo "Hello from `pwd`"; }
+## remote hello somehost: otherhost:/path/to/test
+## # with a remote command
+## remote "git pull origin master" somehost:/path
+function remote() {
+ local do="$1"
+ shift
+ local targets="$*"
+
+ local target=""
+ local target_host=""
+ local target_path=""
+
+ for target in $targets; do
+ target_host="${target%%:*}"
+ target_path="${target/$target_host:/}"
+
+ if [[ -n "$(declare -f $do)" ]]; then
+ mlog notice "Running $do() on $target_host in $target_path"
+ ssh $target_host "cd $target_path && $(declare -f $do) && $do"
+ else
+ mlog notice "Running $do on $target_host in $target_path"
+ ssh $target_host "cd $target_path && $do"
+ fi
+ done
+}
View
@@ -247,7 +247,7 @@ function vps_emerge() {
# Example usage:
## # Add sqlite use flag to php
## # vps_euse dev-lang/php sqlite
-# @calls vps_updateportage
+# @calls vps_configure_portage
# @param package atom
# @param use flags
function vps_euse() {
@@ -257,7 +257,7 @@ function vps_euse() {
echo $atom >> $(vps_get_property $vps_master root)/etc/portage/package.keywords
- vps_updateportage
+ vps_configure_portage
}
# Adds the given package atom to the master vps package.keywords and then
@@ -266,13 +266,13 @@ function vps_euse() {
## # You're looking for troubble, and want unstable mysql
## vps_ebackport dev-db/mysql
# @param package atom to add to package.keywords
-# @call vps_updateportage
+# @call vps_configure_portage
function vps_ebackport() {
local atom=$1
echo $atom >> $(vps_get_property $vps_master root)/etc/portage/package.keywords
- vps_updateportage
+ vps_configure_portage
}
# Patch baselayout.

0 comments on commit 6effdee

Please sign in to comment.