Skip to content

Commit

Permalink
Code formatting update.
Browse files Browse the repository at this point in the history
  • Loading branch information
wayneeseguin committed Apr 19, 2012
1 parent 2279ee2 commit fcc0437
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 45 deletions.
5 changes: 4 additions & 1 deletion bin/sm
Expand Up @@ -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 ))"
Expand Down
3 changes: 2 additions & 1 deletion core/api/shell/checksum/functions
Expand Up @@ -48,6 +48,7 @@ checksum()

if __sm.checksum "${_type}" "${_file}" "${_checksum}" "${_variable}" "${_target}"
then return 0
else return 1 ; fi
else return 1
fi
}

24 changes: 17 additions & 7 deletions core/api/shell/command/functions
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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 ||
Expand All @@ -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
;;
Expand Down
8 changes: 6 additions & 2 deletions core/api/shell/extensions/functions
Expand Up @@ -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."
Expand Down
18 changes: 11 additions & 7 deletions core/api/shell/files/functions
Expand Up @@ -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[*]}"
Expand Down
4 changes: 3 additions & 1 deletion core/api/shell/process/functions
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion core/api/shell/time/functions
Expand Up @@ -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
Expand Down
12 changes: 8 additions & 4 deletions core/internal/shell/checksum/functions
Expand Up @@ -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
}

7 changes: 2 additions & 5 deletions core/internal/shell/config/functions
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion core/internal/shell/json/initialize
Expand Up @@ -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

8 changes: 6 additions & 2 deletions core/internal/shell/package/functions
Expand Up @@ -254,6 +254,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:-}"
Expand All @@ -264,8 +265,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()
Expand Down Expand Up @@ -637,7 +640,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

Expand Down
9 changes: 6 additions & 3 deletions core/internal/shell/process/functions
Expand Up @@ -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
}
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions core/internal/shell/service/functions
Expand Up @@ -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[@]}"

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions core/internal/shell/user/functions
Expand Up @@ -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
Expand All @@ -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()
Expand Down
12 changes: 8 additions & 4 deletions core/sm/shell/log/functions
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion core/sm/shell/log/initialize
Expand Up @@ -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
Expand Down

0 comments on commit fcc0437

Please sign in to comment.