mirror of
https://github.com/TheLocehiliosan/yadm
synced 2026-03-02 03:49:29 +00:00
Merge pull request #220
This commit is contained in:
50
yadm
50
yadm
@@ -45,6 +45,7 @@ GIT_CRYPT_PROGRAM="git-crypt"
|
||||
TRANSCRYPT_PROGRAM="transcrypt"
|
||||
J2CLI_PROGRAM="j2"
|
||||
ENVTPL_PROGRAM="envtpl"
|
||||
ESH_PROGRAM="esh"
|
||||
LSB_RELEASE_PROGRAM="lsb_release"
|
||||
|
||||
OS_RELEASE="/etc/os-release"
|
||||
@@ -250,11 +251,28 @@ function record_score() {
|
||||
done
|
||||
# if we don't find an existing index, create one by appending to the array
|
||||
if [ "$index" -eq -1 ]; then
|
||||
alt_targets+=("$tgt")
|
||||
# set index to the last index (newly created one)
|
||||
for index in "${!alt_targets[@]}"; do :; done
|
||||
# and set its initial score to zero
|
||||
alt_scores[$index]=0
|
||||
# $YADM_CONFIG must be processed first, in case other templates lookup yadm configurations
|
||||
if [ "$tgt" = "$YADM_CONFIG" ]; then
|
||||
alt_targets=("$tgt" "${alt_targets[@]}")
|
||||
alt_sources=("$src" "${alt_sources[@]}")
|
||||
alt_scores=(0 "${alt_scores[@]}")
|
||||
index=0
|
||||
# increase the index of any existing alt_template_cmds
|
||||
new_cmds=()
|
||||
for cmd_index in "${!alt_template_cmds[@]}"; do
|
||||
new_cmds[$((cmd_index+1))]="${alt_template_cmds[$cmd_index]}"
|
||||
done
|
||||
alt_template_cmds=()
|
||||
for cmd_index in "${!new_cmds[@]}"; do
|
||||
alt_template_cmds[$cmd_index]="${new_cmds[$cmd_index]}"
|
||||
done
|
||||
else
|
||||
alt_targets+=("$tgt")
|
||||
# set index to the last index (newly created one)
|
||||
for index in "${!alt_targets[@]}"; do :; done
|
||||
# and set its initial score to zero
|
||||
alt_scores[$index]=0
|
||||
fi
|
||||
fi
|
||||
|
||||
# record nothing if a template command is registered for this file
|
||||
@@ -299,6 +317,8 @@ function choose_template_cmd() {
|
||||
|
||||
if [ "$kind" = "default" ] || [ "$kind" = "" ] && awk_available; then
|
||||
echo "template_default"
|
||||
elif [ "$kind" = "esh" ] && esh_available; then
|
||||
echo "template_esh"
|
||||
elif [ "$kind" = "j2cli" ] || [ "$kind" = "j2" ] && j2cli_available; then
|
||||
echo "template_j2cli"
|
||||
elif [ "$kind" = "envtpl" ] || [ "$kind" = "j2" ] && envtpl_available; then
|
||||
@@ -407,6 +427,22 @@ function template_envtpl() {
|
||||
[ -f "$temp_file" ] && mv -f "$temp_file" "$output"
|
||||
}
|
||||
|
||||
function template_esh() {
|
||||
input="$1"
|
||||
output="$2"
|
||||
temp_file="${output}.$$.$RANDOM"
|
||||
|
||||
"$ESH_PROGRAM" -o "$temp_file" "$input" \
|
||||
YADM_CLASS="$local_class" \
|
||||
YADM_OS="$local_system" \
|
||||
YADM_HOSTNAME="$local_host" \
|
||||
YADM_USER="$local_user" \
|
||||
YADM_DISTRO="$local_distro" \
|
||||
YADM_SOURCE="$input"
|
||||
|
||||
[ -f "$temp_file" ] && mv -f "$temp_file" "$output"
|
||||
}
|
||||
|
||||
# ****** yadm Commands ******
|
||||
|
||||
function alt() {
|
||||
@@ -1938,6 +1974,10 @@ function envtpl_available() {
|
||||
command -v "$ENVTPL_PROGRAM" &> /dev/null && return
|
||||
return 1
|
||||
}
|
||||
function esh_available() {
|
||||
command -v "$ESH_PROGRAM" &> /dev/null && return
|
||||
return 1
|
||||
}
|
||||
function readlink_available() {
|
||||
command -v "readlink" &> /dev/null && return
|
||||
return 1
|
||||
|
||||
Reference in New Issue
Block a user