Permalink
Browse files

Merge branch 'master' of github.com:sm/sm

Conflicts:
	core/internal/shell/package/functions
  • Loading branch information...
2 parents 0821b4e + 6cd9953 commit 32fbaa51737c7763784b08c1ed8cbb6785069172 @mpapis mpapis committed Apr 19, 2012
View
5 bin/sm
@@ -25,7 +25,10 @@ set -o nounset # do not allow unset variables processing
initial_pwd="$PWD" # record where the script was run from right away.
# Account for symlinks
-if [[ -L $0 ]] ; then self=$(readlink $0) ; else self=$0 ; fi
+if [[ -L $0 ]]
+then self=$(readlink $0)
+else self=$0
+fi
# SM Framework path, may be overridden on command line or as exported environment variable.
[[ -n "${sm_path:-}" && -d "${sm_path:-}" ]] || sm_path="$(dirname $(builtin cd $(dirname $self); pwd ))"
@@ -48,6 +48,7 @@ checksum()
if __sm.checksum "${_type}" "${_file}" "${_checksum}" "${_variable}" "${_target}"
then return 0
- else return 1 ; fi
+ else return 1
+ fi
}
@@ -26,7 +26,9 @@ commands()
case "${_token}" in
(exists)
if __sm.command.exists "${1}" > /dev/null 2>&1
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
(is)
_subcommand="$1"
@@ -35,7 +37,9 @@ commands()
case "${_subcommand}" in
(function)
if __sm.command.is.function "$1" >/dev/null 2>&1
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
# (script)
# (binary)
@@ -51,7 +55,9 @@ commands()
case "${_subcommand}" in
(name)
if __sm.command.full.name "$1" >/dev/null 2>&1
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
(*)
(( $# )) && shift ||
@@ -63,19 +69,23 @@ commands()
case "$1" in
(as)
shift
- if [[ "$1" == "user" ]]
- then shift ; fi
+ [[ "$1" != "user" ]] || shift
+
_user="$1" && shift ||
__sm.log.fail "A user name or id must be specified after keyword 'as'"
# TODO: Check to ensure user name/id exists on the system
if __sm.command.run.as "${_user}" "${_flags[*]}" "$@"
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
(*)
_command="$1"
shift
if __sm.command.run "${_command}" "$@"
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
esac
;;
@@ -47,13 +47,17 @@ extension()
(get.uri)
[[ -n "${_name}" ]] || __sm.log.error "Extension name was not given for get uri."
if __sm.extension.get.uri "${_name}"
- then return 0 ; else return $? ; fi
+ then return 0
+ else return $?
+ fi
;;
(install)
[[ -n "${_name}" ]] || __sm.log.error "Extension name was not given for install."
__sm.modules.include internal/extensions/manipulation
if __sm.extension.install "${_name}" "${_uri}"
- then return 0 ; else return $? ; fi
+ then return 0
+ else return $?
+ fi
;;
(search|find)
[[ -n "${_name}" ]] || __sm.log.error "Extension name was not given for search."
@@ -164,30 +164,34 @@ files()
[[ -n "${_files}" ]] || __sm.log.fail "files must be given for 'files ${_command}'."
if __sm.files.${_command%s} "${_string}" "${_regex}" "${_files[@]}"
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
(replace)
[[ -n "${_regex}" ]] || __sm.log.fail "regexp must be given for 'files ${_command}'."
[[ -n "${_files}" ]] || __sm.log.fail "files must be given for 'files ${_command}'."
if __sm.files.${_command} "${_string}" "${_regex}" "${_files[@]}"
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
(open|md5|enter|join|expand|search|within|in|source|empty|nonempty|exist|exists|remove|create|touch|are.*|sha.*)
[[ -n "${_files}" ]] || __sm.log.fail "files must be given for 'files ${_command}'."
if __sm.files.${_command} "${_files[@]}"
- then return 0 ; else return 1 ; fi
+ then return 0
+ else return 1
+ fi
;;
(link)
[[ -e "${_source}" ]] ||
__sm.log.fail "Cannot link ${_source} to ${_target}, source does not exist!"
if [[ -f "${_target}" ]] && ! __sm.string.contains.word "-f" "${_flags[*]}"
- then
- __sm.log.fail "Cannot link ${_source} to ${_target} which exists as a file!"
+ then __sm.log.fail "Cannot link ${_source} to ${_target} which exists as a file!"
fi
if [[ -d "${_target}" ]] && ! __sm.string.contains.word "-f" "${_flags[*]}"
- then
- __sm.log.fail "Cannot link ${_source} to ${_target} which exists as a directory"
+ then __sm.log.fail "Cannot link ${_source} to ${_target} which exists as a directory"
fi
#TODO: what about the -f (force flag) to overwrite if target exists ?
__sm.files.link "${_source}" "${_target}" "${_flags[*]}"
@@ -128,7 +128,9 @@ process()
if [[ -n "${_file}" ]]
then
if __sm.process.lockfile.lock "${_file}"
- then return 0 ; else return 1 ; fi # Let caller deal with the choice of how to react.
+ then return 0
+ else return 1
+ fi # Let caller deal with the choice of how to react.
else
__sm.log.fail "No lockfile was specified for locking."
fi
@@ -23,7 +23,9 @@ timestamp()
case "${_command}" in
(show.new|show.current|set)
if __sm.timestamp.${_command}
- then return 0 ; else return $? ; fi
+ then return 0
+ else return $?
+ fi
;;
(*) __sm.log.error "Unknown command for extension '${_command}'."
esac
@@ -45,16 +45,20 @@ __sm.checksum()
then
if [[ "${_checksum}" == "${_sum}" ]]
then return 0
- else return 1 ; fi
+ else return 1
+ fi
else
if [[ -n "${_variable}" ]]
- then eval "${_variable}='${_sum}'" ; fi
+ then eval "${_variable}='${_sum}'"
+ fi
if [[ -n "${_target}" ]] # TODO: Sanity checking / error handling here.
- then echo "${_sum}" > "${_target}" ; fi
+ then echo "${_sum}" > "${_target}"
+ fi
if [[ -z "${_variable}" && -z "${_target}" ]]
- then echo "${_sum}" ; fi
+ then echo "${_sum}"
+ fi
fi
}
@@ -11,11 +11,8 @@ __sm.config.read()
_prefix="$5"
_delimiter="${6}"
- if [[ -z "${_variable}" ]]
- then _variable="${_key}" ; fi
-
- if [[ -n "${_prefix}" ]]
- then _variable="${_prefix}_${_variable}" ; fi
+ [[ -n "${_variable}" ]] || _variable="${_key}"
+ [[ -z "${_prefix}" ]] || _variable="${_prefix}_${_variable}"
# Run search in the same process to initialize cache variables.
__sm.config.settings.search ${_extension} "${_file}" > /dev/null
@@ -4,5 +4,6 @@ typeset -gx json_uri
typeset -gax extension_args
if (( $# ))
-then __sm.json.cli ${extension_args[@]} ; fi
+then __sm.json.cli ${extension_args[@]}
+fi
@@ -366,6 +366,7 @@ __sm.package.set.ldflags()
{
trace_filter package || set -o xtrace
export LDFLAGS
+
if ! __sm.string.contains.word "-L${active_path}/lib" "${LDFLAGS:-}"
then
LDFLAGS="-L${active_path}/lib${LDFLAGS:+ }${LDFLAGS:-}"
@@ -376,8 +377,10 @@ __sm.package.set.cc()
{
trace_filter package || set -o xtrace
export CC
+
if __sm.os.type.is darwin && [[ -x /usr/bin/gcc-4.2 ]]
- then CC=/usr/bin/gcc-4.2 ; fi
+ then CC=/usr/bin/gcc-4.2
+ fi
}
__sm.package.exports()
@@ -242,7 +242,8 @@ __sm.package.fetch()
__sm.package.fetch.checksum
if [[ -n "${package_checksum:-}" ]]
- then _args+=( "checksum" "${package_checksum}" ) ; fi
+ then _args+=( "checksum" "${package_checksum}" )
+ fi
fetch_uris "${package_url}" "${source_path}/${package_dir}" ${_args[@]} || return 1
@@ -6,7 +6,8 @@ __sm.process.is.running()
_pid=${1:-0} ; _pid_file="$2"
if (( _pid < 1 )) && [[ -s "${_pid_file}" ]]
- then read -r _pid < ${_pid_file} ; fi
+ then read -r _pid < ${_pid_file}
+ fi
kill -0 $_pid
}
@@ -28,7 +29,8 @@ __sm.process.status()
log "${name:-"process"}:"
if [[ -s "${_pid_file}" ]]
- then read -r _pid < ${_pid_file} ; fi
+ then read -r _pid < ${_pid_file}
+ fi
if (( ${_pid} > 0 ))
then
@@ -140,7 +142,8 @@ __sm.process.signal()
_signal="${1}" ; _pid="${2:-0}" ; _pid_file="${3:-}"
if (( _pid < 1 )) && [[ -s "${_pid_file}" ]]
- then read -r _pid < ${_pid_file} ; fi
+ then read -r _pid < ${_pid_file}
+ fi
if (( _pid > 0 ))
then
@@ -116,7 +116,8 @@ __sm.service.setup()
if user is root
then
if ! user exists ${service_user}
- then user create system user "${service_user}" group "${service_user}" ; fi
+ then user create system user "${service_user}" group "${service_user}"
+ fi
paths create "${service_root_paths[@]}"
@@ -475,10 +476,12 @@ __sm.service.init.start()
_command=( "${service_binary}" )
if [[ -n "${service_start_flags}" ]]
- then _command+=("${service_start_flags[@]}") ; fi
+ then _command+=("${service_start_flags[@]}")
+ fi
if [[ -n "${service_flags}" ]]
- then _command+=("${service_flags[@]}") ; fi
+ then _command+=("${service_flags[@]}")
+ fi
if (( service_run_as_root_flag ))
then
@@ -104,7 +104,8 @@ __sm.user.exists()
else # Name
if __sm.os.type.is darwin && __sm.string.contains.word "system" "${_flags}"
- then _user="_${_user#_}" ; fi
+ then _user="_${_user#_}"
+ fi
if __sm.os.type.is darwin
then
@@ -126,7 +127,8 @@ __sm.user.create.unless.exists()
fi
if ! __sm.user.exists "$1" ${_system}
- then __sm.user.add "$@" ; fi
+ then __sm.user.add "$@"
+ fi
}
__sm.user.add()
@@ -154,18 +154,21 @@ backtrace()
_string=${functrace[${_index}]}
_string="${_string%:*}"
if (( ${#_string} > ${_function_length} ))
- then _function_length=${#_string} ; fi
+ then _function_length=${#_string}
+ fi
_string=${funcfiletrace[${_index}]}
_string="${_string%:*}"
_string="${_string#$initial_pwd\/}"
if (( ${#_string} > ${_source_length} ))
- then _source_length=${#_string} ; fi
+ then _source_length=${#_string}
+ fi
_string=${funcfiletrace[${_index}]}
_string=${_string#*:}
if (( ${#_string} > ${_digits} ))
- then _digits=${#_string} ; fi
+ then _digits=${#_string}
+ fi
done
# Determine the format string output for the backtrace, based on your
@@ -203,7 +206,8 @@ backtrace()
_function="${_string%:*}"
_function_line=${_string#*:}
if [[ "$_source" == "zsh" && "$_function" == "zsh" ]]
- then _source="(console)"; fi
+ then _source="(console)"
+ fi
#_line=${funcfiletrace[$(( _index - 1 ))]}
#TODO: make it a switch if required, there is a need to trace internal functions
@@ -15,7 +15,9 @@ trap 'exit 1' USR2 # Exit on USR2 (send by backtrace to $__sm_pid)
export __sm_pid=$$ # Store process pid for closing from backtrace
if [[ -n "${ZSH_VERSION}" ]] # Persist ERR handler
-then set -e; else set -o errtrace ; fi
+then set -e
+else set -o errtrace
+fi
# Call backtrace on error
trap "backtrace \"A command has returned error code '(\$?)' without being handled.\"" ERR

0 comments on commit 32fbaa5

Please sign in to comment.