added verbose mode for source_if_exists
and also expecting `file` instead of `source` as env. variable to make that possible without dancing around: ``` #!/bin/bash file=backup && yadm bootstrap; file=install && yadm bootstrap; file=configure &&yadm bootstrap; ```
This commit is contained in:
parent
5a2ed6c68d
commit
fdbb9cfe26
1 changed files with 14 additions and 9 deletions
|
@ -1,17 +1,17 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Save this file as ~/.config/yadm/bootstrap and make it executable. It expects
|
# Save this file as ~/.config/yadm/bootstrap and make it executable. It expects
|
||||||
# environment variable `source` with a name of shell script to execute.
|
# environment variable `file` with a name of shell script to execute.
|
||||||
# `source` can be relative to ~/.config/yadm/ or full path.
|
# `file` can be relative to ~/.config/yadm/ or has full path.
|
||||||
#
|
#
|
||||||
# Usage:
|
# Usage:
|
||||||
# source=install yadm bootstrap
|
# file=install yadm bootstrap
|
||||||
# or
|
# or
|
||||||
# source=~/.config/yadm/install yadm bootstrap
|
# file=~/.config/yadm/install yadm bootstrap
|
||||||
#
|
#
|
||||||
# where `~/.config/yadm/install` can be like this:
|
# where `~/.config/yadm/install` can be like this:
|
||||||
#
|
#
|
||||||
# [[ ! $(type -t install) = 'function' ]] && echo "Usage: source=$(basename "$0") yadm bootstrap" && exit 1
|
# [[ ! $(type -t install) = 'function' ]] && echo "Usage: file=$(basename "$0") yadm bootstrap" && exit 1
|
||||||
#
|
#
|
||||||
# confirm yes 'softwareupdate --agree-to-license --install --all' "$(info 'Install ' warning 'OSX updates')"
|
# confirm yes 'softwareupdate --agree-to-license --install --all' "$(info 'Install ' warning 'OSX updates')"
|
||||||
# install 'brew' '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
|
# install 'brew' '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
|
||||||
|
@ -42,7 +42,12 @@ warning() {
|
||||||
}
|
}
|
||||||
|
|
||||||
source_if_exists() {
|
source_if_exists() {
|
||||||
if [[ -f $1 ]]; then source "$1"; else return 1; fi
|
local src=$1
|
||||||
|
local verbose="${2:-no}"
|
||||||
|
|
||||||
|
[[ ! -f $src ]] && return 1;
|
||||||
|
[[ "${verbose:0:1}" == v* ]] && printf "%s\n\n" "$(info "-> $src")";
|
||||||
|
source "$src"
|
||||||
}
|
}
|
||||||
|
|
||||||
command_exists () {
|
command_exists () {
|
||||||
|
@ -84,6 +89,6 @@ confirm() {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
source_if_exists "$(dirname "${0}")/$source" ||
|
source_if_exists "$(dirname "${0}")/$file" v ||
|
||||||
source_if_exists $source ||
|
source_if_exists $file v ||
|
||||||
([[ -z $source ]] && echo "Usage: source=FILE yadm bootstrap" || echo "Can't locate file '$source' for bootstrapping")
|
([[ -z $file ]] && echo "Usage: file=FILENAME yadm bootstrap" || echo "Can't locate file '$file' for bootstrapping")
|
||||||
|
|
Loading…
Reference in a new issue