1
0
Fork 0
mirror of synced 2024-12-22 06:31:07 -05:00

Format yadm and bootstrap with shfmt

Command: shfmt -w -ln bash -i 2 -ci <file>
This commit is contained in:
Erik Flodin 2024-12-11 20:05:16 +01:00
parent bb21c9a267
commit f5dfc7ab01
No known key found for this signature in database
GPG key ID: 420A7C865EE3F85F
2 changed files with 218 additions and 221 deletions

View file

@ -35,18 +35,20 @@ REPO_URL=""
function _private_yadm() { function _private_yadm() {
unset -f 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" echo "Found yadm installed locally, removing remote yadm() function"
unset -f _private_yadm unset -f _private_yadm
command yadm "$@" command yadm "$@"
else 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. echo WARNING: Using yadm remotely. You should install yadm locally.
curl -fsSL "$YADM_REPO/raw/$YADM_RELEASE/yadm" | bash -s -- "$@" curl -fsSL "$YADM_REPO/raw/$YADM_RELEASE/yadm" | bash -s -- "$@"
fi fi
} }
export -f _private_yadm 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 # if being sourced, return here, otherwise continue processing
return 2>/dev/null return 2>/dev/null
@ -57,7 +59,7 @@ function remote_yadm() {
} }
function ask_about_source() { function ask_about_source() {
if ! command -v yadm &> /dev/null; then if ! command -v yadm &>/dev/null; then
echo echo
echo "***************************************************" echo "***************************************************"
echo "yadm is NOT currently installed." echo "yadm is NOT currently installed."
@ -83,7 +85,7 @@ function build_url() {
echo " 3. GitLab" echo " 3. GitLab"
echo " 4. Other" echo " 4. Other"
echo 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 case $choice in
1) 1)
REPO_URL="https://github.com/" REPO_URL="https://github.com/"
@ -97,7 +99,7 @@ function build_url() {
*) *)
echo echo
echo Please specify the full URL of your dotfiles repo 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" REPO_URL="$choice"
return return
;; ;;
@ -107,7 +109,7 @@ function build_url() {
echo "Provide your user and repo separated by '/'" echo "Provide your user and repo separated by '/'"
echo "For example: UserName/dotfiles" echo "For example: UserName/dotfiles"
echo echo
read -r -p "User/Repo ->" choice < /dev/tty read -r -p "User/Repo ->" choice </dev/tty
[[ "$choice" =~ ^[^[:space:]]+/[^[:space:]]+$ ]] || { [[ "$choice" =~ ^[^[:space:]]+/[^[:space:]]+$ ]] || {
echo "Not formatted as USER/REPO" echo "Not formatted as USER/REPO"
REPO_URL= REPO_URL=

423
yadm
View file

@ -89,21 +89,21 @@ function main() {
param="${param//\\/\\\\}" param="${param//\\/\\\\}"
param="${param//$_tab/\\$_tab}" param="${param//$_tab/\\$_tab}"
param="${param// /\\ }" param="${param// /\\ }"
_fc+=( "$param" ) _fc+=("$param")
done done
FULL_COMMAND="${_fc[*]}" FULL_COMMAND="${_fc[*]}"
# create the YADM_DIR & YADM_DATA if they doesn't exist yet # create the YADM_DIR & YADM_DATA if they doesn't exist yet
[ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR" [ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR"
[ -d "$YADM_DATA" ] || mkdir -p "$YADM_DATA" [ -d "$YADM_DATA" ] || mkdir -p "$YADM_DATA"
# parse command line arguments # parse command line arguments
local retval=0 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)$" 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() # no argumnts will result in help()
help help
elif [[ "$1" =~ $internal_commands ]] ; then elif [[ "$1" =~ $internal_commands ]]; then
# for internal commands, process all of the arguments # for internal commands, process all of the arguments
YADM_COMMAND="${1//-/_}" YADM_COMMAND="${1//-/_}"
YADM_COMMAND="${YADM_COMMAND/__/}" YADM_COMMAND="${YADM_COMMAND/__/}"
@ -111,32 +111,32 @@ function main() {
shift shift
# commands listed below do not process any of the parameters # 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=("$@") YADM_ARGS=("$@")
else else
while [[ $# -gt 0 ]] ; do while [[ $# -gt 0 ]]; do
key="$1" key="$1"
case $key in case $key in
-a) # used by list() -a) # used by list()
LIST_ALL="YES" LIST_ALL="YES"
;; ;;
-d) # used by all commands -d) # used by all commands
DEBUG="YES" DEBUG="YES"
;; ;;
-f) # used by init(), clone() and upgrade() -f) # used by init(), clone() and upgrade()
FORCE="YES" FORCE="YES"
;; ;;
-l) # used by decrypt() -l) # used by decrypt()
DO_LIST="YES" DO_LIST="YES"
[[ "$YADM_COMMAND" =~ ^(clone|config)$ ]] && YADM_ARGS+=("$1") [[ "$YADM_COMMAND" =~ ^(clone|config)$ ]] && YADM_ARGS+=("$1")
;; ;;
-w) # used by init() and clone() -w) # used by init() and clone()
YADM_WORK="$(qualify_path "$2" "work tree")" YADM_WORK="$(qualify_path "$2" "work tree")"
shift shift
;; ;;
*) # any unhandled arguments *) # any unhandled arguments
YADM_ARGS+=("$1") YADM_ARGS+=("$1")
;; ;;
esac esac
shift shift
done done
@ -162,7 +162,6 @@ function main() {
} }
# ****** Alternate Processing ****** # ****** Alternate Processing ******
function score_file() { function score_file() {
@ -173,7 +172,7 @@ function score_file() {
score=0 score=0
local template_cmd="" local template_cmd=""
IFS=',' read -ra fields <<< "$conditions" IFS=',' read -ra fields <<<"$conditions"
for field in "${fields[@]}"; do for field in "${fields[@]}"; do
local label=${field%%.*} local label=${field%%.*}
local value=${field#*.} local value=${field#*.}
@ -185,32 +184,32 @@ function score_file() {
default) default)
delta=0 delta=0
;; ;;
a|arch) a | arch)
[[ "$value" = "$local_arch" ]] && delta=1 [[ "$value" = "$local_arch" ]] && delta=1
;; ;;
o|os) o | os)
[[ "$value" = "$local_system" ]] && delta=2 [[ "$value" = "$local_system" ]] && delta=2
;; ;;
d|distro) d | distro)
[[ "${value// /_}" = "${local_distro// /_}" ]] && delta=4 [[ "${value// /_}" = "${local_distro// /_}" ]] && delta=4
;; ;;
f|distro_family) f | distro_family)
[[ "${value// /_}" = "${local_distro_family// /_}" ]] && delta=8 [[ "${value// /_}" = "${local_distro_family// /_}" ]] && delta=8
;; ;;
c|class) c | class)
in_list "$value" "${local_classes[@]}" && delta=16 in_list "$value" "${local_classes[@]}" && delta=16
;; ;;
h|hostname) h | hostname)
[[ "$value" = "$local_host" ]] && delta=32 [[ "$value" = "$local_host" ]] && delta=32
;; ;;
u|user) u | user)
[[ "$value" = "$local_user" ]] && delta=64 [[ "$value" = "$local_user" ]] && delta=64
;; ;;
e|extension) e | extension)
# extension isn't a condition and doesn't affect the score # extension isn't a condition and doesn't affect the score
continue continue
;; ;;
t|template|yadm) t | template | yadm)
if [ -d "$source" ]; then if [ -d "$source" ]; then
INVALID_ALT+=("$source") INVALID_ALT+=("$source")
else else
@ -229,11 +228,11 @@ function score_file() {
esac esac
shopt -u nocasematch shopt -u nocasematch
if (( delta < 0 )); then if ((delta < 0)); then
score=0 score=0
return return
fi fi
score=$(( score + 1000 + delta )) score=$((score + 1000 + delta))
done done
record_score "$score" "$target" "$source" "$template_cmd" 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 # search for the index of this target, to see if we already are tracking it
local -i index=$((${#alt_targets[@]} - 1)) local -i index=$((${#alt_targets[@]} - 1))
for (( ; index >= 0; --index )); do for (( ; index >= 0; --index)); do
if [ "${alt_targets[$index]}" = "$target" ]; then if [ "${alt_targets[$index]}" = "$target" ]; then
break break
fi fi
@ -259,11 +258,11 @@ function record_score() {
if [ $index -lt 0 ]; then if [ $index -lt 0 ]; then
# $YADM_CONFIG must be processed first, in case other templates lookup yadm configurations # $YADM_CONFIG must be processed first, in case other templates lookup yadm configurations
if [ "$target" = "$YADM_CONFIG" ]; then if [ "$target" = "$YADM_CONFIG" ]; then
alt_targets=("$target" "${alt_targets[@]}") alt_targets=("$target" "${alt_targets[@]}")
alt_sources=("$source" "${alt_sources[@]}") alt_sources=("$source" "${alt_sources[@]}")
alt_scores=("$score" "${alt_scores[@]}") alt_scores=("$score" "${alt_scores[@]}")
alt_template_cmds=("$template_cmd" "${alt_template_cmds[@]}") alt_template_cmds=("$template_cmd" "${alt_template_cmds[@]}")
else else
alt_targets+=("$target") alt_targets+=("$target")
@ -314,7 +313,7 @@ function template_default() {
# the explicit "space + tab" character class used below is used because not # the explicit "space + tab" character class used below is used because not
# all versions of awk seem to support the POSIX character classes [[:blank:]] # 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 { BEGIN {
classes = ARGV[2] classes = ARGV[2]
for (i = 3; i < ARGC; ++i) { for (i = 3; i < ARGC; ++i) {
@ -437,7 +436,7 @@ EOF
-v source="$input" \ -v source="$input" \
-v source_dir="$(builtin_dirname "$input")" \ -v source_dir="$(builtin_dirname "$input")" \
"$awk_pgm" \ "$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" move_file "$input" "$output" "$temp_file"
} }
@ -447,16 +446,16 @@ function template_j2cli() {
output="$2" output="$2"
temp_file="${output}.$$.$RANDOM" temp_file="${output}.$$.$RANDOM"
YADM_CLASS="$local_class" \ YADM_CLASS="$local_class" \
YADM_ARCH="$local_arch" \ YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \ YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \ YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \ YADM_USER="$local_user" \
YADM_DISTRO="$local_distro" \ YADM_DISTRO="$local_distro" \
YADM_DISTRO_FAMILY="$local_distro_family" \ YADM_DISTRO_FAMILY="$local_distro_family" \
YADM_SOURCE="$input" \ YADM_SOURCE="$input" \
YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \ YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \
"$J2CLI_PROGRAM" "$input" -o "$temp_file" "$J2CLI_PROGRAM" "$input" -o "$temp_file"
move_file "$input" "$output" "$temp_file" move_file "$input" "$output" "$temp_file"
} }
@ -466,16 +465,16 @@ function template_envtpl() {
output="$2" output="$2"
temp_file="${output}.$$.$RANDOM" temp_file="${output}.$$.$RANDOM"
YADM_CLASS="$local_class" \ YADM_CLASS="$local_class" \
YADM_ARCH="$local_arch" \ YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \ YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \ YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \ YADM_USER="$local_user" \
YADM_DISTRO="$local_distro" \ YADM_DISTRO="$local_distro" \
YADM_DISTRO_FAMILY="$local_distro_family" \ YADM_DISTRO_FAMILY="$local_distro_family" \
YADM_SOURCE="$input" \ YADM_SOURCE="$input" \
YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \ YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \
"$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file" "$ENVTPL_PROGRAM" --keep-template "$input" -o "$temp_file"
move_file "$input" "$output" "$temp_file" move_file "$input" "$output" "$temp_file"
} }
@ -486,15 +485,15 @@ function template_esh() {
temp_file="${output}.$$.$RANDOM" temp_file="${output}.$$.$RANDOM"
YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \ YADM_CLASSES="$(join_string $'\n' "${local_classes[@]}")" \
"$ESH_PROGRAM" -o "$temp_file" "$input" \ "$ESH_PROGRAM" -o "$temp_file" "$input" \
YADM_CLASS="$local_class" \ YADM_CLASS="$local_class" \
YADM_ARCH="$local_arch" \ YADM_ARCH="$local_arch" \
YADM_OS="$local_system" \ YADM_OS="$local_system" \
YADM_HOSTNAME="$local_host" \ YADM_HOSTNAME="$local_host" \
YADM_USER="$local_user" \ YADM_USER="$local_user" \
YADM_DISTRO="$local_distro" \ YADM_DISTRO="$local_distro" \
YADM_DISTRO_FAMILY="$local_distro_family" \ YADM_DISTRO_FAMILY="$local_distro_family" \
YADM_SOURCE="$input" YADM_SOURCE="$input"
move_file "$input" "$output" "$temp_file" move_file "$input" "$output" "$temp_file"
} }
@ -617,7 +616,7 @@ function report_invalid_alts() {
${path_list} ${path_list}
*********** ***********
EOF EOF
printf '%s\n' "$msg" >&2 printf '%s\n' "$msg" >&2
} }
function remove_stale_links() { function remove_stale_links() {
@ -646,7 +645,7 @@ function set_local_alt_values() {
while IFS='' read -r class; do while IFS='' read -r class; do
local_classes+=("$class") local_classes+=("$class")
local_class="$class" local_class="$class"
done <<< "$all_classes" done <<<"$all_classes"
local_arch="$(config local.arch)" local_arch="$(config local.arch)"
if [[ -z "$local_arch" ]]; then if [[ -z "$local_arch" ]]; then
@ -683,7 +682,7 @@ function set_local_alt_values() {
function alt_linking() { function alt_linking() {
local -i index 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 target="${alt_targets[$index]}"
local source="${alt_sources[$index]}" local source="${alt_sources[$index]}"
local template_cmd="${alt_template_cmds[$index]}" local template_cmd="${alt_template_cmds[$index]}"
@ -750,30 +749,30 @@ function clone() {
DO_BOOTSTRAP=1 DO_BOOTSTRAP=1
local -a args local -a args
local -i do_checkout=1 local -i do_checkout=1
while [[ $# -gt 0 ]] ; do while [[ $# -gt 0 ]]; do
case "$1" in case "$1" in
--bootstrap) # force bootstrap, without prompt --bootstrap) # force bootstrap, without prompt
DO_BOOTSTRAP=2 DO_BOOTSTRAP=2
;; ;;
--no-bootstrap) # prevent bootstrap, without prompt --no-bootstrap) # prevent bootstrap, without prompt
DO_BOOTSTRAP=3 DO_BOOTSTRAP=3
;; ;;
--checkout) --checkout)
do_checkout=1 do_checkout=1
;; ;;
-n|--no-checkout) -n | --no-checkout)
do_checkout=0 do_checkout=0
;; ;;
--bare|--mirror|--recurse-submodules*|--recursive|--separate-git-dir=*) --bare | --mirror | --recurse-submodules* | --recursive | --separate-git-dir=*)
# ignore arguments without separate parameter # ignore arguments without separate parameter
;; ;;
--separate-git-dir) --separate-git-dir)
# ignore arguments with separate parameter # ignore arguments with separate parameter
shift shift
;; ;;
*) *)
args+=("$1") args+=("$1")
;; ;;
esac esac
shift shift
done done
@ -798,11 +797,11 @@ function clone() {
# first clone without checkout # first clone without checkout
debug "Doing an initial clone of the repository" debug "Doing an initial clone of the repository"
(cd "$wc" && (cd "$wc" &&
"$GIT_PROGRAM" -c core.sharedrepository=0600 clone --no-checkout \ "$GIT_PROGRAM" -c core.sharedrepository=0600 clone --no-checkout \
--separate-git-dir="$YADM_REPO" "${args[@]}" repo.git) || { --separate-git-dir="$YADM_REPO" "${args[@]}" repo.git) || {
debug "Removing repo after failed clone" debug "Removing repo after failed clone"
rm -rf "$YADM_REPO" "$wc" rm -rf "$YADM_REPO" "$wc"
error_out "Unable to clone the repository" error_out "Unable to clone the repository"
} }
configure_repo configure_repo
rm -rf "$wc" rm -rf "$wc"
@ -823,17 +822,17 @@ function clone() {
# finally check out (unless instructed not to) all files that don't exist in $YADM_WORK # finally check out (unless instructed not to) all files that don't exist in $YADM_WORK
if [[ $do_checkout -ne 0 ]]; then if [[ $do_checkout -ne 0 ]]; then
[ -n "$DEBUG" ] && display_private_perms "pre-checkout" [ -n "$DEBUG" ] && display_private_perms "pre-checkout"
cd_work "Clone" || return cd_work "Clone" || return
"$GIT_PROGRAM" ls-files --deleted | while IFS= read -r file; do "$GIT_PROGRAM" ls-files --deleted | while IFS= read -r file; do
"$GIT_PROGRAM" checkout -- ":/$file" "$GIT_PROGRAM" checkout -- ":/$file"
done done
if [ -n "$("$GIT_PROGRAM" ls-files --modified)" ]; then if [ -n "$("$GIT_PROGRAM" ls-files --modified)" ]; then
local msg local msg
IFS='' read -r -d '' msg <<EOF IFS='' read -r -d '' msg <<EOF
**NOTE** **NOTE**
Local files with content that differs from the ones just Local files with content that differs from the ones just
cloned were found in $YADM_WORK. They have been left cloned were found in $YADM_WORK. They have been left
@ -843,12 +842,12 @@ function clone() {
If you know what you're doing, and want to overwrite the If you know what you're doing, and want to overwrite the
tracked files, consider 'yadm checkout "$YADM_WORK"'. tracked files, consider 'yadm checkout "$YADM_WORK"'.
EOF EOF
printf '%s\n' "$msg" printf '%s\n' "$msg"
fi fi
[ -n "$DEBUG" ] && display_private_perms "post-checkout" [ -n "$DEBUG" ] && display_private_perms "post-checkout"
CHANGES_POSSIBLE=1 CHANGES_POSSIBLE=1
fi fi
} }
@ -861,7 +860,7 @@ function config() {
[[ "$option" =~ $local_options ]] && use_repo_config=1 [[ "$option" =~ $local_options ]] && use_repo_config=1
done done
if [ -z "$*" ] ; then if [ -z "$*" ]; then
# with no parameters, provide some helpful documentation # with no parameters, provide some helpful documentation
echo "yadm supports the following configurations:" echo "yadm supports the following configurations:"
echo echo
@ -871,7 +870,7 @@ function config() {
done done
echo echo
local msg local msg
read -r -d '' msg << EOF read -r -d '' msg <<EOF
Please read the CONFIGURATION section in the man Please read the CONFIGURATION section in the man
page for more details about configurations, and page for more details about configurations, and
how to adjust them. how to adjust them.
@ -933,7 +932,7 @@ function _get_cipher() {
output_archive="$1" output_archive="$1"
yadm_cipher="$(config yadm.cipher)" yadm_cipher="$(config yadm.cipher)"
if [ -z "$yadm_cipher" ]; then if [ -z "$yadm_cipher" ]; then
yadm_cipher="gpg" yadm_cipher="gpg"
fi fi
} }
@ -996,7 +995,7 @@ function decrypt() {
[ -f "$YADM_ENCRYPT" ] && exclude_encrypted [ -f "$YADM_ENCRYPT" ] && exclude_encrypted
if [ "$DO_LIST" = "YES" ] ; then if [ "$DO_LIST" = "YES" ]; then
tar_option="t" tar_option="t"
else else
tar_option="x" tar_option="x"
@ -1036,11 +1035,11 @@ function encrypt() {
# offer to add YADM_ARCHIVE if untracked # offer to add YADM_ARCHIVE if untracked
archive_status=$("$GIT_PROGRAM" status --porcelain -uall "$(mixed_path "$YADM_ARCHIVE")" 2>/dev/null) archive_status=$("$GIT_PROGRAM" status --porcelain -uall "$(mixed_path "$YADM_ARCHIVE")" 2>/dev/null)
archive_regex="^\?\?" 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 "It appears that $YADM_ARCHIVE is not tracked by yadm's repository."
echo "Would you like to add it now? (y/n)" echo "Would you like to add it now? (y/n)"
read -r answer < /dev/tty read -r answer </dev/tty
if [[ $answer =~ ^[yY]$ ]] ; then if [[ $answer =~ ^[yY]$ ]]; then
"$GIT_PROGRAM" add "$(mixed_path "$YADM_ARCHIVE")" "$GIT_PROGRAM" add "$(mixed_path "$YADM_ARCHIVE")"
fi fi
fi fi
@ -1104,7 +1103,7 @@ function git_command() {
require_repo require_repo
# translate 'gitconfig' to 'config' -- 'config' is reserved for yadm # translate 'gitconfig' to 'config' -- 'config' is reserved for yadm
if [ "$1" = "gitconfig" ] ; then if [ "$1" = "gitconfig" ]; then
set -- "config" "${@:2}" set -- "config" "${@:2}"
fi fi
@ -1113,7 +1112,7 @@ function git_command() {
if [ "$YADM_WORK" = "$HOME" ]; then if [ "$YADM_WORK" = "$HOME" ]; then
auto_private_dirs=$(config --bool yadm.auto-private-dirs) 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 for pdir in $(private_dirs all); do
assert_private_dirs "$pdir" assert_private_dirs "$pdir"
done done
@ -1138,7 +1137,7 @@ function help() {
readonly padding=" " readonly padding=" "
local msg local msg
IFS='' read -r -d '' msg << EOF IFS='' read -r -d '' msg <<EOF
Usage: yadm <command> [options...] Usage: yadm <command> [options...]
Manage dotfiles maintained in a Git repository. Manage alternate files Manage dotfiles maintained in a Git repository. Manage alternate files
@ -1201,9 +1200,9 @@ function init() {
function introspect() { function introspect() {
case "$1" in case "$1" in
commands|configs|repo|switches) commands | configs | repo | switches)
"introspect_$1" "introspect_$1"
;; ;;
esac esac
} }
@ -1284,7 +1283,7 @@ function list() {
require_repo require_repo
# process relative to YADM_WORK when --all is specified # process relative to YADM_WORK when --all is specified
if [ -n "$LIST_ALL" ] ; then if [ -n "$LIST_ALL" ]; then
cd_work "List" || return cd_work "List" || return
fi fi
@ -1309,13 +1308,13 @@ function perms() {
# only include private globs if using HOME as worktree # only include private globs if using HOME as worktree
if [ "$YADM_WORK" = "$HOME" ]; then if [ "$YADM_WORK" = "$HOME" ]; then
# include all .ssh files (unless disabled) # 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/.[!.]*") GLOBS+=(".ssh" ".ssh/*" ".ssh/.[!.]*")
fi fi
# include all gpg files (unless disabled) # include all gpg files (unless disabled)
gnupghome="$(private_dirs gnupg)" gnupghome="$(private_dirs gnupg)"
if [[ $(config --bool yadm.gpg-perms) != "false" ]] ; then if [[ $(config --bool yadm.gpg-perms) != "false" ]]; then
GLOBS+=("${gnupghome}" "${gnupghome}/*" "${gnupghome}/.[!.]*") GLOBS+=("${gnupghome}" "${gnupghome}/*" "${gnupghome}/.[!.]*")
fi fi
fi fi
@ -1326,7 +1325,7 @@ function perms() {
# remove group/other permissions from collected globs # remove group/other permissions from collected globs
#shellcheck disable=SC2068 #shellcheck disable=SC2068
#(SC2068 is disabled because in this case, we desire globbing) #(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 # TODO: detect and report changing permissions in a portable way
} }
@ -1337,7 +1336,7 @@ function upgrade() {
local -a submodules local -a submodules
local repo_updates=0 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" error_out "Unable to upgrade. Paths have been overridden with command line options"
# choose a legacy repo, the version 2 location will be favored # choose a legacy repo, the version 2 location will be favored
@ -1364,18 +1363,18 @@ function upgrade() {
local submodule_status local submodule_status
submodule_status=$("$GIT_PROGRAM" -C "$YADM_WORK" submodule status) submodule_status=$("$GIT_PROGRAM" -C "$YADM_WORK" submodule status)
while read -r sha submodule rest; do while read -r sha submodule rest; do
[ "$submodule" == "" ] && continue [ "$submodule" == "" ] && continue
if [[ "$sha" = -* ]]; then if [[ "$sha" = -* ]]; then
continue continue
fi fi
"$GIT_PROGRAM" -C "$YADM_WORK" submodule deinit ${FORCE:+-f} -- "$submodule" || { "$GIT_PROGRAM" -C "$YADM_WORK" submodule deinit ${FORCE:+-f} -- "$submodule" || {
for other in "${submodules[@]}"; do for other in "${submodules[@]}"; do
"$GIT_PROGRAM" -C "$YADM_WORK" submodule update --init --recursive -- "$other" "$GIT_PROGRAM" -C "$YADM_WORK" submodule update --init --recursive -- "$other"
done done
error_out "Unable to upgrade. Could not deinit submodule $submodule" error_out "Unable to upgrade. Could not deinit submodule $submodule"
} }
submodules+=("$submodule") submodules+=("$submodule")
done <<< "$submodule_status" done <<<"$submodule_status"
assert_parent "$YADM_REPO" assert_parent "$YADM_REPO"
mv "$LEGACY_REPO" "$YADM_REPO" mv "$LEGACY_REPO" "$YADM_REPO"
@ -1395,7 +1394,7 @@ function upgrade() {
echo "Moving $LEGACY_ARCHIVE to $YADM_ARCHIVE" echo "Moving $LEGACY_ARCHIVE to $YADM_ARCHIVE"
assert_parent "$YADM_ARCHIVE" assert_parent "$YADM_ARCHIVE"
# test to see if path is "tracked" in repo, if so 'git mv' must be used # 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 "$GIT_PROGRAM" mv "$LEGACY_ARCHIVE" "$YADM_ARCHIVE" && repo_updates=1
else else
mv -i "$LEGACY_ARCHIVE" "$YADM_ARCHIVE" mv -i "$LEGACY_ARCHIVE" "$YADM_ARCHIVE"
@ -1403,13 +1402,11 @@ function upgrade() {
fi fi
# handle any remaining version 1 paths # handle any remaining version 1 paths
for legacy_path in \ for legacy_path in \
"$YADM_LEGACY_DIR/config" \ "$YADM_LEGACY_DIR/config" \
"$YADM_LEGACY_DIR/encrypt" \ "$YADM_LEGACY_DIR/encrypt" \
"$YADM_LEGACY_DIR/bootstrap" \ "$YADM_LEGACY_DIR/bootstrap" \
"$YADM_LEGACY_DIR"/hooks/{pre,post}_* \ "$YADM_LEGACY_DIR"/hooks/{pre,post}_*; do
;
do
if [ -e "$legacy_path" ]; then if [ -e "$legacy_path" ]; then
new_filename="${legacy_path#"$YADM_LEGACY_DIR/"}" new_filename="${legacy_path#"$YADM_LEGACY_DIR/"}"
new_filename="$YADM_DIR/$new_filename" new_filename="$YADM_DIR/$new_filename"
@ -1417,7 +1414,7 @@ function upgrade() {
echo "Moving $legacy_path to $new_filename" echo "Moving $legacy_path to $new_filename"
assert_parent "$new_filename" assert_parent "$new_filename"
# test to see if path is "tracked" in repo, if so 'git mv' must be used # 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 "$GIT_PROGRAM" mv "$legacy_path" "$new_filename" && repo_updates=1
else else
mv -i "$legacy_path" "$new_filename" mv -i "$legacy_path" "$new_filename"
@ -1427,13 +1424,13 @@ function upgrade() {
# handle submodules, which need to be reinitialized # handle submodules, which need to be reinitialized
for submodule in "${submodules[@]}"; do for submodule in "${submodules[@]}"; do
"$GIT_PROGRAM" -C "$YADM_WORK" submodule update --init --recursive -- "$submodule" "$GIT_PROGRAM" -C "$YADM_WORK" submodule update --init --recursive -- "$submodule"
done done
[ "$actions_performed" -eq 0 ] && \ [ "$actions_performed" -eq 0 ] &&
echo "No legacy paths found. Upgrade is not necessary" 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." echo "Some files tracked by yadm have been renamed. These changes should probably be commited now."
exit 0 exit 0
@ -1443,7 +1440,8 @@ function upgrade() {
function version() { function version() {
echo "bash version $BASH_VERSION" echo "bash version $BASH_VERSION"
printf " "; "$GIT_PROGRAM" --version printf " "
"$GIT_PROGRAM" --version
echo "yadm version $VERSION" echo "yadm version $VERSION"
exit_with_hook 0 exit_with_hook 0
@ -1472,7 +1470,7 @@ function exclude_encrypted() {
encrypt_data="" encrypt_data=""
while IFS='' read -r line || [ -n "$line" ]; do while IFS='' read -r line || [ -n "$line" ]; do
encrypt_data="${encrypt_data}${line}${newline}" encrypt_data="${encrypt_data}${line}${newline}"
done < "$YADM_ENCRYPT" done <"$YADM_ENCRYPT"
# read info/exclude # read info/exclude
unmanaged="" unmanaged=""
@ -1486,13 +1484,13 @@ function exclude_encrypted() {
else else
managed="${managed}${line}${newline}" managed="${managed}${line}${newline}"
fi fi
done < "$exclude_path" done <"$exclude_path"
fi fi
if [ "${exclude_header}${encrypt_data}" != "$managed" ]; then if [ "${exclude_header}${encrypt_data}" != "$managed" ]; then
debug "Updating ${exclude_path}" debug "Updating ${exclude_path}"
assert_parent "$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 fi
return 0 return 0
@ -1501,16 +1499,16 @@ function exclude_encrypted() {
function query_distro() { function query_distro() {
local 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) distro=$($LSB_RELEASE_PROGRAM -si 2>/dev/null)
elif [ -f "$OS_RELEASE" ]; then elif [ -f "$OS_RELEASE" ]; then
while IFS='' read -r line || [ -n "$line" ]; do while IFS='' read -r line || [ -n "$line" ]; do
if [[ "$line" = ID=* ]]; then if [[ "$line" = ID=* ]]; then
distro="${line#ID=}" distro="${line#ID=}"
distro="${distro//\"}" distro="${distro//\"/}"
break break
fi fi
done < "$OS_RELEASE" done <"$OS_RELEASE"
fi fi
echo "$distro" echo "$distro"
} }
@ -1526,49 +1524,49 @@ function query_distro_family() {
family="${line#ID=}" family="${line#ID=}"
# No break, only used as fallback in case ID_LIKE isn't found # No break, only used as fallback in case ID_LIKE isn't found
fi fi
done < "$OS_RELEASE" done <"$OS_RELEASE"
fi fi
echo "${family//\"}" echo "${family//\"/}"
} }
function process_global_args() { function process_global_args() {
# global arguments are removed before the main processing is done # global arguments are removed before the main processing is done
MAIN_ARGS=() MAIN_ARGS=()
while [[ $# -gt 0 ]] ; do while [[ $# -gt 0 ]]; do
key="$1" key="$1"
case $key in 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")" YADM_DIR="$(qualify_path "$2" "yadm")"
shift shift
;; ;;
--yadm-data) # override the standard YADM_DATA --yadm-data) # override the standard YADM_DATA
YADM_DATA="$(qualify_path "$2" "data")" YADM_DATA="$(qualify_path "$2" "data")"
shift shift
;; ;;
--yadm-repo) # override the standard YADM_REPO --yadm-repo) # override the standard YADM_REPO
YADM_OVERRIDE_REPO="$(qualify_path "$2" "repo")" YADM_OVERRIDE_REPO="$(qualify_path "$2" "repo")"
shift shift
;; ;;
--yadm-config) # override the standard YADM_CONFIG --yadm-config) # override the standard YADM_CONFIG
YADM_OVERRIDE_CONFIG="$(qualify_path "$2" "config")" YADM_OVERRIDE_CONFIG="$(qualify_path "$2" "config")"
shift shift
;; ;;
--yadm-encrypt) # override the standard YADM_ENCRYPT --yadm-encrypt) # override the standard YADM_ENCRYPT
YADM_OVERRIDE_ENCRYPT="$(qualify_path "$2" "encrypt")" YADM_OVERRIDE_ENCRYPT="$(qualify_path "$2" "encrypt")"
shift shift
;; ;;
--yadm-archive) # override the standard YADM_ARCHIVE --yadm-archive) # override the standard YADM_ARCHIVE
YADM_OVERRIDE_ARCHIVE="$(qualify_path "$2" "archive")" YADM_OVERRIDE_ARCHIVE="$(qualify_path "$2" "archive")"
shift shift
;; ;;
--yadm-bootstrap) # override the standard YADM_BOOTSTRAP --yadm-bootstrap) # override the standard YADM_BOOTSTRAP
YADM_OVERRIDE_BOOTSTRAP="$(qualify_path "$2" "bootstrap")" YADM_OVERRIDE_BOOTSTRAP="$(qualify_path "$2" "bootstrap")"
shift shift
;; ;;
*) # main arguments are kept intact *) # main arguments are kept intact
MAIN_ARGS+=("$1") MAIN_ARGS+=("$1")
;; ;;
esac esac
shift shift
done done
@ -1576,17 +1574,17 @@ function process_global_args() {
} }
function qualify_path() { function qualify_path() {
local path="$1" local path="$1"
if [ -z "$path" ]; then if [ -z "$path" ]; then
error_out "You can't specify an empty $2 path" error_out "You can't specify an empty $2 path"
fi fi
if [ "$path" = "." ]; then if [ "$path" = "." ]; then
path="$PWD" path="$PWD"
elif [[ "$path" != /* ]]; then elif [[ "$path" != /* ]]; then
path="$PWD/${path#./}" path="$PWD/${path#./}"
fi fi
echo "$path" echo "$path"
} }
function set_yadm_dirs() { function set_yadm_dirs() {
@ -1594,7 +1592,7 @@ function set_yadm_dirs() {
# only resolve YADM_DATA if it hasn't been provided already # only resolve YADM_DATA if it hasn't been provided already
if [ -z "$YADM_DATA" ]; then if [ -z "$YADM_DATA" ]; then
local base_yadm_data="$XDG_DATA_HOME" local base_yadm_data="$XDG_DATA_HOME"
if [[ ! "$base_yadm_data" =~ ^/ ]] ; then if [[ ! "$base_yadm_data" =~ ^/ ]]; then
base_yadm_data="${HOME}/.local/share" base_yadm_data="${HOME}/.local/share"
fi fi
YADM_DATA="${base_yadm_data}/yadm" 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 # only resolve YADM_DIR if it hasn't been provided already
if [ -z "$YADM_DIR" ]; then if [ -z "$YADM_DIR" ]; then
local base_yadm_dir="$XDG_CONFIG_HOME" local base_yadm_dir="$XDG_CONFIG_HOME"
if [[ ! "$base_yadm_dir" =~ ^/ ]] ; then if [[ ! "$base_yadm_dir" =~ ^/ ]]; then
base_yadm_dir="${HOME}/.config" base_yadm_dir="${HOME}/.config"
fi fi
YADM_DIR="${base_yadm_dir}/yadm" YADM_DIR="${base_yadm_dir}/yadm"
@ -1627,17 +1625,15 @@ function issue_legacy_path_warning() {
# test for legacy paths # test for legacy paths
local legacy_found=() local legacy_found=()
# this is ordered by importance # this is ordered by importance
for legacy_path in \ for legacy_path in \
"$YADM_DIR/$YADM_REPO" \ "$YADM_DIR/$YADM_REPO" \
"$YADM_DIR/$YADM_LEGACY_ARCHIVE" \ "$YADM_DIR/$YADM_LEGACY_ARCHIVE" \
"$YADM_LEGACY_DIR/$YADM_REPO" \ "$YADM_LEGACY_DIR/$YADM_REPO" \
"$YADM_LEGACY_DIR/$YADM_BOOTSTRAP" \ "$YADM_LEGACY_DIR/$YADM_BOOTSTRAP" \
"$YADM_LEGACY_DIR/$YADM_CONFIG" \ "$YADM_LEGACY_DIR/$YADM_CONFIG" \
"$YADM_LEGACY_DIR/$YADM_ENCRYPT" \ "$YADM_LEGACY_DIR/$YADM_ENCRYPT" \
"$YADM_LEGACY_DIR/$YADM_HOOKS"/{pre,post}_* \ "$YADM_LEGACY_DIR/$YADM_HOOKS"/{pre,post}_* \
"$YADM_LEGACY_DIR/$YADM_LEGACY_ARCHIVE" \ "$YADM_LEGACY_DIR/$YADM_LEGACY_ARCHIVE"; do
;
do
[ -e "$legacy_path" ] && legacy_found+=("$legacy_path") [ -e "$legacy_path" ] && legacy_found+=("$legacy_path")
done done
@ -1674,7 +1670,7 @@ ${path_list}
*********** ***********
EOF EOF
printf '%s\n' "$msg" >&2 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 fi 2>/dev/null
case "$OPERATING_SYSTEM" in case "$OPERATING_SYSTEM" in
CYGWIN*|MINGW*|MSYS*) CYGWIN* | MINGW* | MSYS*)
git_version="$("$GIT_PROGRAM" --version 2>/dev/null)" git_version="$("$GIT_PROGRAM" --version 2>/dev/null)"
if [[ "$git_version" =~ windows ]] ; then if [[ "$git_version" =~ windows ]]; then
USE_CYGPATH=1 USE_CYGPATH=1
fi fi
OPERATING_SYSTEM=$(uname -o) OPERATING_SYSTEM=$(uname -o)
;; ;;
*) *) ;;
;;
esac esac
} }
@ -1772,7 +1767,7 @@ function set_operating_system() {
function set_awk() { function set_awk() {
local pgm local pgm
for pgm in "${AWK_PROGRAM[@]}"; do 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 done
} }
@ -1802,8 +1797,8 @@ function invoke_hook() {
exit_status="$2" exit_status="$2"
hook_command="${YADM_HOOKS}/${mode}_$HOOK_COMMAND" hook_command="${YADM_HOOKS}/${mode}_$HOOK_COMMAND"
if [ -x "$hook_command" ] || \ if [ -x "$hook_command" ] ||
{ [[ $OPERATING_SYSTEM == MINGW* ]] && [ -f "$hook_command" ] ;} ; then { [[ $OPERATING_SYSTEM == MINGW* ]] && [ -f "$hook_command" ]; }; then
debug "Invoking hook: $hook_command" debug "Invoking hook: $hook_command"
# expose some internal data to all hooks # expose some internal data to all hooks
@ -1868,7 +1863,7 @@ function assert_private_dirs() {
if [ ! -d "$YADM_WORK/$private_dir" ]; then if [ ! -d "$YADM_WORK/$private_dir" ]; then
debug "Creating $YADM_WORK/$private_dir" debug "Creating $YADM_WORK/$private_dir"
#shellcheck disable=SC2174 #shellcheck disable=SC2174
mkdir -m 0700 -p "$YADM_WORK/$private_dir" &> /dev/null mkdir -m 0700 -p "$YADM_WORK/$private_dir" &>/dev/null
fi fi
done done
} }
@ -1928,12 +1923,12 @@ function parse_encrypt() {
fi fi
;; ;;
esac esac
done < "$YADM_ENCRYPT" done <"$YADM_ENCRYPT"
if [[ ${#include} -gt 0 ]]; then if [[ ${#include} -gt 0 ]]; then
while IFS= read -r filename; do while IFS= read -r filename; do
ENCRYPT_INCLUDE_FILES+=("${filename%/}") ENCRYPT_INCLUDE_FILES+=("${filename%/}")
done <<< "$("$GIT_PROGRAM" ls-files --others "${exclude[@]}" -- "${include[@]}")" done <<<"$("$GIT_PROGRAM" ls-files --others "${exclude[@]}" -- "${include[@]}")"
fi fi
} }
@ -2000,9 +1995,9 @@ function relative_path() {
function auto_alt() { function auto_alt() {
# process alternates if there are possible changes # process alternates if there are possible changes
if [ "$CHANGES_POSSIBLE" = "1" ] ; then if [ "$CHANGES_POSSIBLE" = "1" ]; then
auto_alt=$(config --bool yadm.auto-alt) auto_alt=$(config --bool yadm.auto-alt)
if [ "$auto_alt" != "false" ] ; then if [ "$auto_alt" != "false" ]; then
[ -d "$YADM_REPO" ] && alt [ -d "$YADM_REPO" ] && alt
fi fi
fi fi
@ -2012,9 +2007,9 @@ function auto_alt() {
function auto_perms() { function auto_perms() {
# process permissions if there are possible changes # process permissions if there are possible changes
if [ "$CHANGES_POSSIBLE" = "1" ] ; then if [ "$CHANGES_POSSIBLE" = "1" ]; then
auto_perms=$(config --bool yadm.auto-perms) auto_perms=$(config --bool yadm.auto-perms)
if [ "$auto_perms" != "false" ] ; then if [ "$auto_perms" != "false" ]; then
[ -d "$YADM_REPO" ] && perms [ -d "$YADM_REPO" ] && perms
fi fi
fi fi
@ -2028,12 +2023,12 @@ function auto_bootstrap() {
[ "$DO_BOOTSTRAP" -eq 0 ] && return [ "$DO_BOOTSTRAP" -eq 0 ] && return
[ "$DO_BOOTSTRAP" -eq 3 ] && return [ "$DO_BOOTSTRAP" -eq 3 ] && return
[ "$DO_BOOTSTRAP" -eq 2 ] && bootstrap [ "$DO_BOOTSTRAP" -eq 2 ] && bootstrap
if [ "$DO_BOOTSTRAP" -eq 1 ] ; then if [ "$DO_BOOTSTRAP" -eq 1 ]; then
echo "Found $YADM_BOOTSTRAP" echo "Found $YADM_BOOTSTRAP"
echo "It appears that a bootstrap program exists." echo "It appears that a bootstrap program exists."
echo "Would you like to execute it now? (y/n)" echo "Would you like to execute it now? (y/n)"
read -r answer < /dev/tty read -r answer </dev/tty
if [[ $answer =~ ^[yY]$ ]] ; then if [[ $answer =~ ^[yY]$ ]]; then
bootstrap bootstrap
fi fi
fi fi
@ -2043,8 +2038,8 @@ function auto_bootstrap() {
# ****** Helper Functions ****** # ****** Helper Functions ******
function join_string { function join_string {
local IFS="$1" local IFS="$1"
printf "%s" "${*:2}" printf "%s" "${*:2}"
} }
function in_list { function in_list {
@ -2063,14 +2058,14 @@ function get_mode {
# most *nixes # most *nixes
mode=$(stat -c '%a' "$filename" 2>/dev/null) mode=$(stat -c '%a' "$filename" 2>/dev/null)
if [ -z "$mode" ] ; then if [ -z "$mode" ]; then
# BSD-style # BSD-style
mode=$(stat -f '%p' "$filename" 2>/dev/null) mode=$(stat -f '%p' "$filename" 2>/dev/null)
mode=${mode: -4} mode=${mode: -4}
fi fi
# only accept results if they are octal # only accept results if they are octal
if [[ ! $mode =~ ^[0-7]+$ ]] ; then if [[ ! $mode =~ ^[0-7]+$ ]]; then
mode="" mode=""
fi fi
@ -2105,11 +2100,11 @@ function require_git() {
local more_info="" local more_info=""
if [ "$alt_git" != "" ] ; then if [ "$alt_git" != "" ]; then
GIT_PROGRAM="$alt_git" GIT_PROGRAM="$alt_git"
more_info="\nThis command has been set via the yadm.git-program configuration." more_info="\nThis command has been set via the yadm.git-program configuration."
fi 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" error_out "This functionality requires Git to be installed, but the command '$GIT_PROGRAM' cannot be located.$more_info"
} }
function require_gpg() { function require_gpg() {
@ -2118,11 +2113,11 @@ function require_gpg() {
local more_info="" local more_info=""
if [ "$alt_gpg" != "" ] ; then if [ "$alt_gpg" != "" ]; then
GPG_PROGRAM="$alt_gpg" GPG_PROGRAM="$alt_gpg"
more_info="\nThis command has been set via the yadm.gpg-program configuration." more_info="\nThis command has been set via the yadm.gpg-program configuration."
fi 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" error_out "This functionality requires GPG to be installed, but the command '$GPG_PROGRAM' cannot be located.$more_info"
} }
function require_openssl() { function require_openssl() {
@ -2131,11 +2126,11 @@ function require_openssl() {
local more_info="" local more_info=""
if [ "$alt_openssl" != "" ] ; then if [ "$alt_openssl" != "" ]; then
OPENSSL_PROGRAM="$alt_openssl" OPENSSL_PROGRAM="$alt_openssl"
more_info="\nThis command has been set via the yadm.openssl-program configuration." more_info="\nThis command has been set via the yadm.openssl-program configuration."
fi 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" error_out "This functionality requires OpenSSL to be installed, but the command '$OPENSSL_PROGRAM' cannot be located.$more_info"
} }
function require_repo() { function require_repo() {
@ -2145,11 +2140,11 @@ function require_shell() {
[ -x "$SHELL" ] || error_out "\$SHELL does not refer to an executable." [ -x "$SHELL" ] || error_out "\$SHELL does not refer to an executable."
} }
function require_git_crypt() { 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." error_out "This functionality requires git-crypt to be installed, but the command '$GIT_CRYPT_PROGRAM' cannot be located."
} }
function require_transcrypt() { 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." error_out "This functionality requires transcrypt to be installed, but the command '$TRANSCRYPT_PROGRAM' cannot be located."
} }
function bootstrap_available() { function bootstrap_available() {
@ -2157,23 +2152,23 @@ function bootstrap_available() {
return 1 return 1
} }
function awk_available() { function awk_available() {
command -v "${AWK_PROGRAM[0]}" &> /dev/null && return command -v "${AWK_PROGRAM[0]}" &>/dev/null && return
return 1 return 1
} }
function j2cli_available() { function j2cli_available() {
command -v "$J2CLI_PROGRAM" &> /dev/null && return command -v "$J2CLI_PROGRAM" &>/dev/null && return
return 1 return 1
} }
function envtpl_available() { function envtpl_available() {
command -v "$ENVTPL_PROGRAM" &> /dev/null && return command -v "$ENVTPL_PROGRAM" &>/dev/null && return
return 1 return 1
} }
function esh_available() { function esh_available() {
command -v "$ESH_PROGRAM" &> /dev/null && return command -v "$ESH_PROGRAM" &>/dev/null && return
return 1 return 1
} }
function readlink_available() { function readlink_available() {
command -v "readlink" &> /dev/null && return command -v "readlink" &>/dev/null && return
return 1 return 1
} }
@ -2181,7 +2176,7 @@ function readlink_available() {
function unix_path() { function unix_path() {
# for paths used by bash/yadm # for paths used by bash/yadm
if [ "$USE_CYGPATH" = "1" ] ; then if [ "$USE_CYGPATH" = "1" ]; then
cygpath -u "$1" cygpath -u "$1"
else else
echo "$1" echo "$1"
@ -2189,7 +2184,7 @@ function unix_path() {
} }
function mixed_path() { function mixed_path() {
# for paths used by Git # for paths used by Git
if [ "$USE_CYGPATH" = "1" ] ; then if [ "$USE_CYGPATH" = "1" ]; then
cygpath -m "$1" cygpath -m "$1"
else else
echo "$1" echo "$1"
@ -2213,7 +2208,7 @@ function echo_e() {
# ****** Main processing (when not unit testing) ****** # ****** Main processing (when not unit testing) ******
if [ "$YADM_TEST" != 1 ] ; then if [ "$YADM_TEST" != 1 ]; then
process_global_args "$@" process_global_args "$@"
set_operating_system set_operating_system
set_awk set_awk