Skip to content
Browse files

Updated commentblocks

  • Loading branch information...
1 parent 9673c77 commit 3912515344044ce6f7afeb9a6fade2cbd5cad534 @jpic committed
View
4 .gitignore
@@ -1,2 +1,2 @@
-.logfile
-.swp
+*.logfile
+*.swp
View
4 break/bashunit/main.sh
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# This file declares functions to test the break module which are useable
-# with the mtests_bashunit submodule.
+# This file declares functions to test the break module which are useable with
+# the mtests_bashunit submodule.
# Sets up an arbitary conf path and break interval for testing.
# @calls break_post_source()
View
9 break/functions.sh
@@ -4,7 +4,7 @@
# Is your break granted?
# @stdout Wether your request was granted or denied.
-# @calls break_do
+# @calls break_do()
function break_request() {
if [[ -z $break_previous ]]; then
echo "Enjoy your first break"
@@ -23,10 +23,9 @@ function break_request() {
fi
}
-# Take a break.
-# <p>
-# Updates the previous break timestamp and saves for anti-cheat security.
-# @calls conf_save
+# Take a break. Updates the previous break timestamp and saves for anti-cheat
+# security.
+# @calls conf_save()
function break_do() {
break_previous=$(date +%s)
conf_save break
View
35 break/source.sh
@@ -1,41 +1,32 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# This "lifestyle" module helps bash users to manage their breaks.
-# <p>
# It is particularely good for your health if you use to drink coffee or
# smoke during your breaks. It may also help for laundry or whatever.
-# <p>
# The minimal interval between breaks should be configured and saved
# before this module can do any good.
-# <p>
# Then it is possible to use break_request() to ask for permission to
# take a break.
-# <p>
# In case of rebellion then break_do() should be directly used.
-# <p>
# Example usage:
-# <pre>
-# jpic@natacha:~$ break_conf_interactive
-# $break_interval [7200]: 4
-# Changed break_interval to 4
-# jpic@natacha:~$ break_request && break_request && sleep 5 && break_request
-# Granted, enjoy
-# Denied, get back to work.
-# Granted, enjoy
-# jpic@natacha:~$ cat /home/jpic/.break
-# break_interval="4"
-# break_previous="1254303082"
-# </pre>
+## jpic@natacha:~$ break_conf_interactive
+## $break_interval [7200]: 4
+## Changed break_interval to 4
+## jpic@natacha:~$ break_request && break_request && sleep 5 && break_request
+## Granted, enjoy
+## Denied, get back to work.
+## Granted, enjoy
+## jpic@natacha:~$ cat /home/jpic/.break
+## break_interval="4"
+## break_previous="1254303082"
-# This function should be called when the modhule is loaded. It will
-# load the conf and functions submodules.
+# Loads functions
function break_source() {
source $(module_get_path break)/functions.sh
}
-# This function is responsible for putting the module in a useable state.
-#
-# It tryes to set some defaults.
+# This function is responsible for putting the module in a useable state by
+# setting some defaults.
function break_post_source() {
break_interval=7200
break_conf_path=${HOME}/.break
View
26 conf/auto/conf.sh
@@ -1,16 +1,16 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# Functions which overload default behavior of conf module functions are
-# declared here.
-# conf_auto_get_variables creates or uses variables which are
-# named like conf_auto_yourmodule. These variables are subject to change
-# when the conf_module supports array.
-# conf_auto_conf_interactive overloads conf_interactive for the
-# conf_auto module and also helps the user to set up his bash environment.
+# declared here.
+# conf_auto_get_variables() creates or uses variables which are named like
+# $conf_auto_yourmodule. These variables are subject to change when the
+# conf_module supports array.
+# conf_auto_conf_interactive() overloads conf_interactive() for the conf_auto
+# module and also helps the user to set up his bash environment.
-# Create missing variables like conf_auto_yourmodule for each module with
-# default value "n", and then output the list of variables of conf_auto.
-# @calls conf_get_variables
+# Create missing variables like $conf_auto_yourmodule for each module with
+# default value "n", and then output the list of variables of conf_auto().
+# @calls conf_get_variables()
# @stdout List of module variables.
function conf_auto_get_variables() {
# make up a variable for each module that have a conf path
@@ -25,11 +25,11 @@ function conf_auto_get_variables() {
conf_get_variables conf_auto
}
-# Informs the user of acceptable variable values, proposes to save all
-# current configuration and and helps him setting up the bashrc and
-# bash_logout files if necessary.
+# Informs the user of acceptable variable values, proposes to save all current
+# configuration and and helps him setting up the bashrc and bash_logout files
+# if necessary.
# @stdout Informations and prompts.
-# @calls conf_interactive
+# @calls conf_interactive()
# @log Info, if bashrc or bash_logout was modified.
function conf_auto_conf_interactive() {
local variable=""
View
37 conf/auto/functions.sh
@@ -1,22 +1,19 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# Function conf_auto_get_modules outputs the list of module which
-# the user choosed to auto save and load. Its interface is not subject to
-# changes although it currently contains a hack to workaround conf module not
+# Function conf_auto_get_modules() outputs the list of module which the user
+# choosed to auto save and load. Its interface is not subject to changes
+# although it currently contains a hack to workaround conf module not
# supporting arrays.
-# Function conf_auto_load_decorator decorates conf_load() and so
-# takes a module name as argument. This function can be called in your module
+# Function conf_auto_load_decorator() decorates conf_load() and so takes a
+# module name as argument. This function can be called in your module
# _post_source() function.
-# Function conf_auto_save_all calls conf_save() for all modules
-# which the user choosed to auto save and load.
+# Function conf_auto_save_all calls() conf_save() for all modules which the
+# user choosed to auto save and load.
-# Output a list of module names which the user choosed to use with this
-# module.
-# <p>
-# Its interface is not subject to changes although it currently contains a
-# hack to workaround conf module not supporting arrays.
-# <p>
-# The so-called hack is that it uses variables like conf_auto_yourmodule
+# Output a list of module names which the user choosed to use with this module.
+# Its interface is not subject to changes although it currently contains a hack
+# to workaround conf module not supporting arrays.
+# The so-called hack is that it uses variables like $conf_auto_yourmodule
# instead of an array of module names.
function conf_auto_get_modules() {
local variable=""
@@ -34,8 +31,8 @@ function conf_auto_get_modules() {
}
# Save configuration of each module which the users choosed to use with
-# conf_auto.
-# @calls conf_auto_get_modules, conf_save()
+# conf_auto().
+# @calls conf_auto_get_modules(), conf_save()
function conf_auto_save_all() {
for module_name in $(conf_auto_get_modules); do
conf_save $module_name
@@ -43,8 +40,8 @@ function conf_auto_save_all() {
}
# Load configuration of each module which the users choosed to use with
-# conf_auto.
-# @calls conf_auto_get_modules, conf_load()
+# conf_auto().
+# @calls conf_auto_get_modules(), conf_load()
function conf_auto_load_all() {
for module_name in $(conf_auto_get_modules); do
conf_load $module_name
@@ -53,7 +50,7 @@ function conf_auto_load_all() {
# Save the configuration of a given module only if the user choosed to use
# it with conf_auto.
-# @calls conf_auto_get_modules, conf_save()
+# @calls conf_auto_get_modules(), conf_save()
function conf_auto_save_decorator() {
local module_name="$1"
@@ -64,7 +61,7 @@ function conf_auto_save_decorator() {
# Loads the configuration of a given module only if the user choosed to use
# it with conf_auto.
-# @calls conf_auto_get_modules, conf_load()
+# @calls conf_auto_get_modules(), conf_load()
function conf_auto_load_decorator() {
local module_name="$1"
View
18 conf/auto/source.sh
@@ -2,14 +2,11 @@
# -*- coding: utf-8 -*-
# This submodule of conf allows the user to define the modules which config
# should be auto saved and auto loaded.
-# <p>
-# It is the only module which _post_source() function should call conf_load()
-# because other module should call conf_auto_load_decorator() to load a
-# module configuration <b>if</b> the user wants it autoloaded.
-# <p>
+# It is the only module which _post_source() function, conf_auto_post_source()
+# should call conf_load() because other module should have their configuration
+# loaded by conf_auto_load_all().
# See conf_auto/functions.sh for information about the additionnal API for
# conf.
-# <p>
# See conf_auto/conf.sh for information about the conf overloads for this
# module.
@@ -20,11 +17,10 @@ function conf_auto_source() {
}
# Sets conf_auto_conf_path and loads the module configuration.
-# <p>
-# Note: your modules should not call conf_load in their _post_source() func,
-# it should call conf_auto_load_decorator() instead, see functions.sh for
-# more details.
-# @calls conf_load
+# Note: your modules should not call conf_load in their _post_source() func, it
+# should call conf_auto_load_decorator() instead, see functions.sh for more
+# details.
+# @calls conf_load()
function conf_auto_post_source() {
conf_auto_conf_path="$HOME/.conf_auto"
View
14 conf/functions.sh
@@ -5,22 +5,22 @@
# conf/module.sh.
# This script basically declares CRUD functions for given configuration file
# path and given set of configuration variables.
-# Functions declared in this file are likely to change in future major
-# versions because the features that could be added are:
+# Functions declared in this file are likely to change in future major versions
+# because the features that could be added are:
# - array support in configurations,
# - better (hidden) password prompt support,
# - the user interface could use multiple frontends,
# Note that <a href="http://code.google.com/p/shesfw/">shesfw</a> is open
-# source and has an (unfinished) user interface API with several backends
-# which could be useable for example with new generation browsers like:
+# source and has an (unfinished) user interface API with several backends which
+# could be useable for example with new generation browsers like:
# - <a href="http://uzbl.org">uzbl</a>,
# - <a href="http://vimpression.org">vimpression</a>,
# - <a href="http://surf.suckless.org">surf</a>
# Saves given variables in the given configuration file.
-# This function uses sed to update variables in the configuration file if
-# the file contains a declaration of this variable. This is likely to be
-# dropped in the future.
+# This function uses sed to update variables in the configuration file if the
+# file contains a declaration of this variable. This is likely to be dropped in
+# the future.
# Missing directories will be created if necessary.
# @param Path to configuration file
# @param List of variable names
View
25 conf/module.sh
@@ -3,19 +3,18 @@
# All functions defined in this file take a module name as parameter, and are
# polite. Refer to the polite standard chapter in the documentation to figure
# how to overload the behaviour of any of these functions.
-# The highest level function is conf which runs all functions declared in
-# this file at some point. It makes configuring a module easy for the user,
-# who has to type in bash:
+# The highest level function is conf which runs all functions declared in this
+# file at some point. It makes configuring a module easy for the user, who has
+# to type in bash:
# # this will run the interactive module configurator
# conf yourmodule
-# Medium level functions are conf_save(), conf_load() and
-# conf_interactive() which only encapsulate the actual conf functions which
-# are declared in functions.sh.
-# Lowest level functions are conf_get_variables() and
-# conf_get_path(). The first outputs the name of the variables of the module
-# for use in conf_save() and conf_interactive(), and the latter outputs the
-# path to the module configuration file which is used by conf_save() and
-# conf_load().
+# Medium level functions are conf_save(), conf_load() and conf_interactive()
+# which only encapsulate the actual conf functions which are declared in
+# conf/functions.sh.
+# Lowest level functions are conf_get_variables() and conf_get_path(). The
+# first outputs the name of the variables of the module for use in conf_save()
+# and conf_interactive(), and the latter outputs the path to the module
+# configuration file which is used by conf_save() and conf_load().
# @polite All functions of this script are polite.
# Configure a module.
@@ -89,7 +88,7 @@ function conf_load() {
# This function interactively prompts the user to change the values of all
# variables of a module.
# For example, calling `conf_interactive yourmodule` will prompt the user to
-# change values of all variables prefixed with yourmodule (ie.
+# change values of all variables prefixed with yourmodule (for example
# $yourmodule_conf_path, $yourmodule_preference ...)
# Note that this method does not save the new values.
#
@@ -112,7 +111,7 @@ function conf_interactive() {
mlog debug "Done interactive configuration for $module_name"
}
-# This function outputs all variable names which are prefixed by the given
+# This function outputs all variable names which are prefixed by the given
# module name.
#
# WARNING: if the first element is a module name then eval will be used. If the
View
6 conf/source.sh
@@ -1,8 +1,8 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# This module declares functions to interface with configuration variables
-# and files in functions.sh, and functions that take a module as argument
-# in module.sh.
+# This module declares functions to interface with configuration variables and
+# files in functions.sh, and functions that take a module as argument in
+# module.sh.
#
# See conf/functions.sh for more details on avalaible functions.
# See conf/module.sh for details concerning functions that work with modules.
View
8 docs/bashdoc/source.sh
@@ -1,6 +1,12 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# Bashdoc tiein for the docs module.
+# Bashdoc tiein for the docs module. Not used anymore.
+
+# Blacklists the module.
+# @calls module_blacklist_add()
+function docs_bashdoc_post_source() {
+ module_blacklist_add docs_bashdoc
+}
# Outputs the documentation for a given module to
# $docs_path/modules/$module_name.
View
7 docs/source.sh
@@ -1,9 +1,9 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
# The role of this module is to generate the documentation of installed modules.
-# It depends on bashdoc which is provided.
-# <p>
-# Type "conf docs" to configure the output directory.
+# Example usage:
+## conf docs # configure variables such as the output dir
+## docs # run the generator
# Sets up the default path.
function docs_post_source() {
@@ -31,6 +31,7 @@ function docs() {
rst2html "$(module_get_path module)/docs/guide.rst" > "$docs_path/bashworks_guide.html"
}
+# Regenerates the example documentation.
function docs_test() {
docs_path="$(module_get_path docs)/bwdocs/example/"
if [[ ! -d "$docs_path" ]]; then
View
9 hack/functions.sh
@@ -1,8 +1,10 @@
+#!/bin/bash
+# -*- coding: utf-8 -*-
# Various bash hacks.
# Check if a variable is a non empty array.
# @stdout "Yes" if the variable is a non empty array.
-# @param Variable name
+# @param Name of the variable to check.
function hack_is_non_empty_array() {
declare -a | grep -q $1=\'\(\\[;
@@ -12,9 +14,8 @@ function hack_is_non_empty_array() {
}
# Adds each repository path to CDPATH environment variable.
-# <pre>
-# # change directory to somemodule, whatever is the current directory
-# cd somemodule
+## # change directory to somemodule, whatever is the current directory
+## cd somemodule
# @variable CDPATH, repo_path
function hack_cdpath() {
local repo_path=""
View
2 hack/shunit2/non_empty_array.sh
@@ -1,3 +1,5 @@
+#!/bin/bash
+# -*- coding: utf-8 -*-
# Tests for hack_is_non_empty_array()
# Ensures that hack_is_non_empty_array() outputs nothing if variable is not an
View
98 mlog/bashinator-0.3.sh
@@ -5,10 +5,8 @@
#
# Created by Wolfram Schlich <wschlich@gentoo.org>
# Licensed under the GNU GPLv3
-
#
-# REQUIRED PROGRAMS
-# =================
+# *REQUIRED PROGRAMS*:
# - rm
# - touch
# - mktemp
@@ -17,33 +15,18 @@
# - sed
# - date
# - sendmail (default /usr/sbin/sendmail, can be overridden with __SendmailBin)
-#
# define the required minimum bash version for this
# bashinator release to function properly
export __BashinatorRequiredBashVersion=3.2.0
-#
-# bashinator control functions
-#
-
+# Initializes bashinator.
+# @variable $__BashinatorRequiredBashVersion default: 0.0.0
+# @variable $BASH_VERSINFO
+# @variable $EUID
+# @variable $PATH
function __boot() {
- # ----- head -----
- #
- # DESCRIPTION:
- # initializes bashinator
- #
- # ARGUMENTS:
- # /
- #
- # GLOBAL VARIABLES USED:
- # __BashinatorRequiredBashVersion (default: 0.0.0)
- # BASH_VERSINFO
- # EUID
- # PATH
- #
-
# check for required bash version
IFS='.'
set -- ${__BashinatorRequiredBashVersion:-0.0.0}
@@ -76,23 +59,14 @@ function __boot() {
} # __boot()
+# - dispatches the application.
+# - calls the __init() and __main()
+# - functions that have to be defined by the user.
+#
+# @param *: all arguments of the originally executed script
+# @variable Exit: can be set to a custom exit code from within
+# the user functions
function __dispatch() {
-
- # ----- head -----
- #
- # DESCRIPTION:
- # dispatches the application.
- # calls the __init() and __main()
- # functions that have to be defined by the user.
- #
- # ARGUMENTS:
- # *: all arguments of the originally executed script
- #
- # GLOBAL VARIABLES USED:
- # Exit: can be set to a custom exit code from within
- # the user functions
- #
-
# check for user defined __init() function
if ! declare -F __init >&/dev/null; then
__die 2 "function __init() does not exist, unable to dispatch application"
@@ -121,25 +95,12 @@ function __dispatch() {
} # __dispatch()
+# run application main pre-processing tasks
+# @variable $__ScriptSubCommandLog default: 0
+# @variable $__ScriptSubCommandLogFile
+# @variable $__ScriptLock default: 0
+# @variable $__ScriptLockFile
function __prepare() {
-
- # ----- head -----
- #
- # DESCRIPTION:
- # run application main pre-processing tasks
- #
- # ARGUMENTS:
- # /
- #
- # GLOBAL VARIABLES USED:
- # __ScriptSubCommandLog (default: 0)
- # __ScriptSubCommandLogFile
- # __ScriptLock (default: 0)
- # __ScriptLockFile
- #
-
- # ----- main -----
-
# handle script subcommand logfile
if [[ ${__ScriptSubCommandLog:-0} == 1 ]]; then
# create temporary logfile
@@ -177,25 +138,12 @@ function __prepare() {
} # __prepare()
+# run application main post-processing tasks
+# @variable $__ScriptSubCommandLog default: 0
+# @variable $__ScriptSubCommandLogFile
+# @variable $__ScriptLock default: 0
+# @variable $__ScriptLockFile
function __cleanup() {
-
- # ----- head -----
- #
- # DESCRIPTION:
- # run application main post-processing tasks
- #
- # ARGUMENTS:
- # /
- #
- # GLOBAL VARIABLES USED:
- # __ScriptSubCommandLog (default: 0)
- # __ScriptSubCommandLogFile
- # __ScriptLock (default: 0)
- # __ScriptLockFile
- #
-
- # ----- main -----
-
# remove script subcommand logfile
if [[ ${__ScriptSubCommandLog:-0} == 1 && "${__ScriptSubCommandLogFile}" != /dev/null ]]; then
__msg debug "removing script subcommand logfile '${__ScriptSubCommandLogFile}'"
View
28 mlog/source.sh
@@ -1,11 +1,31 @@
+#!/bin/bash
+# -*- coding: utf-8 -*-
+# Wraps around the _great_ *bashinator* logging library.
+# See mlog().
+
+# Loads Bashinator!
function mlog_source() {
source $(module_get_path mlog)/bashinator-0.3.sh
}
-function mlog_post_source() {
- conf_auto_load_decorator mlog
-}
-
+# Log a message with a given security.
+# Example usage:
+## mlog debug "Something happenned which might help you figuring what TF"
+## mlog info "Some script started correctly"
+## mlog notice "Database is 8 days old"
+## mlog warning "Database is older than your father"
+## mlog err "Database is not started"
+## mlog crit "Database crashed"
+## mlog alert "Unsecure data"
+## mlog emerg "Data lost, probably burning in hell" Example usage:
+## mlog debug "Something happenned which might help you figuring what TF"
+## mlog info "Some script started correctly"
+## mlog notice "Database is 8 days old"
+## mlog warning "Database is older than your father"
+## mlog err "Database is not started"
+## mlog crit "Database crashed"
+## mlog alert "Unsecure data"
+## mlog emerg "Data lost, probably burning in hell"
function mlog() {
local level="$1"
local message="$2"
View
9 mpd/functions.sh
@@ -1,17 +1,14 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Mpd management functions
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# Mplayer and ncmpc management functions.
-# This starts or reattach a screen session with both the player and the
-# remote controll in its windows.
+# This starts or reattach a screen session with both the player and the remote
+# controll in its windows.
function mpd_screen() {
screen -S music -c $mpd_screenrc -D -R
}
# Starts your player command in a loop.
-#
# Press Ctrl+C a few times to stop it.
function mpd_play() {
while true;
View
15 mpd/source.sh
@@ -1,23 +1,16 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Mpd management module
-# @Copyright Copyright 2009, James Pic
-# @License Apache
-#
-# This simple module handles making a remote http connection to mpd stream
-# and to mpd administration.
+# This simple module handles making a remote http connection to mpd stream and
+# to mpd administration.
#
-# Basically it presents some configurable shortcuts
+# Basically it presents some configurable shortcuts, if you like mpd, mplayer,
+# ncmpc and screen then maybe this module will be useful to you.
# Declares module configuration variable names.
function mpd_source() {
source $(module_get_path mpd)/functions.sh
}
-# Module initialization callback
-#
-# This function is responsible for putting the module in a useable state.
-#
# It sets some defaults and load the user configuration data.
function mpd_post_source() {
mpd_host=""
View
22 mtests/bashunit/assertions.sh
@@ -2,18 +2,14 @@
# -*- coding: utf-8 -*-
# Bashunit is a good script, but the assertion functions are very hard
# to use because they are not documented, and examples are like "assert true"
-# <p>
# This script provides functions for bashunit which are easier to use
# not only because they are documented, but also because working and
# challenging examples are provided.
# Asserts that a command returns a zero status.
-# <p>
# For example:
-# <pre>
-# assert_zero "ls foobar" # fails if foobar does not exist
-# assert_zero ls # passes if the working directory exists
-# </pre>
+## assert_zero "ls foobar" # fails if foobar does not exist
+## assert_zero ls # passes if the working directory exists
# @param Command and arguments to test
function mtests_bashunit_assert_zero() {
__bashunit_g_testMessage="Assert that $* returns 0 failed"
@@ -26,12 +22,9 @@ function mtests_bashunit_assert_zero() {
}
# Asserts that a mathematical expression is true.
-# <p>
# For example:
-# <pre>
-# assert_math "1 > 2" # fails
-# assert_math "1 == 1" # passes
-# </pre>
+## assert_math "1 > 2" # fails
+## assert_math "1 == 1" # passes
# Refer to Bash manual section "ARITHMETIC EVALUATION" for more information.
# @param Arithmetic expression to evaluate.
function mtests_bashunit_assert_math() {
@@ -44,12 +37,9 @@ function mtests_bashunit_assert_math() {
}
# Asserts that an expression returns 0.
-# <p>
# For example:
-# <pre>
-# assert_true "foobar =~ oob" # pass, "oob" is in "foobar"
-# assert_true "foo == bar" # fails, "foo" is different from "bar".
-# </pre>
+## assert_true "foobar =~ oob" # pass, "oob" is in "foobar"
+## assert_true "foo == bar" # fails, "foo" is different from "bar".
# Refer to Bash manual section "SHELL GRAMMAR" subsection "Compound Commands".
# @param Expression to evaluate.
function mtests_bashunit_assert_true() {
View
8 mtests/bashunit/runner.sh
@@ -1,16 +1,14 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Break management module
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# @license GPLv3 (bashunit)
# This script contains bashunit outputter and listener functions.
#
# Bashunit uses listener functions which names are present in the
-# BASHUNIT_TESTLISTENERS environment variable, separated by spaces.
+# $BASHUNIT_TESTLISTENERS environment variable, separated by spaces.
# Listener functions are run when tests are executed.
#
# Bashunit uses outputter functions which names are present in the
-# BASHUNIT_OUTPUTTER environment variable, separated by spaces.
+# $BASHUNIT_OUTPUTTER environment variable, separated by spaces.
# Outputter funcitons are run when all tests are done executing.
# Outputs a green dot when a test passes and a red F when a test fails.
View
3 mtests/bashunit/source.sh
@@ -2,7 +2,6 @@
# -*- coding: utf-8 -*-
# Wraps around bashunit bash testing framework. Read bashunit/current/README for
# information about working with bashunit.
-# <p>
# Module tests which use bashunit should be in a subdirectory of the module
# named "bashunit".
@@ -29,7 +28,7 @@ function mtests_bashunit_post_source() {
# Runs bashunit tests of a module.
# @polite Will try yourmodule_mtests_basshunit()
-# @calls ResultColletor, RunAll, Run, $BASHUNIT_OUTPUTTER
+# @calls ResultColletor(), RunAll(), Run(), $BASHUNIT_OUTPUTTER
function mtests_bashunit() {
local bashunit_dir=$(module_get_path mtests)/bashunit/current
local module_name=$1
View
5 mtests/shunit/source.sh
@@ -2,11 +2,10 @@
# -*- coding: utf-8 -*-
# Wraps around shunit bash testing framework. Read shunit/current/README for
# information about working with shunit.
-# <p>
# Module tests which use shunit should be in a subdirectory of the module
# named "shunit".
-# Sets SHUNIT_HOME environment variable required by shunit.
+# Sets $SHUNIT_HOME environment variable required by shunit.
function mtests_shunit_pre_source() {
export SHUNIT_HOME="$(module_get_path mtests_shunit)/current"
}
@@ -18,7 +17,7 @@ function mtests_shunit_source() {
# Runs the test suites of a module.
# @polite Will try yourmodule_mtests_shunit()
-# @calls shuStart
+# @calls shuStart()
function mtests_shunit() {
local module_name=$1
View
2 mtests/shunit2/source.sh
@@ -2,9 +2,9 @@
# -*- coding: utf-8 -*-
# Wraps around shunit2 bash testing framework. Read shunit2/current/README for
# information about working with shunit2.
-# <p>
# Module tests which use shunit2 should be in a subdirectory of the module
# named "shunit2".
+# See hack/shunit2 for an example.
# Runs the shunit2 test suite of a given module.
# @polite Will try yourmodule_mtests_shunit2()
View
6 mtests/source.sh
@@ -2,15 +2,13 @@
# -*- coding: utf-8 -*-
# This module wraps around xUnit frameworks through submodules:
# - bashunit: tested, working in module break,
-# - shunit: untested, should work
-# - shunit2: untested, recommanded
+# - shunit: untested, should work,
+# - shunit2: untested, working in module hack,
# Runs all tests of a given module.
-# <p>
# If the module has a "bashunit" sub directory then mtests_bashunit will be
# called. Same goes for the other supported test frameworks: "shunit" and
# "shunit2",
-# <p>
# Shunit2 is recommanded.
# @polite Will try yourmodule_mtests()
# @calls mtests_bashunit, mtests_shunit, mtests_shunit2
View
11 os/source.sh
@@ -1,12 +1,9 @@
#!/usr/bin/env bash
-# -*- coding: utf-8 -*-
-# @Synopsis OS management module
-# @Copyright Copyright 2009, James Pic
-# @License Apache
-# In its early version, it just figures the os.
-# The plan: port multi-os compiles and bin/ symlinks from my .bashrc
+# In its early version, it just figures the os in a more general way than
+# $OSTYPE.
+# The plan: port multi-os compiles and bin/ symlinks from my .bashrc
-# Declares module configuration variable names and sets the os.
+# Sets $os_type to bsd or linux.
function os_source() {
uname -a | grep -q -i bsd
if [[ $? -eq 0 ]]; then
View
4 todo/functions.sh
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Todo management functions
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# A simple todo list module.
# Adds a todo to the list.
# @param Todo name
View
6 todo/source.sh
@@ -1,10 +1,8 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Todo management module
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# A simple module to manage a todo list.
-# Declares module configuration variable names.
+# Sources required functions.
function todo_source() {
source $(module_get_path todo)/functions.sh
}
View
4 vcs/git.sh
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis GIT VCS management functions
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# VCS interface for git.
# Commits with a given message
# @param Message
View
8 vcs/source.sh
@@ -1,21 +1,21 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis VCS management module
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# VCS wrapper, for git only right now.
-# Declares module configuration variable names.
+# Sources functions and aliases.
function vcs_source() {
source $(module_get_path vcs)/functions.sh
source $(module_get_path vcs)/aliases.sh
}
+# Sets variable defaultts.
function vcs_post_source() {
vcs_src_path=""
vcs_type=""
vps_conf_path=$(vcs_get_conf_path)
}
+# Returns $vps_src_path/.vcs.sh
function vcs_get_conf_path() {
echo ${vcs_src_path}/.vcs.sh
}
View
4 volume/functions.sh
@@ -1,8 +1,6 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Sound volume management functions
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# Some volue management functions which work under linux or bsd.
# Outputs the current volume
function volume_get_current() {
View
26 volume/source.sh
@@ -1,36 +1,22 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Sound volume management module
-# @Copyright Copyright 2009, James Pic
-# @License Apache
-#
-# This module provides a simple way to deal with volume management
-# under both bsd and linux systems.
-#
-# Volume incrementation and decrementation interval is saveable as well
-# as current volume.
-#
-# This can easely be used in scripts which your favourite window manager
-# can call.
+# This module provides a simple way to deal with volume management under both
+# bsd and linux systems.
+# Volume incrementation and decrementation interval is saveable as well as
+# current volume.
+# This can easely be used in scripts which your favourite window manager can
+# call.
-# Module source callback
-#
# This function should be called when the module is loaded, it will
# take care of loading the conf and function submodules.
function volume_source() {
source $(module_get_path volume)/functions.sh
}
-# Module initialization callback.
-#
# This function is responsible of preparing the module in a useable state
# by setting a default volume interval and getting the current volume.
-#
-# It also attemps to load the user conf.
function volume_post_source() {
volume_interval=5
volume_current=$(volume_get_current)
volume_conf_path=${HOME}/.volume
-
- conf_auto_load_decorator volume
}
View
41 vps/conf.sh
@@ -1,4 +1,30 @@
-# Prompts the admin for the host ip to use
+#!/bin/bash
+# -*- coding: utf-8 -*-
+# Configuration overloads for the vps module. Basically it offers a more
+# sofisticated way to configure $vps_ip, $vps_intranet and $vps_host_ip, which
+# you might want to set yourself in your script that calls `conf() vps`.
+
+# Prompts the admin for the host ip to use.
+# Example config:
+## # eth0
+## ROUTER_INTERNET_MAP+=("1.1.1.0")
+## ROUTER_INTRANET_MAP+=("192.168.1.")
+## ROUTER_ZONE_MAP+=("net")
+## ROUTER_LABEL_MAP+=("Non-free (eth0)")
+## # eth1
+## ROUTER_INTERNET_MAP+=("1.1.1.1")
+## ROUTER_INTRANET_MAP+=("192.168.2.")
+## ROUTER_ZONE_MAP+=("net2")
+## ROUTER_LABEL_MAP+=("Free (eth1)")
+# Note that those which are really required for vps_conf_interactive_network()
+# ar the INTERNET and INTRANET ones. The ZONE one is used by the swall module
+# tiein. The LABEL one is just to give your tubes a name, for example we use
+# one for clients and one for us and whatever we want to host, so when it says
+# "Free" the admin friend who helped, it really means "YAY ENJOY YOUR FREE GBPS
+# BRO!".
+# @variable $ROUTER_INTERNET MAP: list of internet ips.
+# @variable $ROUTER_INTRANET_MAP: list of *corresponding* intranet ips.
+# @variable $ROUTER_LABEL_MAP: optionnal.
function vps_conf_interactive_network() {
if [[ -z $ROUTER_INTERNET_MAP ]] || [[ -z $ROUTER_INTRANET_MAP ]]; then
mlog warning "ROUTER_INTERNET_MAP and ROUTER_INTRANET_MAP are not set, cannot configure network"
@@ -30,10 +56,15 @@ function vps_conf_interactive_network() {
}
function vps_conf_interactive() {
- unset vps_ip
- unset vps_intranet
- unset vps_host_ip
+ if [[ -z $ROUTER_INTERNET_MAP ]] || [[ -z $ROUTER_INTRANET_MAP ]]; then
+ unset vps_ip
+ unset vps_intranet
+ unset vps_host_ip
+ fi
conf_interactive vps
- vps_conf_interactive_network
+
+ if [[ -z $ROUTER_INTERNET_MAP ]] || [[ -z $ROUTER_INTRANET_MAP ]]; then
+ vps_conf_interactive_network
+ fi
}
View
97 vps/functions.sh
@@ -1,10 +1,9 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis VCS management functions
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# Linux-vserver management functions.
-# Outputs a free id between 100 and 240
+# Outputs a free id between 100 and 240 by checking $VPS_ETC_DIR.
+# @variable $VPS_ETC_DIR should be set to the vps config directory.
function vps_get_free_id() {
for i in {100..240}; do
grep -q "vps_id=\"${i}\"" ${VPS_ETC_DIR}/*.config
@@ -16,6 +15,9 @@ function vps_get_free_id() {
done
}
+# Outputs a config property of another VPS. For example:
+## foovps_ip=$(vps_get_property foovps ip)
+# @ calls conf_save()
function vps_get_property() {
local name="$1"
local property_name="vps_$2"
@@ -30,7 +32,7 @@ function vps_get_property() {
return 0
}
-# Generates a VPS
+# Generates a VPS, runs almost all functions.
function vps_generate() {
vps_getstage
vps_build
@@ -44,20 +46,28 @@ function vps_generate() {
vps_start
}
+# Make the vps mount $vps_packages_dir.
function vps_configure_fstab() {
echo ${vps_packages_dir} /usr/portage/packages none bind,ro 0 0 >> ${vps_root}/etc/fstab
}
+# Gets the ip of the $vps_mailer vps and uses it to set the vps "mail" host ip
+# to its /etc/hosts
function vps_configure_hosts() {
local mail_ip=$(vps_get_property $vps_mailer ip)
echo ${mail_ip} mail >> ${vps_root}/etc/hosts
}
+# Copies /etc/portage from the $vps_master vps to the current vps. This is
+# useful if all packages and tests should not be done on the host server.
function vps_configure_portage() {
local master_root=$(vps_get_property $vps_master root)
cp -r ${master_root}/etc/portage/* ${vps_root}/etc/portage
}
+# Set up the VPS interface to use host dummy0, $vps_ip, $vps_id as name and 24
+# as prefix. Also adds net.dummy0 to the vps default runlevel and configures
+# the vps /etc/conf.d/net and /etc/resolv.conf
function vps_configure_net() {
local workdir=`pwd`
@@ -84,6 +94,13 @@ function vps_configure_net() {
cd $workdir
}
+# Copies some configuration files from the $vps_admin home directory to the vps
+# /root:
+# - .ssh/authorized_key*
+# - .bashrc
+# - .vim*
+# - .screenrc
+# - .terminfo
function vps_configure_root() {
mkdir -p ${vps_root}/root/.ssh/
cp /home/${vps_admin}/.ssh/authorized_key* ${vps_root}/root/.ssh/
@@ -93,11 +110,15 @@ function vps_configure_root() {
cp -R /home/${vps_admin}/.terminfo ${vps_root}/root
}
+# Adds sshd to the default vps runlevel.
function vps_configure_runlevels() {
cd ${vps_root}/etc/runlevels/default
ln -sfn ../../init.d/sshd .
}
+# Downloads $vps_stage_url to $vps_stage_path if it's not already there. Note
+# that it sudoes it as nobody.
+# @uses sudo -u nobody wget
function vps_getstage() {
if [[ ! -f ${vps_stage_path} ]]; then
cd ${vps_stage_path%/*};
@@ -105,6 +126,8 @@ function vps_getstage() {
fi
}
+# Wraps around the vserver build command.
+# @uses vserver command
function vps_build() {
vserver ${vps_name} build \
--context ${vps_id} \
@@ -116,25 +139,47 @@ function vps_build() {
-t ${vps_stage_path}
}
+# enter the vserver
+# @uses vserver command
function vps_enter() {
vserver $vps_name enter
}
+
+# delete the vserver and its config, without warning.
+# @uses vserver command
function vps_delete() {
vserver $vps_name delete
rm -rf $vps_config_path
}
+
+# starts the vserver
+# @uses vserver command
function vps_start() {
vserver $vps_name start
}
+
+# stops the vserver
+# @uses vserver command
function vps_stop() {
vserver $vps_name stop
}
+
+# restarts the vserver
+# @uses vserver command
function vps_restart() {
vserver $vps_name restart
}
+
+# executes a command in the vps
+# @param command to execute
+# @uses vserver command
function vps_exec() {
vserver $vps_name exec $*
}
+
+# deletes all vps which name start with "test" without any warning.
+# @variable $vps_config_dir
+# @uses vserver delete command
function vps_delete_test_vps() {
current=`pwd`
@@ -149,9 +194,15 @@ function vps_delete_test_vps() {
cd $current
}
-# vps_emerge <emerge options>
-#
-# Emerges in $vps_master then from the binpkg to $vps_name
+
+# Wrapper to emerge for compiling programs:
+# - try to emerge with -K (binpkg)
+# - emerge on $vps_master if it required
+# - recurses.
+# Emerges in $vps_master then from the binpto $vps_name
+# @param emerge options
+# @call vps_emerge()
+# @uses vemerge command
function vps_emerge() {
vemerge $vps_name -- -K $@
@@ -159,7 +210,7 @@ function vps_emerge() {
return 0
fi
- vemerge $vps_master -- $@
+ vemerge $vps_master -- -av $@
if [[ $? != 0 ]]; then
echo "Emerging on $vps_master did not succeed, not merging binary package to $vps_name"
@@ -168,27 +219,35 @@ function vps_emerge() {
vemerge $vps_name -- -Kav $@
}
-# vps_use <package atom> <flags>
+
+# Adds the given use flag for the given package atom to the master vps package.keywords and then updates the current vps portage.
+# Example usage:
+## # Add sqlite use flag to php
+## # vps_euse dev-lang/php sqlite
+# @calls vps_updateportage
+# @param package atom
+# @param use flags
function vps_euse() {
local atom=$1
shift 1
local use=$@
- local current_vps=$vps_name
- vps_load_config $vps_master
- echo $atom $use >> $vps_root/etc/portage/package.use
- vps_load_config $current_vps
+ echo $atom >> $(vps_get_property $vps_master root)/etc/portage/package.keywords
vps_updateportage
}
-# vps_backport <package atom>
+
+# Adds the given package atom to the master vps package.keywords and then
+# updates the current server.
+# Example usage:
+## # 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
function vps_ebackport() {
local atom=$1
- local current_vps=$vps_name
- vps_load_config $vps_master
- echo $atom >> $vps_root/etc/portage/package.keywords
- vps_load_config $current_vps
+ echo $atom >> $(vps_get_property $vps_master root)/etc/portage/package.keywords
vps_updateportage
}
View
21 vps/source.sh
@@ -1,9 +1,16 @@
#!/usr/bin/env bash
# -*- coding: utf-8 -*-
-# @Synopsis Template management module
-# @Copyright Copyright 2009, James Pic
-# @License Apache
+# VPS management module, currently only supporting Linux-Vserver and Gentoo
+# GNU/Linux.
+# Example usage:
+## vps yourvps
+## vps_generate
+## vps_enter
+# See vps functions documentation for more information.
+# Sets the default globals if required.
+# @variable $VPS_DIR
+# @variable $VPS_ETC_DIR
function vps_pre_source() {
if [[ -z $VPS_DIR ]]; then
VPS_DIR="/vservers"
@@ -20,6 +27,7 @@ function vps_source() {
source $(module_get_path vps)/conf.sh
}
+# Unsets all vps variables.
function vps_post_source() {
vps_name=""
vps_root=""
@@ -33,16 +41,15 @@ function vps_post_source() {
vps_ip=""
vps_intranet=""
vps_host_ip=""
- vps_conf_path=$(vps_get_conf_path)
+ vps_conf_path=$(vps_conf_get_path)
}
-function vps_get_conf_path() {
+function vps_conf_get_path() {
echo $VPS_ETC_DIR/${vps_name}.config
}
# Initialises a vps configuration with a given name
# @param VPS name
-# @param Silent (optionnal)
function vps() {
local usage="vps \$vps_name"
vps_name="$1"
@@ -51,7 +58,7 @@ function vps() {
mlog error "Usage: $usage"
fi
- vps_conf_path=$(vps_get_conf_path)
+ vps_conf_path=$(vps_conf_get_path)
if [[ ! -f $vps_conf_path ]]; then
mlog info $vps_conf_path not found, configuring new vps
View
6 wepcrack/functions.sh
@@ -1,4 +1,10 @@
#!/bin/bash
+# My good old wepcrack script. It works very well and could teach you stuff,
+# *but* it is not ported to the framework architecture so it's blacklisted
+# until then.
+# Anyhow, if you want to enjoy it, then just do:
+## source wepcrack/functions.sh
+# It will display help by itself, as well as how to use the help pages.
CONFIG="config.sh"
ESSID=""
View
6 wepcrack/source.sh
@@ -1,4 +1,8 @@
+#!/bin/bash
+# -*- coding: utf-8 -*-
+# The wepcrack module wraps around aircrack-ng.
+
+# Blacklists the wepcrack module which has not been fully ported yet
function wepcrack_pre_source() {
- mlog warn "wepcrack module not ported to module.sh yet, still using 0alpha0 template ... err ..."
module_blacklist_add wepcrack
}

0 comments on commit 3912515

Please sign in to comment.
Something went wrong with that request. Please try again.