1
0
Fork 0
mirror of synced 2024-12-04 06:35:36 -05:00

Compare commits

...

6 commits

Author SHA1 Message Date
Andrey G.
49fab59c91
Merge fdbb9cfe26 into ec10041024 2024-11-24 20:29:13 +01:00
Erik Flodin
ec10041024
Call bootstrap scripts with a tty
Inspired by #449 but using read instead of mapfile to make it work with bash
3. Fixes #344.
2024-11-24 20:18:22 +01:00
Erik Flodin
3a1b236147
Link features in README.md to yadm.io (as suggested in #346) 2024-11-24 17:03:56 +01:00
Andrey G
fdbb9cfe26
added verbose mode for source_if_exists
and also expecting `file` instead of `source` as env. variable to make that possible without dancing around: 
```
#!/bin/bash

file=backup && yadm bootstrap;
file=install && yadm bootstrap;
file=configure &&yadm bootstrap;
```
2023-12-21 21:05:50 -05:00
Andrey G
5a2ed6c68d
linting 2023-12-21 12:40:46 -05:00
Andrey G
f76eecc321
Create bootstrap-source
Add example of bootstrap that can be used to run interactive shell scripts
2023-12-21 12:28:13 -05:00
3 changed files with 116 additions and 11 deletions

View file

@ -18,11 +18,12 @@
**yadm** is a tool for managing [dotfiles][].
* Based on [Git][], with full range of Git's features
* Supports system-specific alternative files or templated files
* Encryption of private data using [GnuPG][], [OpenSSL][], [transcrypt][], or
[git-crypt][]
* Customizable initialization (bootstrapping)
* Customizable hooks for before and after any operation
* Supports system-specific [alternative][feature-alternates] files or
[templated][feature-templates] files
* [Encryption][feature-encryption] of private data using [GnuPG][],
[OpenSSL][], [transcrypt][], or [git-crypt][]
* Customizable initialization ([bootstrapping][feature-bootstrap])
* Customizable [hooks][feature-hooks] for before and after any operation
Complete features, usage, examples and installation instructions can be found on
the [yadm.io][website-link] website.
@ -63,6 +64,11 @@ The star count helps others discover yadm.
[develop-commits]: https://github.com/yadm-dev/yadm/commits/develop
[develop-date]: https://img.shields.io/github/last-commit/yadm-dev/yadm/develop.svg?label=develop
[dotfiles]: https://en.wikipedia.org/wiki/Hidden_file_and_hidden_directory
[feature-alternates]: https://yadm.io/docs/alternates
[feature-bootstrap]: https://yadm.io/docs/bootstrap
[feature-hooks]: https://yadm.io/docs/hooks
[feature-encryption]: https://yadm.io/docs/encryption
[feature-templates]: https://yadm.io/docs/templates
[gh-pages-badge]: https://img.shields.io/github/actions/workflow/status/yadm-dev/yadm/test.yml?branch=gh-pages
[git-crypt]: https://github.com/AGWA/git-crypt
[homebrew-badge]: https://img.shields.io/homebrew/v/yadm.svg

View file

@ -14,11 +14,16 @@ if [[ ! -d "$BOOTSTRAP_D" ]]; then
exit 1
fi
find -L "$BOOTSTRAP_D" -type f | sort | while IFS= read -r bootstrap; do
if [[ -x "$bootstrap" && ! "$bootstrap" =~ "##" && ! "$bootstrap" =~ "~$" ]]; then
if ! "$bootstrap"; then
echo "Error: bootstrap '$bootstrap' failed" >&2
exit 1
fi
declare -a bootstraps
while IFS= read -r bootstrap; do
if [[ -x "$bootstrap" && ! "$bootstrap" =~ "##" && ! "$bootstrap" =~ ~$ ]]; then
bootstraps+=("$bootstrap")
fi
done < <(find -L "$BOOTSTRAP_D" -type f | sort)
for bootstrap in "${bootstraps[@]}"; do
if ! "$bootstrap"; then
echo "Error: bootstrap '$bootstrap' failed" >&2
exit 1
fi
done

View file

@ -0,0 +1,94 @@
#!/bin/bash
# Save this file as ~/.config/yadm/bootstrap and make it executable. It expects
# environment variable `file` with a name of shell script to execute.
# `file` can be relative to ~/.config/yadm/ or has full path.
#
# Usage:
# file=install yadm bootstrap
# or
# file=~/.config/yadm/install yadm bootstrap
#
# where `~/.config/yadm/install` can be like this:
#
# [[ ! $(type -t install) = 'function' ]] && echo "Usage: file=$(basename "$0") yadm bootstrap" && exit 1
#
# confirm yes 'softwareupdate --agree-to-license --install --all' "$(info 'Install ' warning 'OSX updates')"
# install 'brew' '/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"'
#
# brew bundle --global
#
TEXT_COLOR_RED=$(tput setaf 1)
TEXT_COLOR_GREEN=$(tput setaf 2)
TEXT_COLOR_BLUE=$(tput setaf 4)
TEXT_COLOR_YELLOW=$(tput setaf 3)
TEXT_DEFAULT=$(tput sgr0)
info() {
printf "${TEXT_COLOR_BLUE}%s${TEXT_DEFAULT}" "$1"; "${@:2}"
}
error() {
printf "${TEXT_COLOR_RED}%s${TEXT_DEFAULT}" "$1"; "${@:2}"
}
success() {
printf "${TEXT_COLOR_GREEN}%s${TEXT_DEFAULT}" "$1"; "${@:2}"
}
warning() {
printf "${TEXT_COLOR_YELLOW}%s${TEXT_DEFAULT}" "$1"; "${@:2}"
}
source_if_exists() {
local src=$1
local verbose="${2:-no}"
[[ ! -f $src ]] && return 1;
[[ "${verbose:0:1}" == v* ]] && printf "%s\n\n" "$(info "-> $src")";
source "$src"
}
command_exists () {
command -v "$1" &> /dev/null
}
# install a 'command' via 'code' if it was not previously installed yet
install() {
local command=$1
local code=$2
local message=$(info 'Installing ' warning "$command")
if command_exists "$command"; then
echo "$message...[$(success 'already')]"
else
echo "$message..."
eval "$code"
fi
}
# execute a 'code' after confirmation from user
confirm() {
local default_answer="${1:-no}"
local code=$2
local message=$3
local options answer
if [[ "${default_answer:0:1}" == y* ]]; then
options="$(success 'YES')/no"
else
options="yes/$(success 'NO')"
fi
read -r -p "${message} [${options}]:" answer
answer=${answer:-$default_answer}
if [[ "${answer:0:1}" == y* ]]; then
eval "$code"
fi
}
source_if_exists "$(dirname "${0}")/$file" v ||
source_if_exists $file v ||
([[ -z $file ]] && echo "Usage: file=FILENAME yadm bootstrap" || echo "Can't locate file '$file' for bootstrapping")