Format yadm and bootstrap with shfmt
Command: shfmt -w -ln bash -i 2 -ci <file>
This commit is contained in:
parent
bb21c9a267
commit
f5dfc7ab01
2 changed files with 218 additions and 221 deletions
16
bootstrap
16
bootstrap
|
@ -35,18 +35,20 @@ REPO_URL=""
|
|||
|
||||
function _private_yadm() {
|
||||
unset -f yadm
|
||||
if command -v yadm &> /dev/null; then
|
||||
if command -v yadm &>/dev/null; then
|
||||
echo "Found yadm installed locally, removing remote yadm() function"
|
||||
unset -f _private_yadm
|
||||
command yadm "$@"
|
||||
else
|
||||
function yadm() { _private_yadm "$@"; }; export -f yadm
|
||||
function yadm() { _private_yadm "$@"; }
|
||||
export -f yadm
|
||||
echo WARNING: Using yadm remotely. You should install yadm locally.
|
||||
curl -fsSL "$YADM_REPO/raw/$YADM_RELEASE/yadm" | bash -s -- "$@"
|
||||
fi
|
||||
}
|
||||
export -f _private_yadm
|
||||
function yadm() { _private_yadm "$@"; }; export -f yadm
|
||||
function yadm() { _private_yadm "$@"; }
|
||||
export -f yadm
|
||||
|
||||
# if being sourced, return here, otherwise continue processing
|
||||
return 2>/dev/null
|
||||
|
@ -57,7 +59,7 @@ function remote_yadm() {
|
|||
}
|
||||
|
||||
function ask_about_source() {
|
||||
if ! command -v yadm &> /dev/null; then
|
||||
if ! command -v yadm &>/dev/null; then
|
||||
echo
|
||||
echo "***************************************************"
|
||||
echo "yadm is NOT currently installed."
|
||||
|
@ -83,7 +85,7 @@ function build_url() {
|
|||
echo " 3. GitLab"
|
||||
echo " 4. Other"
|
||||
echo
|
||||
read -r -p "Where is your repo? (1/2/3/4) ->" choice < /dev/tty
|
||||
read -r -p "Where is your repo? (1/2/3/4) ->" choice </dev/tty
|
||||
case $choice in
|
||||
1)
|
||||
REPO_URL="https://github.com/"
|
||||
|
@ -97,7 +99,7 @@ function build_url() {
|
|||
*)
|
||||
echo
|
||||
echo Please specify the full URL of your dotfiles repo
|
||||
read -r -p "URL ->" choice < /dev/tty
|
||||
read -r -p "URL ->" choice </dev/tty
|
||||
REPO_URL="$choice"
|
||||
return
|
||||
;;
|
||||
|
@ -107,7 +109,7 @@ function build_url() {
|
|||
echo "Provide your user and repo separated by '/'"
|
||||
echo "For example: UserName/dotfiles"
|
||||
echo
|
||||
read -r -p "User/Repo ->" choice < /dev/tty
|
||||
read -r -p "User/Repo ->" choice </dev/tty
|
||||
[[ "$choice" =~ ^[^[:space:]]+/[^[:space:]]+$ ]] || {
|
||||
echo "Not formatted as USER/REPO"
|
||||
REPO_URL=
|
||||
|
|
197
yadm
197
yadm
|
@ -89,7 +89,7 @@ function main() {
|
|||
param="${param//\\/\\\\}"
|
||||
param="${param//$_tab/\\$_tab}"
|
||||
param="${param// /\\ }"
|
||||
_fc+=( "$param" )
|
||||
_fc+=("$param")
|
||||
done
|
||||
FULL_COMMAND="${_fc[*]}"
|
||||
|
||||
|
@ -100,10 +100,10 @@ function main() {
|
|||
# parse command line arguments
|
||||
local retval=0
|
||||
internal_commands="^(alt|bootstrap|clean|clone|config|decrypt|encrypt|enter|git-crypt|help|--help|init|introspect|list|perms|transcrypt|upgrade|version|--version)$"
|
||||
if [ -z "$*" ] ; then
|
||||
if [ -z "$*" ]; then
|
||||
# no argumnts will result in help()
|
||||
help
|
||||
elif [[ "$1" =~ $internal_commands ]] ; then
|
||||
elif [[ "$1" =~ $internal_commands ]]; then
|
||||
# for internal commands, process all of the arguments
|
||||
YADM_COMMAND="${1//-/_}"
|
||||
YADM_COMMAND="${YADM_COMMAND/__/}"
|
||||
|
@ -111,10 +111,10 @@ function main() {
|
|||
shift
|
||||
|
||||
# commands listed below do not process any of the parameters
|
||||
if [[ "$YADM_COMMAND" =~ ^(enter|git_crypt)$ ]] ; then
|
||||
if [[ "$YADM_COMMAND" =~ ^(enter|git_crypt)$ ]]; then
|
||||
YADM_ARGS=("$@")
|
||||
else
|
||||
while [[ $# -gt 0 ]] ; do
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case $key in
|
||||
-a) # used by list()
|
||||
|
@ -162,7 +162,6 @@ function main() {
|
|||
|
||||
}
|
||||
|
||||
|
||||
# ****** Alternate Processing ******
|
||||
|
||||
function score_file() {
|
||||
|
@ -173,7 +172,7 @@ function score_file() {
|
|||
score=0
|
||||
local template_cmd=""
|
||||
|
||||
IFS=',' read -ra fields <<< "$conditions"
|
||||
IFS=',' read -ra fields <<<"$conditions"
|
||||
for field in "${fields[@]}"; do
|
||||
local label=${field%%.*}
|
||||
local value=${field#*.}
|
||||
|
@ -185,32 +184,32 @@ function score_file() {
|
|||
default)
|
||||
delta=0
|
||||
;;
|
||||
a|arch)
|
||||
a | arch)
|
||||
[[ "$value" = "$local_arch" ]] && delta=1
|
||||
;;
|
||||
o|os)
|
||||
o | os)
|
||||
[[ "$value" = "$local_system" ]] && delta=2
|
||||
;;
|
||||
d|distro)
|
||||
d | distro)
|
||||
[[ "${value// /_}" = "${local_distro// /_}" ]] && delta=4
|
||||
;;
|
||||
f|distro_family)
|
||||
f | distro_family)
|
||||
[[ "${value// /_}" = "${local_distro_family// /_}" ]] && delta=8
|
||||
;;
|
||||
c|class)
|
||||
c | class)
|
||||
in_list "$value" "${local_classes[@]}" && delta=16
|
||||
;;
|
||||
h|hostname)
|
||||
h | hostname)
|
||||
[[ "$value" = "$local_host" ]] && delta=32
|
||||
;;
|
||||
u|user)
|
||||
u | user)
|
||||
[[ "$value" = "$local_user" ]] && delta=64
|
||||
;;
|
||||
e|extension)
|
||||
e | extension)
|
||||
# extension isn't a condition and doesn't affect the score
|
||||
continue
|
||||
;;
|
||||
t|template|yadm)
|
||||
t | template | yadm)
|
||||
if [ -d "$source" ]; then
|
||||
INVALID_ALT+=("$source")
|
||||
else
|
||||
|
@ -229,11 +228,11 @@ function score_file() {
|
|||
esac
|
||||
shopt -u nocasematch
|
||||
|
||||
if (( delta < 0 )); then
|
||||
if ((delta < 0)); then
|
||||
score=0
|
||||
return
|
||||
fi
|
||||
score=$(( score + 1000 + delta ))
|
||||
score=$((score + 1000 + delta))
|
||||
done
|
||||
|
||||
record_score "$score" "$target" "$source" "$template_cmd"
|
||||
|
@ -250,7 +249,7 @@ function record_score() {
|
|||
|
||||
# search for the index of this target, to see if we already are tracking it
|
||||
local -i index=$((${#alt_targets[@]} - 1))
|
||||
for (( ; index >= 0; --index )); do
|
||||
for (( ; index >= 0; --index)); do
|
||||
if [ "${alt_targets[$index]}" = "$target" ]; then
|
||||
break
|
||||
fi
|
||||
|
@ -314,7 +313,7 @@ function template_default() {
|
|||
|
||||
# the explicit "space + tab" character class used below is used because not
|
||||
# all versions of awk seem to support the POSIX character classes [[:blank:]]
|
||||
read -r -d '' awk_pgm << "EOF"
|
||||
read -r -d '' awk_pgm <<"EOF"
|
||||
BEGIN {
|
||||
classes = ARGV[2]
|
||||
for (i = 3; i < ARGC; ++i) {
|
||||
|
@ -437,7 +436,7 @@ EOF
|
|||
-v source="$input" \
|
||||
-v source_dir="$(builtin_dirname "$input")" \
|
||||
"$awk_pgm" \
|
||||
"$input" "${local_classes[@]}" > "$temp_file" || rm -f "$temp_file"
|
||||
"$input" "${local_classes[@]}" >"$temp_file" || rm -f "$temp_file"
|
||||
|
||||
move_file "$input" "$output" "$temp_file"
|
||||
}
|
||||
|
@ -646,7 +645,7 @@ function set_local_alt_values() {
|
|||
while IFS='' read -r class; do
|
||||
local_classes+=("$class")
|
||||
local_class="$class"
|
||||
done <<< "$all_classes"
|
||||
done <<<"$all_classes"
|
||||
|
||||
local_arch="$(config local.arch)"
|
||||
if [[ -z "$local_arch" ]]; then
|
||||
|
@ -683,7 +682,7 @@ function set_local_alt_values() {
|
|||
|
||||
function alt_linking() {
|
||||
local -i index
|
||||
for (( index = 0; index < ${#alt_targets[@]}; ++index )); do
|
||||
for ((index = 0; index < ${#alt_targets[@]}; ++index)); do
|
||||
local target="${alt_targets[$index]}"
|
||||
local source="${alt_sources[$index]}"
|
||||
local template_cmd="${alt_template_cmds[$index]}"
|
||||
|
@ -750,7 +749,7 @@ function clone() {
|
|||
DO_BOOTSTRAP=1
|
||||
local -a args
|
||||
local -i do_checkout=1
|
||||
while [[ $# -gt 0 ]] ; do
|
||||
while [[ $# -gt 0 ]]; do
|
||||
case "$1" in
|
||||
--bootstrap) # force bootstrap, without prompt
|
||||
DO_BOOTSTRAP=2
|
||||
|
@ -761,10 +760,10 @@ function clone() {
|
|||
--checkout)
|
||||
do_checkout=1
|
||||
;;
|
||||
-n|--no-checkout)
|
||||
-n | --no-checkout)
|
||||
do_checkout=0
|
||||
;;
|
||||
--bare|--mirror|--recurse-submodules*|--recursive|--separate-git-dir=*)
|
||||
--bare | --mirror | --recurse-submodules* | --recursive | --separate-git-dir=*)
|
||||
# ignore arguments without separate parameter
|
||||
;;
|
||||
--separate-git-dir)
|
||||
|
@ -861,7 +860,7 @@ function config() {
|
|||
[[ "$option" =~ $local_options ]] && use_repo_config=1
|
||||
done
|
||||
|
||||
if [ -z "$*" ] ; then
|
||||
if [ -z "$*" ]; then
|
||||
# with no parameters, provide some helpful documentation
|
||||
echo "yadm supports the following configurations:"
|
||||
echo
|
||||
|
@ -871,7 +870,7 @@ function config() {
|
|||
done
|
||||
echo
|
||||
local msg
|
||||
read -r -d '' msg << EOF
|
||||
read -r -d '' msg <<EOF
|
||||
Please read the CONFIGURATION section in the man
|
||||
page for more details about configurations, and
|
||||
how to adjust them.
|
||||
|
@ -996,7 +995,7 @@ function decrypt() {
|
|||
|
||||
[ -f "$YADM_ENCRYPT" ] && exclude_encrypted
|
||||
|
||||
if [ "$DO_LIST" = "YES" ] ; then
|
||||
if [ "$DO_LIST" = "YES" ]; then
|
||||
tar_option="t"
|
||||
else
|
||||
tar_option="x"
|
||||
|
@ -1036,11 +1035,11 @@ function encrypt() {
|
|||
# offer to add YADM_ARCHIVE if untracked
|
||||
archive_status=$("$GIT_PROGRAM" status --porcelain -uall "$(mixed_path "$YADM_ARCHIVE")" 2>/dev/null)
|
||||
archive_regex="^\?\?"
|
||||
if [[ $archive_status =~ $archive_regex ]] ; then
|
||||
if [[ $archive_status =~ $archive_regex ]]; then
|
||||
echo "It appears that $YADM_ARCHIVE is not tracked by yadm's repository."
|
||||
echo "Would you like to add it now? (y/n)"
|
||||
read -r answer < /dev/tty
|
||||
if [[ $answer =~ ^[yY]$ ]] ; then
|
||||
read -r answer </dev/tty
|
||||
if [[ $answer =~ ^[yY]$ ]]; then
|
||||
"$GIT_PROGRAM" add "$(mixed_path "$YADM_ARCHIVE")"
|
||||
fi
|
||||
fi
|
||||
|
@ -1104,7 +1103,7 @@ function git_command() {
|
|||
require_repo
|
||||
|
||||
# translate 'gitconfig' to 'config' -- 'config' is reserved for yadm
|
||||
if [ "$1" = "gitconfig" ] ; then
|
||||
if [ "$1" = "gitconfig" ]; then
|
||||
set -- "config" "${@:2}"
|
||||
fi
|
||||
|
||||
|
@ -1113,7 +1112,7 @@ function git_command() {
|
|||
|
||||
if [ "$YADM_WORK" = "$HOME" ]; then
|
||||
auto_private_dirs=$(config --bool yadm.auto-private-dirs)
|
||||
if [ "$auto_private_dirs" != "false" ] ; then
|
||||
if [ "$auto_private_dirs" != "false" ]; then
|
||||
for pdir in $(private_dirs all); do
|
||||
assert_private_dirs "$pdir"
|
||||
done
|
||||
|
@ -1138,7 +1137,7 @@ function help() {
|
|||
readonly padding=" "
|
||||
|
||||
local msg
|
||||
IFS='' read -r -d '' msg << EOF
|
||||
IFS='' read -r -d '' msg <<EOF
|
||||
Usage: yadm <command> [options...]
|
||||
|
||||
Manage dotfiles maintained in a Git repository. Manage alternate files
|
||||
|
@ -1201,7 +1200,7 @@ function init() {
|
|||
|
||||
function introspect() {
|
||||
case "$1" in
|
||||
commands|configs|repo|switches)
|
||||
commands | configs | repo | switches)
|
||||
"introspect_$1"
|
||||
;;
|
||||
esac
|
||||
|
@ -1284,7 +1283,7 @@ function list() {
|
|||
require_repo
|
||||
|
||||
# process relative to YADM_WORK when --all is specified
|
||||
if [ -n "$LIST_ALL" ] ; then
|
||||
if [ -n "$LIST_ALL" ]; then
|
||||
cd_work "List" || return
|
||||
fi
|
||||
|
||||
|
@ -1309,13 +1308,13 @@ function perms() {
|
|||
# only include private globs if using HOME as worktree
|
||||
if [ "$YADM_WORK" = "$HOME" ]; then
|
||||
# include all .ssh files (unless disabled)
|
||||
if [[ $(config --bool yadm.ssh-perms) != "false" ]] ; then
|
||||
if [[ $(config --bool yadm.ssh-perms) != "false" ]]; then
|
||||
GLOBS+=(".ssh" ".ssh/*" ".ssh/.[!.]*")
|
||||
fi
|
||||
|
||||
# include all gpg files (unless disabled)
|
||||
gnupghome="$(private_dirs gnupg)"
|
||||
if [[ $(config --bool yadm.gpg-perms) != "false" ]] ; then
|
||||
if [[ $(config --bool yadm.gpg-perms) != "false" ]]; then
|
||||
GLOBS+=("${gnupghome}" "${gnupghome}/*" "${gnupghome}/.[!.]*")
|
||||
fi
|
||||
fi
|
||||
|
@ -1326,7 +1325,7 @@ function perms() {
|
|||
# remove group/other permissions from collected globs
|
||||
#shellcheck disable=SC2068
|
||||
#(SC2068 is disabled because in this case, we desire globbing)
|
||||
chmod -f go-rwx ${GLOBS[@]} &> /dev/null
|
||||
chmod -f go-rwx ${GLOBS[@]} &>/dev/null
|
||||
# TODO: detect and report changing permissions in a portable way
|
||||
|
||||
}
|
||||
|
@ -1337,7 +1336,7 @@ function upgrade() {
|
|||
local -a submodules
|
||||
local repo_updates=0
|
||||
|
||||
[[ -n "${YADM_OVERRIDE_REPO}${YADM_OVERRIDE_ARCHIVE}" || "$YADM_DATA" = "$YADM_DIR" ]] && \
|
||||
[[ -n "${YADM_OVERRIDE_REPO}${YADM_OVERRIDE_ARCHIVE}" || "$YADM_DATA" = "$YADM_DIR" ]] &&
|
||||
error_out "Unable to upgrade. Paths have been overridden with command line options"
|
||||
|
||||
# choose a legacy repo, the version 2 location will be favored
|
||||
|
@ -1375,7 +1374,7 @@ function upgrade() {
|
|||
error_out "Unable to upgrade. Could not deinit submodule $submodule"
|
||||
}
|
||||
submodules+=("$submodule")
|
||||
done <<< "$submodule_status"
|
||||
done <<<"$submodule_status"
|
||||
|
||||
assert_parent "$YADM_REPO"
|
||||
mv "$LEGACY_REPO" "$YADM_REPO"
|
||||
|
@ -1395,7 +1394,7 @@ function upgrade() {
|
|||
echo "Moving $LEGACY_ARCHIVE to $YADM_ARCHIVE"
|
||||
assert_parent "$YADM_ARCHIVE"
|
||||
# test to see if path is "tracked" in repo, if so 'git mv' must be used
|
||||
if "$GIT_PROGRAM" ls-files --error-unmatch "$LEGACY_ARCHIVE" &> /dev/null; then
|
||||
if "$GIT_PROGRAM" ls-files --error-unmatch "$LEGACY_ARCHIVE" &>/dev/null; then
|
||||
"$GIT_PROGRAM" mv "$LEGACY_ARCHIVE" "$YADM_ARCHIVE" && repo_updates=1
|
||||
else
|
||||
mv -i "$LEGACY_ARCHIVE" "$YADM_ARCHIVE"
|
||||
|
@ -1407,9 +1406,7 @@ function upgrade() {
|
|||
"$YADM_LEGACY_DIR/config" \
|
||||
"$YADM_LEGACY_DIR/encrypt" \
|
||||
"$YADM_LEGACY_DIR/bootstrap" \
|
||||
"$YADM_LEGACY_DIR"/hooks/{pre,post}_* \
|
||||
;
|
||||
do
|
||||
"$YADM_LEGACY_DIR"/hooks/{pre,post}_*; do
|
||||
if [ -e "$legacy_path" ]; then
|
||||
new_filename="${legacy_path#"$YADM_LEGACY_DIR/"}"
|
||||
new_filename="$YADM_DIR/$new_filename"
|
||||
|
@ -1417,7 +1414,7 @@ function upgrade() {
|
|||
echo "Moving $legacy_path to $new_filename"
|
||||
assert_parent "$new_filename"
|
||||
# test to see if path is "tracked" in repo, if so 'git mv' must be used
|
||||
if "$GIT_PROGRAM" ls-files --error-unmatch "$legacy_path" &> /dev/null; then
|
||||
if "$GIT_PROGRAM" ls-files --error-unmatch "$legacy_path" &>/dev/null; then
|
||||
"$GIT_PROGRAM" mv "$legacy_path" "$new_filename" && repo_updates=1
|
||||
else
|
||||
mv -i "$legacy_path" "$new_filename"
|
||||
|
@ -1430,10 +1427,10 @@ function upgrade() {
|
|||
"$GIT_PROGRAM" -C "$YADM_WORK" submodule update --init --recursive -- "$submodule"
|
||||
done
|
||||
|
||||
[ "$actions_performed" -eq 0 ] && \
|
||||
[ "$actions_performed" -eq 0 ] &&
|
||||
echo "No legacy paths found. Upgrade is not necessary"
|
||||
|
||||
[ "$repo_updates" -eq 1 ] && \
|
||||
[ "$repo_updates" -eq 1 ] &&
|
||||
echo "Some files tracked by yadm have been renamed. These changes should probably be commited now."
|
||||
|
||||
exit 0
|
||||
|
@ -1443,7 +1440,8 @@ function upgrade() {
|
|||
function version() {
|
||||
|
||||
echo "bash version $BASH_VERSION"
|
||||
printf " "; "$GIT_PROGRAM" --version
|
||||
printf " "
|
||||
"$GIT_PROGRAM" --version
|
||||
echo "yadm version $VERSION"
|
||||
exit_with_hook 0
|
||||
|
||||
|
@ -1472,7 +1470,7 @@ function exclude_encrypted() {
|
|||
encrypt_data=""
|
||||
while IFS='' read -r line || [ -n "$line" ]; do
|
||||
encrypt_data="${encrypt_data}${line}${newline}"
|
||||
done < "$YADM_ENCRYPT"
|
||||
done <"$YADM_ENCRYPT"
|
||||
|
||||
# read info/exclude
|
||||
unmanaged=""
|
||||
|
@ -1486,13 +1484,13 @@ function exclude_encrypted() {
|
|||
else
|
||||
managed="${managed}${line}${newline}"
|
||||
fi
|
||||
done < "$exclude_path"
|
||||
done <"$exclude_path"
|
||||
fi
|
||||
|
||||
if [ "${exclude_header}${encrypt_data}" != "$managed" ]; then
|
||||
debug "Updating ${exclude_path}"
|
||||
assert_parent "$exclude_path"
|
||||
printf "%s" "${unmanaged}${exclude_header}${encrypt_data}" > "$exclude_path"
|
||||
printf "%s" "${unmanaged}${exclude_header}${encrypt_data}" >"$exclude_path"
|
||||
fi
|
||||
|
||||
return 0
|
||||
|
@ -1501,16 +1499,16 @@ function exclude_encrypted() {
|
|||
|
||||
function query_distro() {
|
||||
local distro=""
|
||||
if command -v "$LSB_RELEASE_PROGRAM" &> /dev/null; then
|
||||
if command -v "$LSB_RELEASE_PROGRAM" &>/dev/null; then
|
||||
distro=$($LSB_RELEASE_PROGRAM -si 2>/dev/null)
|
||||
elif [ -f "$OS_RELEASE" ]; then
|
||||
while IFS='' read -r line || [ -n "$line" ]; do
|
||||
if [[ "$line" = ID=* ]]; then
|
||||
distro="${line#ID=}"
|
||||
distro="${distro//\"}"
|
||||
distro="${distro//\"/}"
|
||||
break
|
||||
fi
|
||||
done < "$OS_RELEASE"
|
||||
done <"$OS_RELEASE"
|
||||
fi
|
||||
echo "$distro"
|
||||
}
|
||||
|
@ -1526,19 +1524,19 @@ function query_distro_family() {
|
|||
family="${line#ID=}"
|
||||
# No break, only used as fallback in case ID_LIKE isn't found
|
||||
fi
|
||||
done < "$OS_RELEASE"
|
||||
done <"$OS_RELEASE"
|
||||
fi
|
||||
echo "${family//\"}"
|
||||
echo "${family//\"/}"
|
||||
}
|
||||
|
||||
function process_global_args() {
|
||||
|
||||
# global arguments are removed before the main processing is done
|
||||
MAIN_ARGS=()
|
||||
while [[ $# -gt 0 ]] ; do
|
||||
while [[ $# -gt 0 ]]; do
|
||||
key="$1"
|
||||
case $key in
|
||||
-Y|--yadm-dir) # override the standard YADM_DIR
|
||||
-Y | --yadm-dir) # override the standard YADM_DIR
|
||||
YADM_DIR="$(qualify_path "$2" "yadm")"
|
||||
shift
|
||||
;;
|
||||
|
@ -1594,7 +1592,7 @@ function set_yadm_dirs() {
|
|||
# only resolve YADM_DATA if it hasn't been provided already
|
||||
if [ -z "$YADM_DATA" ]; then
|
||||
local base_yadm_data="$XDG_DATA_HOME"
|
||||
if [[ ! "$base_yadm_data" =~ ^/ ]] ; then
|
||||
if [[ ! "$base_yadm_data" =~ ^/ ]]; then
|
||||
base_yadm_data="${HOME}/.local/share"
|
||||
fi
|
||||
YADM_DATA="${base_yadm_data}/yadm"
|
||||
|
@ -1603,7 +1601,7 @@ function set_yadm_dirs() {
|
|||
# only resolve YADM_DIR if it hasn't been provided already
|
||||
if [ -z "$YADM_DIR" ]; then
|
||||
local base_yadm_dir="$XDG_CONFIG_HOME"
|
||||
if [[ ! "$base_yadm_dir" =~ ^/ ]] ; then
|
||||
if [[ ! "$base_yadm_dir" =~ ^/ ]]; then
|
||||
base_yadm_dir="${HOME}/.config"
|
||||
fi
|
||||
YADM_DIR="${base_yadm_dir}/yadm"
|
||||
|
@ -1635,9 +1633,7 @@ function issue_legacy_path_warning() {
|
|||
"$YADM_LEGACY_DIR/$YADM_CONFIG" \
|
||||
"$YADM_LEGACY_DIR/$YADM_ENCRYPT" \
|
||||
"$YADM_LEGACY_DIR/$YADM_HOOKS"/{pre,post}_* \
|
||||
"$YADM_LEGACY_DIR/$YADM_LEGACY_ARCHIVE" \
|
||||
;
|
||||
do
|
||||
"$YADM_LEGACY_DIR/$YADM_LEGACY_ARCHIVE"; do
|
||||
[ -e "$legacy_path" ] && legacy_found+=("$legacy_path")
|
||||
done
|
||||
|
||||
|
@ -1674,7 +1670,7 @@ ${path_list}
|
|||
***********
|
||||
EOF
|
||||
printf '%s\n' "$msg" >&2
|
||||
LEGACY_WARNING_ISSUED=1
|
||||
LEGACY_WARNING_ISSUED=1
|
||||
|
||||
}
|
||||
|
||||
|
@ -1756,15 +1752,14 @@ function set_operating_system() {
|
|||
fi 2>/dev/null
|
||||
|
||||
case "$OPERATING_SYSTEM" in
|
||||
CYGWIN*|MINGW*|MSYS*)
|
||||
CYGWIN* | MINGW* | MSYS*)
|
||||
git_version="$("$GIT_PROGRAM" --version 2>/dev/null)"
|
||||
if [[ "$git_version" =~ windows ]] ; then
|
||||
if [[ "$git_version" =~ windows ]]; then
|
||||
USE_CYGPATH=1
|
||||
fi
|
||||
OPERATING_SYSTEM=$(uname -o)
|
||||
;;
|
||||
*)
|
||||
;;
|
||||
*) ;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
@ -1772,7 +1767,7 @@ function set_operating_system() {
|
|||
function set_awk() {
|
||||
local pgm
|
||||
for pgm in "${AWK_PROGRAM[@]}"; do
|
||||
command -v "$pgm" &> /dev/null && AWK_PROGRAM=("$pgm") && return
|
||||
command -v "$pgm" &>/dev/null && AWK_PROGRAM=("$pgm") && return
|
||||
done
|
||||
}
|
||||
|
||||
|
@ -1802,8 +1797,8 @@ function invoke_hook() {
|
|||
exit_status="$2"
|
||||
hook_command="${YADM_HOOKS}/${mode}_$HOOK_COMMAND"
|
||||
|
||||
if [ -x "$hook_command" ] || \
|
||||
{ [[ $OPERATING_SYSTEM == MINGW* ]] && [ -f "$hook_command" ] ;} ; then
|
||||
if [ -x "$hook_command" ] ||
|
||||
{ [[ $OPERATING_SYSTEM == MINGW* ]] && [ -f "$hook_command" ]; }; then
|
||||
debug "Invoking hook: $hook_command"
|
||||
|
||||
# expose some internal data to all hooks
|
||||
|
@ -1868,7 +1863,7 @@ function assert_private_dirs() {
|
|||
if [ ! -d "$YADM_WORK/$private_dir" ]; then
|
||||
debug "Creating $YADM_WORK/$private_dir"
|
||||
#shellcheck disable=SC2174
|
||||
mkdir -m 0700 -p "$YADM_WORK/$private_dir" &> /dev/null
|
||||
mkdir -m 0700 -p "$YADM_WORK/$private_dir" &>/dev/null
|
||||
fi
|
||||
done
|
||||
}
|
||||
|
@ -1928,12 +1923,12 @@ function parse_encrypt() {
|
|||
fi
|
||||
;;
|
||||
esac
|
||||
done < "$YADM_ENCRYPT"
|
||||
done <"$YADM_ENCRYPT"
|
||||
|
||||
if [[ ${#include} -gt 0 ]]; then
|
||||
while IFS= read -r filename; do
|
||||
ENCRYPT_INCLUDE_FILES+=("${filename%/}")
|
||||
done <<< "$("$GIT_PROGRAM" ls-files --others "${exclude[@]}" -- "${include[@]}")"
|
||||
done <<<"$("$GIT_PROGRAM" ls-files --others "${exclude[@]}" -- "${include[@]}")"
|
||||
fi
|
||||
}
|
||||
|
||||
|
@ -2000,9 +1995,9 @@ function relative_path() {
|
|||
function auto_alt() {
|
||||
|
||||
# process alternates if there are possible changes
|
||||
if [ "$CHANGES_POSSIBLE" = "1" ] ; then
|
||||
if [ "$CHANGES_POSSIBLE" = "1" ]; then
|
||||
auto_alt=$(config --bool yadm.auto-alt)
|
||||
if [ "$auto_alt" != "false" ] ; then
|
||||
if [ "$auto_alt" != "false" ]; then
|
||||
[ -d "$YADM_REPO" ] && alt
|
||||
fi
|
||||
fi
|
||||
|
@ -2012,9 +2007,9 @@ function auto_alt() {
|
|||
function auto_perms() {
|
||||
|
||||
# process permissions if there are possible changes
|
||||
if [ "$CHANGES_POSSIBLE" = "1" ] ; then
|
||||
if [ "$CHANGES_POSSIBLE" = "1" ]; then
|
||||
auto_perms=$(config --bool yadm.auto-perms)
|
||||
if [ "$auto_perms" != "false" ] ; then
|
||||
if [ "$auto_perms" != "false" ]; then
|
||||
[ -d "$YADM_REPO" ] && perms
|
||||
fi
|
||||
fi
|
||||
|
@ -2028,12 +2023,12 @@ function auto_bootstrap() {
|
|||
[ "$DO_BOOTSTRAP" -eq 0 ] && return
|
||||
[ "$DO_BOOTSTRAP" -eq 3 ] && return
|
||||
[ "$DO_BOOTSTRAP" -eq 2 ] && bootstrap
|
||||
if [ "$DO_BOOTSTRAP" -eq 1 ] ; then
|
||||
if [ "$DO_BOOTSTRAP" -eq 1 ]; then
|
||||
echo "Found $YADM_BOOTSTRAP"
|
||||
echo "It appears that a bootstrap program exists."
|
||||
echo "Would you like to execute it now? (y/n)"
|
||||
read -r answer < /dev/tty
|
||||
if [[ $answer =~ ^[yY]$ ]] ; then
|
||||
read -r answer </dev/tty
|
||||
if [[ $answer =~ ^[yY]$ ]]; then
|
||||
bootstrap
|
||||
fi
|
||||
fi
|
||||
|
@ -2063,14 +2058,14 @@ function get_mode {
|
|||
|
||||
# most *nixes
|
||||
mode=$(stat -c '%a' "$filename" 2>/dev/null)
|
||||
if [ -z "$mode" ] ; then
|
||||
if [ -z "$mode" ]; then
|
||||
# BSD-style
|
||||
mode=$(stat -f '%p' "$filename" 2>/dev/null)
|
||||
mode=${mode: -4}
|
||||
fi
|
||||
|
||||
# only accept results if they are octal
|
||||
if [[ ! $mode =~ ^[0-7]+$ ]] ; then
|
||||
if [[ ! $mode =~ ^[0-7]+$ ]]; then
|
||||
mode=""
|
||||
fi
|
||||
|
||||
|
@ -2105,11 +2100,11 @@ function require_git() {
|
|||
|
||||
local more_info=""
|
||||
|
||||
if [ "$alt_git" != "" ] ; then
|
||||
if [ "$alt_git" != "" ]; then
|
||||
GIT_PROGRAM="$alt_git"
|
||||
more_info="\nThis command has been set via the yadm.git-program configuration."
|
||||
fi
|
||||
command -v "$GIT_PROGRAM" &> /dev/null ||
|
||||
command -v "$GIT_PROGRAM" &>/dev/null ||
|
||||
error_out "This functionality requires Git to be installed, but the command '$GIT_PROGRAM' cannot be located.$more_info"
|
||||
}
|
||||
function require_gpg() {
|
||||
|
@ -2118,11 +2113,11 @@ function require_gpg() {
|
|||
|
||||
local more_info=""
|
||||
|
||||
if [ "$alt_gpg" != "" ] ; then
|
||||
if [ "$alt_gpg" != "" ]; then
|
||||
GPG_PROGRAM="$alt_gpg"
|
||||
more_info="\nThis command has been set via the yadm.gpg-program configuration."
|
||||
fi
|
||||
command -v "$GPG_PROGRAM" &> /dev/null ||
|
||||
command -v "$GPG_PROGRAM" &>/dev/null ||
|
||||
error_out "This functionality requires GPG to be installed, but the command '$GPG_PROGRAM' cannot be located.$more_info"
|
||||
}
|
||||
function require_openssl() {
|
||||
|
@ -2131,11 +2126,11 @@ function require_openssl() {
|
|||
|
||||
local more_info=""
|
||||
|
||||
if [ "$alt_openssl" != "" ] ; then
|
||||
if [ "$alt_openssl" != "" ]; then
|
||||
OPENSSL_PROGRAM="$alt_openssl"
|
||||
more_info="\nThis command has been set via the yadm.openssl-program configuration."
|
||||
fi
|
||||
command -v "$OPENSSL_PROGRAM" &> /dev/null ||
|
||||
command -v "$OPENSSL_PROGRAM" &>/dev/null ||
|
||||
error_out "This functionality requires OpenSSL to be installed, but the command '$OPENSSL_PROGRAM' cannot be located.$more_info"
|
||||
}
|
||||
function require_repo() {
|
||||
|
@ -2145,11 +2140,11 @@ function require_shell() {
|
|||
[ -x "$SHELL" ] || error_out "\$SHELL does not refer to an executable."
|
||||
}
|
||||
function require_git_crypt() {
|
||||
command -v "$GIT_CRYPT_PROGRAM" &> /dev/null ||
|
||||
command -v "$GIT_CRYPT_PROGRAM" &>/dev/null ||
|
||||
error_out "This functionality requires git-crypt to be installed, but the command '$GIT_CRYPT_PROGRAM' cannot be located."
|
||||
}
|
||||
function require_transcrypt() {
|
||||
command -v "$TRANSCRYPT_PROGRAM" &> /dev/null ||
|
||||
command -v "$TRANSCRYPT_PROGRAM" &>/dev/null ||
|
||||
error_out "This functionality requires transcrypt to be installed, but the command '$TRANSCRYPT_PROGRAM' cannot be located."
|
||||
}
|
||||
function bootstrap_available() {
|
||||
|
@ -2157,23 +2152,23 @@ function bootstrap_available() {
|
|||
return 1
|
||||
}
|
||||
function awk_available() {
|
||||
command -v "${AWK_PROGRAM[0]}" &> /dev/null && return
|
||||
command -v "${AWK_PROGRAM[0]}" &>/dev/null && return
|
||||
return 1
|
||||
}
|
||||
function j2cli_available() {
|
||||
command -v "$J2CLI_PROGRAM" &> /dev/null && return
|
||||
command -v "$J2CLI_PROGRAM" &>/dev/null && return
|
||||
return 1
|
||||
}
|
||||
function envtpl_available() {
|
||||
command -v "$ENVTPL_PROGRAM" &> /dev/null && return
|
||||
command -v "$ENVTPL_PROGRAM" &>/dev/null && return
|
||||
return 1
|
||||
}
|
||||
function esh_available() {
|
||||
command -v "$ESH_PROGRAM" &> /dev/null && return
|
||||
command -v "$ESH_PROGRAM" &>/dev/null && return
|
||||
return 1
|
||||
}
|
||||
function readlink_available() {
|
||||
command -v "readlink" &> /dev/null && return
|
||||
command -v "readlink" &>/dev/null && return
|
||||
return 1
|
||||
}
|
||||
|
||||
|
@ -2181,7 +2176,7 @@ function readlink_available() {
|
|||
|
||||
function unix_path() {
|
||||
# for paths used by bash/yadm
|
||||
if [ "$USE_CYGPATH" = "1" ] ; then
|
||||
if [ "$USE_CYGPATH" = "1" ]; then
|
||||
cygpath -u "$1"
|
||||
else
|
||||
echo "$1"
|
||||
|
@ -2189,7 +2184,7 @@ function unix_path() {
|
|||
}
|
||||
function mixed_path() {
|
||||
# for paths used by Git
|
||||
if [ "$USE_CYGPATH" = "1" ] ; then
|
||||
if [ "$USE_CYGPATH" = "1" ]; then
|
||||
cygpath -m "$1"
|
||||
else
|
||||
echo "$1"
|
||||
|
@ -2213,7 +2208,7 @@ function echo_e() {
|
|||
|
||||
# ****** Main processing (when not unit testing) ******
|
||||
|
||||
if [ "$YADM_TEST" != 1 ] ; then
|
||||
if [ "$YADM_TEST" != 1 ]; then
|
||||
process_global_args "$@"
|
||||
set_operating_system
|
||||
set_awk
|
||||
|
|
Loading…
Reference in a new issue