Remove superfluous `;` in comments

This commit is contained in:
Tim Byrne 2019-03-24 17:22:11 -05:00
parent 58edf313aa
commit 2aa1710214
No known key found for this signature in database
GPG Key ID: 14DB4FC2465A4B12
1 changed files with 91 additions and 91 deletions

182
yadm
View File

@ -15,7 +15,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
#; execute script with bash (shebang line is /bin/sh for portability) # execute script with bash (shebang line is /bin/sh for portability)
if [ -z "$BASH_VERSION" ]; then if [ -z "$BASH_VERSION" ]; then
[ "$YADM_TEST" != 1 ] && exec bash "$0" "$@" [ "$YADM_TEST" != 1 ] && exec bash "$0" "$@"
fi fi
@ -44,34 +44,34 @@ OPERATING_SYSTEM="Unknown"
ENCRYPT_INCLUDE_FILES="unparsed" ENCRYPT_INCLUDE_FILES="unparsed"
#; flag causing path translations with cygpath # flag causing path translations with cygpath
USE_CYGPATH=0 USE_CYGPATH=0
#; flag when something may have changes (which prompts auto actions to be performed) # flag when something may have changes (which prompts auto actions to be performed)
CHANGES_POSSIBLE=0 CHANGES_POSSIBLE=0
#; flag when a bootstrap should be performed after cloning # flag when a bootstrap should be performed after cloning
#; 0: skip auto_bootstrap, 1: ask, 2: perform bootstrap, 3: prevent bootstrap # 0: skip auto_bootstrap, 1: ask, 2: perform bootstrap, 3: prevent bootstrap
DO_BOOTSTRAP=0 DO_BOOTSTRAP=0
function main() { function main() {
require_git require_git
#; capture full command, for passing to hooks # capture full command, for passing to hooks
FULL_COMMAND="$*" FULL_COMMAND="$*"
#; create the YADM_DIR if it doesn't exist yet # create the YADM_DIR if it doesn't exist yet
[ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR" [ -d "$YADM_DIR" ] || mkdir -p "$YADM_DIR"
#; parse command line arguments # parse command line arguments
local retval=0 local retval=0
internal_commands="^(alt|bootstrap|clean|clone|config|decrypt|encrypt|enter|help|init|introspect|list|perms|version)$" internal_commands="^(alt|bootstrap|clean|clone|config|decrypt|encrypt|enter|help|init|introspect|list|perms|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_ARGS=() YADM_ARGS=()
shift shift
@ -79,26 +79,26 @@ function main() {
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() and clone() -f) # used by init() and clone()
FORCE="YES" FORCE="YES"
;; ;;
-l) #; used by decrypt() -l) # used by decrypt()
DO_LIST="YES" DO_LIST="YES"
;; ;;
-w) #; used by init() and clone() -w) # used by init() and clone()
if [[ ! "$2" =~ ^/ ]] ; then if [[ ! "$2" =~ ^/ ]] ; then
error_out "You must specify a fully qualified work tree" error_out "You must specify a fully qualified work tree"
fi fi
YADM_WORK="$2" YADM_WORK="$2"
shift shift
;; ;;
*) #; any unhandled arguments *) # any unhandled arguments
YADM_ARGS+=("$1") YADM_ARGS+=("$1")
;; ;;
esac esac
@ -109,14 +109,14 @@ function main() {
invoke_hook "pre" invoke_hook "pre"
$YADM_COMMAND "${YADM_ARGS[@]}" $YADM_COMMAND "${YADM_ARGS[@]}"
else else
#; any other commands are simply passed through to git # any other commands are simply passed through to git
HOOK_COMMAND="$1" HOOK_COMMAND="$1"
invoke_hook "pre" invoke_hook "pre"
git_command "$@" git_command "$@"
retval="$?" retval="$?"
fi fi
#; process automatic events # process automatic events
auto_alt auto_alt
auto_perms auto_perms
auto_bootstrap auto_bootstrap
@ -125,7 +125,7 @@ function main() {
} }
#; ****** yadm Commands ****** # ****** yadm Commands ******
function alt() { function alt() {
@ -149,7 +149,7 @@ function alt() {
local_host="$(config local.hostname)" local_host="$(config local.hostname)"
if [ -z "$local_host" ] ; then if [ -z "$local_host" ] ; then
local_host=$(hostname) local_host=$(hostname)
local_host=${local_host%%.*} #; trim any domain from hostname local_host=${local_host%%.*} # trim any domain from hostname
fi fi
match_host="(%|$local_host)" match_host="(%|$local_host)"
@ -159,16 +159,16 @@ function alt() {
fi fi
match_user="(%|$local_user)" match_user="(%|$local_user)"
#; regex for matching "<file>##CLASS.SYSTEM.HOSTNAME.USER" # regex for matching "<file>##CLASS.SYSTEM.HOSTNAME.USER"
match1="^(.+)##(()|$match_system|$match_system\.$match_host|$match_system\.$match_host\.$match_user)$" match1="^(.+)##(()|$match_system|$match_system\.$match_host|$match_system\.$match_host\.$match_user)$"
match2="^(.+)##($match_class|$match_class\.$match_system|$match_class\.$match_system\.$match_host|$match_class\.$match_system\.$match_host\.$match_user)$" match2="^(.+)##($match_class|$match_class\.$match_system|$match_class\.$match_system\.$match_host|$match_class\.$match_system\.$match_host\.$match_user)$"
cd_work "Alternates" || return cd_work "Alternates" || return
#; only be noisy if the "alt" command was run directly # only be noisy if the "alt" command was run directly
[ "$YADM_COMMAND" = "alt" ] && loud="YES" [ "$YADM_COMMAND" = "alt" ] && loud="YES"
#; decide if a copy should be done instead of a symbolic link # decide if a copy should be done instead of a symbolic link
local do_copy=0 local do_copy=0
if [[ $OPERATING_SYSTEM == CYGWIN* ]] ; then if [[ $OPERATING_SYSTEM == CYGWIN* ]] ; then
if [[ $(config --bool yadm.cygwin-copy) == "true" ]] ; then if [[ $(config --bool yadm.cygwin-copy) == "true" ]] ; then
@ -176,14 +176,14 @@ function alt() {
fi fi
fi fi
#; loop over all "tracked" files # loop over all "tracked" files
#; for every file which matches the above regex, create a symlink # for every file which matches the above regex, create a symlink
for match in $match1 $match2; do for match in $match1 $match2; do
last_linked='' last_linked=''
local IFS=$'\n' local IFS=$'\n'
for tracked_file in $("$GIT_PROGRAM" ls-files | sort) "${ENCRYPT_INCLUDE_FILES[@]}"; do for tracked_file in $("$GIT_PROGRAM" ls-files | sort) "${ENCRYPT_INCLUDE_FILES[@]}"; do
tracked_file="$YADM_WORK/$tracked_file" tracked_file="$YADM_WORK/$tracked_file"
#; process both the path, and it's parent directory # process both the path, and it's parent directory
for alt_path in "$tracked_file" "${tracked_file%/*}"; do for alt_path in "$tracked_file" "${tracked_file%/*}"; do
if [ -e "$alt_path" ] ; then if [ -e "$alt_path" ] ; then
if [[ $alt_path =~ $match ]] ; then if [[ $alt_path =~ $match ]] ; then
@ -207,8 +207,8 @@ function alt() {
done done
done done
#; loop over all "tracked" files # loop over all "tracked" files
#; for every file which is a *##yadm.j2 create a real file # for every file which is a *##yadm.j2 create a real file
local IFS=$'\n' local IFS=$'\n'
local match="^(.+)##yadm\\.j2$" local match="^(.+)##yadm\\.j2$"
for tracked_file in $("$GIT_PROGRAM" ls-files | sort) "${ENCRYPT_INCLUDE_FILES[@]}"; do for tracked_file in $("$GIT_PROGRAM" ls-files | sort) "${ENCRYPT_INCLUDE_FILES[@]}"; do
@ -261,13 +261,13 @@ function clone() {
while [[ $# -gt 0 ]] ; do while [[ $# -gt 0 ]] ; do
key="$1" key="$1"
case $key in case $key 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
;; ;;
*) #; main arguments are kept intact *) # main arguments are kept intact
clone_args+=("$1") clone_args+=("$1")
;; ;;
esac esac
@ -276,18 +276,18 @@ function clone() {
[ -n "$DEBUG" ] && display_private_perms "initial" [ -n "$DEBUG" ] && display_private_perms "initial"
#; clone will begin with a bare repo # clone will begin with a bare repo
local empty= local empty=
init $empty init $empty
#; add the specified remote, and configure the repo to track origin/master # add the specified remote, and configure the repo to track origin/master
debug "Adding remote to new repo" debug "Adding remote to new repo"
"$GIT_PROGRAM" remote add origin "${clone_args[@]}" "$GIT_PROGRAM" remote add origin "${clone_args[@]}"
debug "Configuring new repo to track origin/master" debug "Configuring new repo to track origin/master"
"$GIT_PROGRAM" config branch.master.remote origin "$GIT_PROGRAM" config branch.master.remote origin
"$GIT_PROGRAM" config branch.master.merge refs/heads/master "$GIT_PROGRAM" config branch.master.merge refs/heads/master
#; fetch / merge (and possibly fallback to reset) # fetch / merge (and possibly fallback to reset)
debug "Doing an initial fetch of the origin" debug "Doing an initial fetch of the origin"
"$GIT_PROGRAM" fetch origin || { "$GIT_PROGRAM" fetch origin || {
debug "Removing repo after failed clone" debug "Removing repo after failed clone"
@ -327,7 +327,7 @@ function clone() {
in another way. in another way.
EOF EOF
else else
#; skip auto_bootstrap if conflicts could not be stashed # skip auto_bootstrap if conflicts could not be stashed
DO_BOOTSTRAP=0 DO_BOOTSTRAP=0
cat <<EOF cat <<EOF
**NOTE** **NOTE**
@ -359,7 +359,7 @@ function config() {
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
for supported_config in $(introspect_configs); do for supported_config in $(introspect_configs); do
@ -375,14 +375,14 @@ EOF
require_repo require_repo
#; operate on the yadm repo's configuration file # operate on the yadm repo's configuration file
#; this is always local to the machine # this is always local to the machine
git config --local "$@" git config --local "$@"
CHANGES_POSSIBLE=1 CHANGES_POSSIBLE=1
else else
#; operate on the yadm configuration file # operate on the yadm configuration file
git config --file="$(mixed_path "$YADM_CONFIG")" "$@" git config --file="$(mixed_path "$YADM_CONFIG")" "$@"
fi fi
@ -402,7 +402,7 @@ function decrypt() {
tar_option="x" tar_option="x"
fi fi
#; decrypt the archive # decrypt the archive
if ($GPG_PROGRAM -d "$YADM_ARCHIVE" || echo 1) | tar v${tar_option}f - -C "$YADM_WORK"; then if ($GPG_PROGRAM -d "$YADM_ARCHIVE" || echo 1) | tar v${tar_option}f - -C "$YADM_WORK"; then
[ ! "$DO_LIST" = "YES" ] && echo "All files decrypted." [ ! "$DO_LIST" = "YES" ] && echo "All files decrypted."
else else
@ -421,7 +421,7 @@ function encrypt() {
cd_work "Encryption" || return cd_work "Encryption" || return
#; Build gpg options for gpg # Build gpg options for gpg
GPG_KEY="$(config yadm.gpg-recipient)" GPG_KEY="$(config yadm.gpg-recipient)"
if [ "$GPG_KEY" = "ASK" ]; then if [ "$GPG_KEY" = "ASK" ]; then
GPG_OPTS=("--no-default-recipient" "-e") GPG_OPTS=("--no-default-recipient" "-e")
@ -431,19 +431,19 @@ function encrypt() {
GPG_OPTS=("-c") GPG_OPTS=("-c")
fi fi
#; report which files will be encrypted # report which files will be encrypted
echo "Encrypting the following files:" echo "Encrypting the following files:"
printf '%s\n' "${ENCRYPT_INCLUDE_FILES[@]}" printf '%s\n' "${ENCRYPT_INCLUDE_FILES[@]}"
echo echo
#; encrypt all files which match the globs # encrypt all files which match the globs
if tar -f - -c "${ENCRYPT_INCLUDE_FILES[@]}" | $GPG_PROGRAM --yes "${GPG_OPTS[@]}" --output "$YADM_ARCHIVE"; then if tar -f - -c "${ENCRYPT_INCLUDE_FILES[@]}" | $GPG_PROGRAM --yes "${GPG_OPTS[@]}" --output "$YADM_ARCHIVE"; then
echo "Wrote new file: $YADM_ARCHIVE" echo "Wrote new file: $YADM_ARCHIVE"
else else
error_out "Unable to write $YADM_ARCHIVE" error_out "Unable to write $YADM_ARCHIVE"
fi fi
#; 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
@ -485,13 +485,13 @@ 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
#; ensure private .ssh and .gnupg directories exist first # ensure private .ssh and .gnupg directories exist first
#; TODO: consider restricting this to only commands which modify the work-tree # TODO: consider restricting this to only commands which modify the work-tree
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
@ -500,7 +500,7 @@ function git_command() {
CHANGES_POSSIBLE=1 CHANGES_POSSIBLE=1
#; pass commands through to git # pass commands through to git
debug "Running git command $GIT_PROGRAM $*" debug "Running git command $GIT_PROGRAM $*"
"$GIT_PROGRAM" "$@" "$GIT_PROGRAM" "$@"
return "$?" return "$?"
@ -544,17 +544,17 @@ EOF
function init() { function init() {
#; safety check, don't attempt to init when the repo is already present # safety check, don't attempt to init when the repo is already present
[ -d "$YADM_REPO" ] && [ -z "$FORCE" ] && \ [ -d "$YADM_REPO" ] && [ -z "$FORCE" ] && \
error_out "Git repo already exists. [$YADM_REPO]\nUse '-f' if you want to force it to be overwritten." error_out "Git repo already exists. [$YADM_REPO]\nUse '-f' if you want to force it to be overwritten."
#; remove existing if forcing the init to happen anyway # remove existing if forcing the init to happen anyway
[ -d "$YADM_REPO" ] && { [ -d "$YADM_REPO" ] && {
debug "Removing existing repo prior to init" debug "Removing existing repo prior to init"
rm -rf "$YADM_REPO" rm -rf "$YADM_REPO"
} }
#; init a new bare repo # init a new bare repo
debug "Init new repo" debug "Init new repo"
"$GIT_PROGRAM" init --shared=0600 --bare "$(mixed_path "$YADM_REPO")" "$@" "$GIT_PROGRAM" init --shared=0600 --bare "$(mixed_path "$YADM_REPO")" "$@"
configure_repo configure_repo
@ -629,12 +629,12 @@ 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
#; list tracked files # list tracked files
"$GIT_PROGRAM" ls-files "$GIT_PROGRAM" ls-files
} }
@ -643,33 +643,33 @@ function perms() {
parse_encrypt parse_encrypt
#; TODO: prevent repeats in the files changed # TODO: prevent repeats in the files changed
cd_work "Perms" || return cd_work "Perms" || return
GLOBS=() GLOBS=()
#; include the archive created by "encrypt" # include the archive created by "encrypt"
[ -f "$YADM_ARCHIVE" ] && GLOBS+=("$YADM_ARCHIVE") [ -f "$YADM_ARCHIVE" ] && GLOBS+=("$YADM_ARCHIVE")
#; 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/*") GLOBS+=(".ssh" ".ssh/*")
fi fi
#; include all gpg files (unless disabled) # include all gpg files (unless disabled)
if [[ $(config --bool yadm.gpg-perms) != "false" ]] ; then if [[ $(config --bool yadm.gpg-perms) != "false" ]] ; then
GLOBS+=(".gnupg" ".gnupg/*") GLOBS+=(".gnupg" ".gnupg/*")
fi fi
#; include any files we encrypt # include any files we encrypt
GLOBS+=("${ENCRYPT_INCLUDE_FILES[@]}") GLOBS+=("${ENCRYPT_INCLUDE_FILES[@]}")
#; 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 2>&1 chmod -f go-rwx ${GLOBS[@]} >/dev/null 2>&1
#; TODO: detect and report changing permissions in a portable way # TODO: detect and report changing permissions in a portable way
} }
@ -680,7 +680,7 @@ function version() {
} }
#; ****** Utility Functions ****** # ****** Utility Functions ******
function query_distro() { function query_distro() {
distro="" distro=""
@ -692,54 +692,54 @@ function query_distro() {
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
if [[ ! "$2" =~ ^/ ]] ; then if [[ ! "$2" =~ ^/ ]] ; then
error_out "You must specify a fully qualified yadm directory" error_out "You must specify a fully qualified yadm directory"
fi fi
YADM_DIR="$2" YADM_DIR="$2"
shift shift
;; ;;
--yadm-repo) #; override the standard YADM_REPO --yadm-repo) # override the standard YADM_REPO
if [[ ! "$2" =~ ^/ ]] ; then if [[ ! "$2" =~ ^/ ]] ; then
error_out "You must specify a fully qualified repo path" error_out "You must specify a fully qualified repo path"
fi fi
YADM_OVERRIDE_REPO="$2" YADM_OVERRIDE_REPO="$2"
shift shift
;; ;;
--yadm-config) #; override the standard YADM_CONFIG --yadm-config) # override the standard YADM_CONFIG
if [[ ! "$2" =~ ^/ ]] ; then if [[ ! "$2" =~ ^/ ]] ; then
error_out "You must specify a fully qualified config path" error_out "You must specify a fully qualified config path"
fi fi
YADM_OVERRIDE_CONFIG="$2" YADM_OVERRIDE_CONFIG="$2"
shift shift
;; ;;
--yadm-encrypt) #; override the standard YADM_ENCRYPT --yadm-encrypt) # override the standard YADM_ENCRYPT
if [[ ! "$2" =~ ^/ ]] ; then if [[ ! "$2" =~ ^/ ]] ; then
error_out "You must specify a fully qualified encrypt path" error_out "You must specify a fully qualified encrypt path"
fi fi
YADM_OVERRIDE_ENCRYPT="$2" YADM_OVERRIDE_ENCRYPT="$2"
shift shift
;; ;;
--yadm-archive) #; override the standard YADM_ARCHIVE --yadm-archive) # override the standard YADM_ARCHIVE
if [[ ! "$2" =~ ^/ ]] ; then if [[ ! "$2" =~ ^/ ]] ; then
error_out "You must specify a fully qualified archive path" error_out "You must specify a fully qualified archive path"
fi fi
YADM_OVERRIDE_ARCHIVE="$2" YADM_OVERRIDE_ARCHIVE="$2"
shift shift
;; ;;
--yadm-bootstrap) #; override the standard YADM_BOOTSTRAP --yadm-bootstrap) # override the standard YADM_BOOTSTRAP
if [[ ! "$2" =~ ^/ ]] ; then if [[ ! "$2" =~ ^/ ]] ; then
error_out "You must specify a fully qualified bootstrap path" error_out "You must specify a fully qualified bootstrap path"
fi fi
YADM_OVERRIDE_BOOTSTRAP="$2" YADM_OVERRIDE_BOOTSTRAP="$2"
shift shift
;; ;;
*) #; main arguments are kept intact *) # main arguments are kept intact
MAIN_ARGS+=("$1") MAIN_ARGS+=("$1")
;; ;;
esac esac
@ -750,14 +750,14 @@ function process_global_args() {
function configure_paths() { function configure_paths() {
#; change all paths to be relative to YADM_DIR # change all paths to be relative to YADM_DIR
YADM_REPO="$YADM_DIR/$YADM_REPO" YADM_REPO="$YADM_DIR/$YADM_REPO"
YADM_CONFIG="$YADM_DIR/$YADM_CONFIG" YADM_CONFIG="$YADM_DIR/$YADM_CONFIG"
YADM_ENCRYPT="$YADM_DIR/$YADM_ENCRYPT" YADM_ENCRYPT="$YADM_DIR/$YADM_ENCRYPT"
YADM_ARCHIVE="$YADM_DIR/$YADM_ARCHIVE" YADM_ARCHIVE="$YADM_DIR/$YADM_ARCHIVE"
YADM_BOOTSTRAP="$YADM_DIR/$YADM_BOOTSTRAP" YADM_BOOTSTRAP="$YADM_DIR/$YADM_BOOTSTRAP"
#; independent overrides for paths # independent overrides for paths
if [ -n "$YADM_OVERRIDE_REPO" ]; then if [ -n "$YADM_OVERRIDE_REPO" ]; then
YADM_REPO="$YADM_OVERRIDE_REPO" YADM_REPO="$YADM_OVERRIDE_REPO"
fi fi
@ -774,7 +774,7 @@ function configure_paths() {
YADM_BOOTSTRAP="$YADM_OVERRIDE_BOOTSTRAP" YADM_BOOTSTRAP="$YADM_OVERRIDE_BOOTSTRAP"
fi fi
#; use the yadm repo for all git operations # use the yadm repo for all git operations
GIT_DIR=$(mixed_path "$YADM_REPO") GIT_DIR=$(mixed_path "$YADM_REPO")
export GIT_DIR export GIT_DIR
@ -784,23 +784,23 @@ function configure_repo() {
debug "Configuring new repo" debug "Configuring new repo"
#; change bare to false (there is a working directory) # change bare to false (there is a working directory)
"$GIT_PROGRAM" config core.bare 'false' "$GIT_PROGRAM" config core.bare 'false'
#; set the worktree for the yadm repo # set the worktree for the yadm repo
"$GIT_PROGRAM" config core.worktree "$(mixed_path "$YADM_WORK")" "$GIT_PROGRAM" config core.worktree "$(mixed_path "$YADM_WORK")"
#; by default, do not show untracked files and directories # by default, do not show untracked files and directories
"$GIT_PROGRAM" config status.showUntrackedFiles no "$GIT_PROGRAM" config status.showUntrackedFiles no
#; possibly used later to ensure we're working on the yadm repo # possibly used later to ensure we're working on the yadm repo
"$GIT_PROGRAM" config yadm.managed 'true' "$GIT_PROGRAM" config yadm.managed 'true'
} }
function set_operating_system() { function set_operating_system() {
#; special detection of WSL (windows subsystem for linux) # special detection of WSL (windows subsystem for linux)
local proc_version local proc_version
proc_version=$(cat "$PROC_VERSION" 2>/dev/null) proc_version=$(cat "$PROC_VERSION" 2>/dev/null)
if [[ "$proc_version" =~ Microsoft ]]; then if [[ "$proc_version" =~ Microsoft ]]; then
@ -851,7 +851,7 @@ function invoke_hook() {
if [ -x "$hook_command" ] ; then if [ -x "$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
work=$(unix_path "$("$GIT_PROGRAM" config core.worktree)") work=$(unix_path "$("$GIT_PROGRAM" config core.worktree)")
YADM_HOOK_COMMAND=$HOOK_COMMAND YADM_HOOK_COMMAND=$HOOK_COMMAND
YADM_HOOK_EXIT=$exit_status YADM_HOOK_EXIT=$exit_status
@ -867,7 +867,7 @@ function invoke_hook() {
"$hook_command" "$hook_command"
hook_status=$? hook_status=$?
#; failing "pre" hooks will prevent commands from being run # failing "pre" hooks will prevent commands from being run
if [ "$mode" = "pre" ] && [ "$hook_status" -ne 0 ]; then if [ "$mode" = "pre" ] && [ "$hook_status" -ne 0 ]; then
echo "Hook $hook_command was not successful" echo "Hook $hook_command was not successful"
echo "$HOOK_COMMAND will not be run" echo "$HOOK_COMMAND will not be run"
@ -922,7 +922,7 @@ function parse_encrypt() {
exclude_pattern="^!(.+)" exclude_pattern="^!(.+)"
if [ -f "$YADM_ENCRYPT" ] ; then if [ -f "$YADM_ENCRYPT" ] ; then
#; parse both included/excluded # parse both included/excluded
while IFS='' read -r line || [ -n "$line" ]; do while IFS='' read -r line || [ -n "$line" ]; do
if [[ ! $line =~ ^# && ! $line =~ ^[[:space:]]*$ ]] ; then if [[ ! $line =~ ^# && ! $line =~ ^[[:space:]]*$ ]] ; then
local IFS=$'\n' local IFS=$'\n'
@ -944,7 +944,7 @@ function parse_encrypt() {
fi fi
done < "$YADM_ENCRYPT" done < "$YADM_ENCRYPT"
#; remove excludes from the includes # remove excludes from the includes
#(SC2068 is disabled because in this case, we desire globbing) #(SC2068 is disabled because in this case, we desire globbing)
FINAL_INCLUDE=() FINAL_INCLUDE=()
#shellcheck disable=SC2068 #shellcheck disable=SC2068
@ -957,7 +957,7 @@ function parse_encrypt() {
[ -n "$skip" ] || FINAL_INCLUDE+=("$included") [ -n "$skip" ] || FINAL_INCLUDE+=("$included")
done done
#; sort the encrypted files # sort the encrypted files
#shellcheck disable=SC2207 #shellcheck disable=SC2207
IFS=$'\n' ENCRYPT_INCLUDE_FILES=($(sort <<<"${FINAL_INCLUDE[*]}")) IFS=$'\n' ENCRYPT_INCLUDE_FILES=($(sort <<<"${FINAL_INCLUDE[*]}"))
unset IFS unset IFS
@ -965,11 +965,11 @@ function parse_encrypt() {
} }
#; ****** Auto Functions ****** # ****** Auto Functions ******
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
@ -981,7 +981,7 @@ 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
@ -1010,7 +1010,7 @@ function auto_bootstrap() {
} }
#; ****** Prerequisites Functions ****** # ****** Prerequisites Functions ******
function require_archive() { function require_archive() {
[ -f "$YADM_ARCHIVE" ] || error_out "$YADM_ARCHIVE does not exist. did you forget to create it?" [ -f "$YADM_ARCHIVE" ] || error_out "$YADM_ARCHIVE does not exist. did you forget to create it?"
@ -1061,10 +1061,10 @@ function envtpl_available() {
return 1 return 1
} }
#; ****** Directory tranlations ****** # ****** Directory tranlations ******
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
@ -1072,7 +1072,7 @@ function unix_path() {
fi fi
} }
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
@ -1080,7 +1080,7 @@ function mixed_path() {
fi fi
} }
#; ****** echo replacements ****** # ****** echo replacements ******
function echo() { function echo() {
IFS=' ' IFS=' '
printf '%s\n' "$*" printf '%s\n' "$*"
@ -1094,7 +1094,7 @@ function echo_e() {
printf '%b\n' "$*" printf '%b\n' "$*"
} }
#; ****** 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 "$@"