This example script will generate a finished repository using one or more repository definition files. Since the files are shell scripts, the method is extensible and allows the use of a single source patch in many generated patches
chmod a+x <path>/generaterepo.sh
.sample.repo
~~~~~
location='/Volumes/ftpmountpoint'
comment='#Maintained by: <user> for: <organization>'</organization></user>
usb3=templates/usb3.txt
function patch1 {
NAME='A sample referenced patch'
TYPE='DSDT'
patchline 'This is an arbitrary line, probably for comments'
patchadd templates/gigabitethernet.txt
patchline '#This is a comment'
}
function patch2 {
NAME='A sample variable patch'
TYPE='DSDT'
patchadd $usb3
patchline '#Another comment'
}
function patch3 {
NAME='A sample replaced patch'
TYPE='DSDT'
patchline '#The command below will replace #1# in the template with HELLOWORLD'
patchadd templates/signon.txt HELLOWORLD
patchline '#The next will make several replacements, #1#, #2#, #3#'
patchadd templates/finish.txt HELLO BONJOUR BIENVENUE
}
function patch4 {
NAME='A sample heredoc patch'
TYPE='DSDT'
patchline '#This patch uses heredoc syntax to embed the text directly in the definition file'
patchline <<EOF
into device label RP08 insert begin
Device (HDAU) {
Name (_ADR, Zero)
}
end
EOF
}
function finish {
umount $location
#Perform any cleanup here, like unmounting a share. This function is optional
#You may also use the included put() convenience method for SCP transfers
put username@host:path
}
Example Template
----
This example shows a template with two replacements, one for the parent device's label, and the second for the address to insert. You might call this template from a patch like "patchadd templates/hdau.txt RP08 0xFFFF0000"
hdau.txt
into device label #1# insert begin
Device (HDAU) {
Name (_ADR, #2#)
}
end
Generaterepo.sh
----
function msg {
printf "\e[1;32m==>\e[m %s\n" "$1"]
}
function msg2 {
printf "\e[1;34m ->\e[m %s\n" "$1"
}
function info {
printf " %s\n" "$1"
}
function err {
printf "\e[1;31mError:\e[m $1\n"
exit $2
}
function warn {
printf "\e[1;33mWarning:\e[m $1\n"
}
function contains {
[ "${1#*$2}" != "$1" || [ "$1" == "$2" ]
}
function usage {
msg "Usage: ${0##/*} [DEFINITION FILES]"
exit 0
}
function patchline {
local text
if [ $# -eq 0 ];then read -d'\0' text; else text="$1";fi
echo "$text" >&3
}
function patchadd {
local text="$(cat "$1")" index=1
[ -n "$text" ]
shift
while [ $index -le $# ]; do text="${text//#$index#/${!index}}"; let index++; done
contains "$text" "#$index#" && warn "Unreplaced index $index"
patchline "$text"
}
function put {
msg2 "Putting to $1"
pushd "$location" &>/dev/null
scp .maciasl * $1
popd &>/dev/null
rm -rf "$location"
}
function generate {
msg "Generating $1"
source "$1"
mkdir -p "$location"
:>"$location"/.maciasl
local index=1
local ref=patch$index tempfile filename
while type $ref >/dev/null 2>&1; do
msg2 "Building #$index"
tempfile=$(mktemp -u -t repo)
exec 3<>$tempfile
patchline "$comment"
eval $ref
unset $ref
exec 3>&-
filename="$(echo ${NAME// /} | tr '[A-Z]' '[a-z]')".txt
[ -f "$location/$filename" ] && warn "$filename already exists in $location"
mv "$tempfile" "$location/$filename"
echo -e "$NAME\t$TYPE\t$filename" >>"$location"/.maciasl
let index++
ref=patch$index
done
if type finish >/dev/null 2>&1; then msg2 'Finishing'; finish; unset finish; fi
msg2 'Finished'
}
while [ $# -gt 0 ]
do if [ -f "$1" ]; then
generate "$1"
else usage
fi
shift
done
~~~~