diff --git a/extensions/builtin/core/modules/shell/core/cli b/extensions/builtin/core/modules/shell/core/cli index fd857fc6..69683201 100644 --- a/extensions/builtin/core/modules/shell/core/cli +++ b/extensions/builtin/core/modules/shell/core/cli @@ -38,6 +38,16 @@ do debug_flag=1 ;; + --module=*) + preload_modules+=( ${token##--module=} ) + ;; + + --call=*) + call_action="${token##--call=}" + [[ "$call_action" =~ \/ ]] && preload_modules+=( ${call_action%/*} ) || true + call_action="${call_action##*/}" + ;; + --) shift #end of processing extension_args=("$@") diff --git a/extensions/builtin/core/modules/shell/core/initialize b/extensions/builtin/core/modules/shell/core/initialize index 926b37bb..12e3b5f9 100644 --- a/extensions/builtin/core/modules/shell/core/initialize +++ b/extensions/builtin/core/modules/shell/core/initialize @@ -54,6 +54,9 @@ true \ "${active_path:="${packages_path}/active"}" \ "${extension_args:=""}" +# Make sure preload_modules is an array +export preload_modules=( ${preload_modules[@]} ) + if [[ -d "${active_path}/bin" ]] then export PATH="${active_path}/bin:${active_path}/sbin:${PATH}" @@ -81,6 +84,16 @@ if [[ -n $bdsm_script ]] then # load script . $bdsm_script +elif [[ -n "${call_action}" ]] +then + if ! declare -F "${call_action}" >/dev/null + then + error "${call_action} is not a valid function name" + else + trace_filter action + "${call_action}" "${extension_args[@]}" + trace_filter + fi elif set | grep '^extension_args=(' >/dev/null then case "${extension_args[0]}" in diff --git a/extensions/builtin/core/modules/shell/modules/initialize b/extensions/builtin/core/modules/shell/modules/initialize index a9699617..67cc25be 100644 --- a/extensions/builtin/core/modules/shell/modules/initialize +++ b/extensions/builtin/core/modules/shell/modules/initialize @@ -14,3 +14,9 @@ do module_path="${module_def//*=}" log_search preload "$module_name" "${module_path}" done + +for module in ${preload_modules[@]} +do + module_or_error ${module} \ + "Can not load preload_module: ${module}" +done diff --git a/extensions/builtin/ext/modules/shell/project/dsl b/extensions/builtin/ext/modules/shell/project/dsl index 502e7a88..fdd94431 100644 --- a/extensions/builtin/ext/modules/shell/project/dsl +++ b/extensions/builtin/ext/modules/shell/project/dsl @@ -43,8 +43,7 @@ project_initialize() : \ "${shared_path:=${project_path}/shared}" \ "${release_path:=${project_path}/current}" \ - "${environment:="production"}" \ - "${vcs:=$(vcs "${shared_path}/${project}")}" + "${environment:="production"}" # Set the project log path into the shared path's log directory project_log_path="$shared_path/log" @@ -63,75 +62,3 @@ project_initialize() source_files ".${project}rc" fi } - -# -# ## vcs() -# -# Detect and set the vcs, if any, for the current project. -# -# ### Input Parameters -# -# First parameter must be the path to a repository for determining the VCS. -# -# ### Stream Outputs -# -# None. -# -# ### Environmental effects -# -# The environment variable 'vcs' will be set to the VCS detected, or 'git' by -# default. -# -# ### Return Codes -# -# 0 for success -# -# ### Failure Scenarios -# -# Fails if no repository path is given. -# -# ### Usage Examples -# -# user$ vcs /home/appuser/shared/appuser -# user$ echo $vcs -# git -# -# ##### Code Walkthrough -vcs() -{ - # Store the first parameter in the path variable. This is the path that we - # will check to see what vcs it contains. - local _path="$1" - - # if the path variable is nonempty - if variable_is_nonempty _path - then - # and if there is a .git directory in the given path - if path_exists "${_path}/.git" - then - # Then set the vcs variable to git. - vcs="git" - - # and if there is a .svn directory in the given path - elif path_exists "${_path}/.svn" - then - # Then set the vcs variable to svn. - vcs="svn" - - # and if there is a .hg directory in the given path - elif path_exists "${_path}/.hg" - then - # Then set the vcs variable to hg. - vcs="hg" - - # # TODO: detect when vcs="fossil" - else - # otherwise default the scm to git - vcs="git" - fi - else - # Programming error, no path was passed in in order to determine the vcs - fail "Repository path must be given in order to detect the VCS used." - fi -} - diff --git a/extensions/builtin/ext/modules/shell/vcs/dsl b/extensions/builtin/ext/modules/shell/vcs/dsl index bf4fe6f3..0fc274da 100644 --- a/extensions/builtin/ext/modules/shell/vcs/dsl +++ b/extensions/builtin/ext/modules/shell/vcs/dsl @@ -49,7 +49,7 @@ directory_get() if cp -r ${_source} "${_target}" >/dev/null 2>&1 then - write "$(cd "${_source}"; pwd)" to "${_target}/.uri" + echo "$(cd "${_source}"; pwd)" > "${_target}/.uri" else fail "There was an error copying '${_source}'" fi @@ -67,7 +67,14 @@ git_get() local _target="${scm_path}/$( scm_identifier "${_url}" )" - if path_exists "$_target/.git" + _final_target=$( + builtin cd "${initial_pwd}" + mkdir -p "${_final_target}" + builtin cd "${_final_target}" + pwd + ) + + if [[ -d "$_target/.git" ]] then builtin cd "${_target}" git checkout master -f -q 2>&1 >/dev/null @@ -101,7 +108,7 @@ git_get() fail "Git pull failed." fi else - ensure_paths_exist "${_target}" + mkdir -p "${_target}" if git clone --depth 1 ${_url} "${_target}" 2>&1 >/dev/null then echo "${_url}" > "${_target}/.uri" @@ -109,20 +116,21 @@ git_get() local _url_https="${_url/git:\/\//https:\/\/}" if git clone --depth 1 ${_url_https} "${_target}" 2>&1 >/dev/null then - write "${_url_https}" to "${_target}/.uri" + echo "${_url_https}" > "${_target}/.uri" else fail "There was an error while cloning the repository from the url '${_url}'" fi fi fi + rm -rf "${_final_target}" 2>&1 >/dev/null - if ! cp -r "${_target}" "${_final_target}" 2>&1 >/dev/null + if ! cp -frT "${_target}" "${_final_target}" 2>&1 >/dev/null then fail "There was an error copying '${_target}' -> '${_final_target}'" fi - enter "$initial_pwd" + builtin cd "$initial_pwd" } hg_get() @@ -163,7 +171,7 @@ github_get() # use git for fetching github repo git_get "git://github.com/${_url}.git" "${_target}" "$@" # and overwrite repo uri - write "${_url}" to "${_target}/.uri" + echo "${_url}" > "${_target}/.uri" } archive_get() { @@ -225,6 +233,7 @@ is_archive_uri() { return 0 ;; esac + return 1 } # ## fetch\_uri() @@ -242,7 +251,7 @@ fetch_uri() log "${log_prefix}Fetching $1" unset scm_type - if path_exists "$1" # check for directory + if [[ -d "$1" ]] # check for directory then scm_type='directory' directory_get "$@" @@ -286,6 +295,11 @@ fetch_uri() esac } +fetch() +{ + fetch_uri "$@" +} + scm_help() { NIY "display help for scm" diff --git a/extensions/builtin/ext/modules/shell/vcs/modules b/extensions/builtin/ext/modules/shell/vcs/modules new file mode 100644 index 00000000..102ae21a --- /dev/null +++ b/extensions/builtin/ext/modules/shell/vcs/modules @@ -0,0 +1 @@ +bdsm/variables diff --git a/extensions/builtin/install/actions/install b/extensions/builtin/install/actions/install deleted file mode 100755 index 156ffd94..00000000 --- a/extensions/builtin/install/actions/install +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env bash - -install_bdsm diff --git a/extensions/builtin/install/modules/shell/modules b/extensions/builtin/install/modules/shell/modules index 37245241..6f4656e3 100644 --- a/extensions/builtin/install/modules/shell/modules +++ b/extensions/builtin/install/modules/shell/modules @@ -1,2 +1,3 @@ +bdsm/filesystem ext/vcs ext/users diff --git a/install b/install index 6d4277c5..e6967425 100755 --- a/install +++ b/install @@ -37,7 +37,8 @@ bdsm_path="$PWD" # Path to load everything from modules_path="${bdsm_path}/extensions/builtin/core/modules" export initial_pwd bdsm_path modules_path -extension_args=(install install) +preload_modules=( install ) +call_action=install_bdsm # basic options parsing . "${modules_path}/shell/core/cli" # initialize BDSM