build.sh: Support comments in package files (#14)
* build.sh: Support comments in package files This patch allows the use of hash comments inside patch files. It's a little ugly, but it strips comments and collapses all whitespace down to single space characters between package names. It handles comments anywhere in a line, as well. Was unsure if \ continuation of the long sed line or the inclusion of a couple of lines of comments explaining what the sed expressions are doing would be appreciated, so didn't include them in this patch. * build.sh: whitespace fix * build.sh: Use sed script for packages files Broke the sed expressions out of build.sh and put them their own documented sed script. This greatly improves readability and avoids build.sh getting messier. Broke the substitution command into two separate subs. The first just deletes comments, and the second collapses all whitespace into a single space. This too is easier to read, and catches a couple of edge cases that would result it not all whitespace being collapsed. The result may still have (one) leading and/or trailing space, which is acceptable.
This commit is contained in:
parent
b9b8df3d11
commit
abc3e45727
2 changed files with 15 additions and 2 deletions
6
build.sh
6
build.sh
|
@ -16,7 +16,8 @@ EOF
|
||||||
fi
|
fi
|
||||||
if [ -f ${i}-packages-nr ]; then
|
if [ -f ${i}-packages-nr ]; then
|
||||||
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
|
log "Begin ${SUB_STAGE_DIR}/${i}-packages-nr"
|
||||||
PACKAGES=`cat $i-packages-nr | tr '\n' ' '`
|
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < ${i}-packages-nr)"
|
||||||
|
PACKAGES="$(sed -e "$sed_expr_packages" < ${i}-packages-nr)"
|
||||||
if [ -n "$PACKAGES" ]; then
|
if [ -n "$PACKAGES" ]; then
|
||||||
on_chroot sh -e - << EOF
|
on_chroot sh -e - << EOF
|
||||||
apt-get install --no-install-recommends -y $PACKAGES
|
apt-get install --no-install-recommends -y $PACKAGES
|
||||||
|
@ -26,7 +27,7 @@ EOF
|
||||||
fi
|
fi
|
||||||
if [ -f ${i}-packages ]; then
|
if [ -f ${i}-packages ]; then
|
||||||
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
|
log "Begin ${SUB_STAGE_DIR}/${i}-packages"
|
||||||
PACKAGES=`cat $i-packages | tr '\n' ' '`
|
PACKAGES="$(sed -f "${SCRIPT_DIR}/remove-comments.sed" < ${i}-packages)"
|
||||||
if [ -n "$PACKAGES" ]; then
|
if [ -n "$PACKAGES" ]; then
|
||||||
on_chroot sh -e - << EOF
|
on_chroot sh -e - << EOF
|
||||||
apt-get install -y $PACKAGES
|
apt-get install -y $PACKAGES
|
||||||
|
@ -77,6 +78,7 @@ EOF
|
||||||
log "End ${SUB_STAGE_DIR}"
|
log "End ${SUB_STAGE_DIR}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
run_stage(){
|
run_stage(){
|
||||||
log "Begin ${STAGE_DIR}"
|
log "Begin ${STAGE_DIR}"
|
||||||
STAGE=$(basename ${STAGE_DIR})
|
STAGE=$(basename ${STAGE_DIR})
|
||||||
|
|
11
scripts/remove-comments.sed
Normal file
11
scripts/remove-comments.sed
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Deletes comments and collapses whitespace in ##-packages files
|
||||||
|
|
||||||
|
# Append (N)ext line to buffer
|
||||||
|
# if (!)not ($)buffer is EOF, (b)ranch to (:)label loop
|
||||||
|
:loop
|
||||||
|
N
|
||||||
|
$ !b loop
|
||||||
|
|
||||||
|
# Buffer is "line1\nline2\n...lineN", del comments and collapse whitespace
|
||||||
|
s/#[^\n]*//g
|
||||||
|
s/[[:space:]]\{1,\}/ /g
|
Loading…
Reference in a new issue