Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

161 lines (153 sloc) 4.515 kb
#!/bin/sh
#
# SM Framework Core Module ~ Versioned FileSystem (versionedfs)
#
# API Version: 1.0.0
#
# paths *
#
# TODO: Finish this API documentation below
#
# paths move source target mode owner
# user$ paths move "freetds-0.91rc"* to "freetds-0.91"
#
#
# user$ paths enter "/usr/local/src"
#
#
# user$ paths exist /bin/sm
# user$ echo $?
# 0
#
# user$ paths exist /bin/asdfasdf
# user$ echo $?
# 1
#
#
# user$ cd ; sm call paths expand test
# /home/user/test
#
# user$ paths copy "freetds-0.91rc"* to "freetds-0.91"
#
# user$ paths create a b c
# user$ ls
# a b c
#
# user$ path remove /tmp/somedir /tmp/someotherdir
#
# user$ path copy to "$HOME/backup/" "$HOME/bin" "$HOME/projects"
#
# user$ path chown $USER "$HOME" "/usr/local"
#
#
# user$ path chmod $USER "$HOME" "/usr/local"
#
path() { paths "$@" ; }
paths()
{
trace_filter filesystem || set -o xtrace
local _token _command _path _paths _source _target _mode _owner _flags _glob __paths_commands
_paths=()
__paths_commands=(
"change owner to=chown"
"change rights to=chmod"
"exist=exists"
)
if __sm.command.detect "$*" "${__paths_commands[@]}"
then
_command="${__sm_command_dotted}"
shift "${__sm_command_words}"
else
__sm.log.fail "No command given.\nUsage: \npaths <command> ..."
fi
case "${_command}" in
(chmod)
_mode="${1}"
shift || __sm.log.fail "Mode must follow keywords 'chmod'"
;;
(chown)
_owner="${1}"
shift || __sm.log.fail "Owner must be provided after keyword 'owner'"
;;
esac
while (( $# ))
do
_token="$1" && shift
case "${_token}" in
(to)
_target="${1}"
shift || __sm.log.fail "Target path must be given after keyword 'to'"
;;
(from)
_source="${1}"
shift || __sm.log.fail "Source path must be given after keyword 'from'"
;;
(mode|permissions)
_mode="${1}"
shift || __sm.log.fail "Mode must follow keyword '${_token}'"
;;
(owner)
_owner="${1}"
shift || __sm.log.fail "Owner must be given after keyword 'owner'"
;;
(recursive|recursively)
_flags+=(-R)
;;
(matching|regex|glob)
_regex="$1"
shift ||
__sm.log.fail "Shell glob pattern string must b given after keyword '${_token}'"
;;
(in)
_paths+=("$1")
shift || __sm.log.fail "A path is expected following keyword 'in'"
;;
(*)
_paths+=("${_token}")
;;
esac
done
case "${_command}" in
(chown)
[[ -n "${_owner}" ]] || __sm.log.fail "'identity {user}[:{group}]' was not given."
[[ -n "${_paths}" ]] || __sm.log.fail "Paths must be given."
__sm.paths.chown "${_owner}" "${_flags[*]}" "${_paths[@]}"
;;
(chmod)
[[ -n "${_mode}" ]] || __sm.log.fail "'mode {file mode}' must be given."
[[ -n "${_paths}" ]] || __sm.log.fail "Paths to chmod must be given."
__sm.paths.chmod "${_mode}" "${_flags[*]}" "${_paths[@]}"
;;
(search)
[[ -n "${_paths}" ]] || __sm.log.fail "Path to search paths under must be given."
[[ -n "${_glob}" ]] || __sm.log.fail "Glob pattern was not given (matches {glob})."
__sm.paths.search "${_regex}" "${_paths}"
;;
(in)
[[ -n "${_paths}" ]] || __sm.log.fail "Path to list paths in must be given."
__sm.paths.in "${_paths[@]}"
;;
(absolute)
[[ -n "${_paths}" ]] || __sm.log.fail "Path to expand must be given."
__sm.paths.absolute "${_paths[@]}"
;;
(create|remove|enter|exists|join|expand)
[[ -n "${_paths}" ]] || __sm.log.fail "Path to ${_command} must be given."
__sm.paths.${_command} "${_paths[@]}"
;;
(copy)
[[ -n "${_target}" ]] || __sm.log.fail "Target path (to) for copying into must be given."
__sm.paths.copy "${_target}" "${_flags[*]}" "${_paths[@]}"
;;
(move)
[[ -n "${_source}" ]] || __sm.log.fail "Source must be given to ${_command} (from x)."
[[ -n "${_target}" ]] || __sm.log.fail "Target must be given to ${_command} (to y)."
__sm.paths.move "${_source}" "${_target}"
;;
(*)
__sm.log.fail "Unknown command for paths: '${_command}' "\
"A paths command must be specified as the first parameter: "\
"{chown,chmod,create,remove,copy,in,search,enter,exist,join,expand,move,copy}"
;;
esac
}
Jump to Line
Something went wrong with that request. Please try again.