Skip to content

Commit

Permalink
Refactoring update.sh
Browse files Browse the repository at this point in the history
- Removing sed and HEREDOC hell
- Using FEATURES var from Makefile
  • Loading branch information
wiltonsr committed Jun 18, 2024
1 parent a336211 commit a84ab95
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 88 deletions.
11 changes: 8 additions & 3 deletions Dockerfile.template
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,17 @@ RUN cvs -d :pserver:[email protected]:/cvs -z9 co libowfat ; \

# http://erdgeist.org/arts/software/opentracker/#build-instructions
RUN cd /usr/src/opentracker ; \
%%MAKEFILE_SED_EXPRESSIONS%% \
# Build opentracker statically to use it in scratch image
LDFLAGS=-static make ; \
LDFLAGS=-static make \
%%MAKEFILE_FEATURES%% ;\
bash -c 'mkdir -pv /tmp/stage/{etc/opentracker,bin}' ; \
bash -c 'touch /tmp/stage/etc/opentracker/{white,black}list' ; \
cp -v opentracker.conf.sample /tmp/stage/etc/opentracker/opentracker.conf ; \
%%OPENTRACKER_CONF_SED_EXPRESSIONS%% \
# Opentrack configuration file
sed -ri \
-e 's!(.*)(tracker.user)(.*)!\2 farmhand!g;' \
%%OPENTRACKER_CONFS%% \
/tmp/stage/etc/opentracker/opentracker.conf ; \
install -m 755 opentracker.debug /tmp/stage/bin ; \
make DESTDIR=/tmp/stage BINDIR="/bin" install

Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ Because of that there are two another tags, `blacklist` and `whitelist`, which w
### Whitelist Mode

```bash
touch local-whitelist
chmod -v 0666 local-whitelist

docker run \
--rm \
--name opentracker \
Expand All @@ -149,6 +152,9 @@ docker run \
### Blacklist Mode

```bash
touch local-blacklist
chmod -v 0666 local-blacklist

docker run \
--rm \
--name opentracker \
Expand Down
25 changes: 14 additions & 11 deletions blacklist.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ RUN cvs -d :pserver:[email protected]:/cvs -z9 co libowfat ; \

# http://erdgeist.org/arts/software/opentracker/#build-instructions
RUN cd /usr/src/opentracker ; \
# Makefile blacklist sed expressions
sed -ri -e '\
/^#.*DWANT_ACCESSLIST_BLACK/s/^#//; \
' Makefile ; \
# Build opentracker statically to use it in scratch image
LDFLAGS=-static make ; \
LDFLAGS=-static make \
FEATURES+=-DWANT_FULLSCRAPE \
FEATURES+=-DWANT_FULLLOG_NETWORKS \
FEATURES+=-DWANT_LOG_NUMWANT \
FEATURES+=-DWANT_MODEST_FULLSCRAPES \
FEATURES+=-DWANT_SPOT_WOODPECKER \
FEATURES+=-DWANT_ACCESSLIST_BLACK \
;\
bash -c 'mkdir -pv /tmp/stage/{etc/opentracker,bin}' ; \
bash -c 'touch /tmp/stage/etc/opentracker/{white,black}list' ; \
cp -v opentracker.conf.sample /tmp/stage/etc/opentracker/opentracker.conf ; \
# Opentrack conf blacklist sed expressions
sed -ri -e '\
s!(.*)(tracker.user)(.*)!\2 farmhand!g; \
s!(.*)(access.blacklist)(.*)!\2 /etc/opentracker/blacklist!g; \
' /tmp/stage/etc/opentracker/opentracker.conf ; \
touch /tmp/stage/etc/opentracker/blacklist ; \
# Opentrack configuration file
sed -ri \
-e 's!(.*)(tracker.user)(.*)!\2 farmhand!g;' \
-e 's!(.*)(access.blacklist)(.*)!\2 /etc/opentracker/blacklist!g;' \
/tmp/stage/etc/opentracker/opentracker.conf ; \
install -m 755 opentracker.debug /tmp/stage/bin ; \
make DESTDIR=/tmp/stage BINDIR="/bin" install

Expand Down
19 changes: 13 additions & 6 deletions open.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,22 @@ RUN cvs -d :pserver:[email protected]:/cvs -z9 co libowfat ; \

# http://erdgeist.org/arts/software/opentracker/#build-instructions
RUN cd /usr/src/opentracker ; \
# No need to change Makefile to open mode
# Build opentracker statically to use it in scratch image
LDFLAGS=-static make ; \
LDFLAGS=-static make \
FEATURES+=-DWANT_FULLSCRAPE \
FEATURES+=-DWANT_FULLLOG_NETWORKS \
FEATURES+=-DWANT_LOG_NUMWANT \
FEATURES+=-DWANT_MODEST_FULLSCRAPES \
FEATURES+=-DWANT_SPOT_WOODPECKER \
;\
bash -c 'mkdir -pv /tmp/stage/{etc/opentracker,bin}' ; \
bash -c 'touch /tmp/stage/etc/opentracker/{white,black}list' ; \
cp -v opentracker.conf.sample /tmp/stage/etc/opentracker/opentracker.conf ; \
# Opentrack conf whitelist sed expressions
sed -ri -e '\
s!(.*)(tracker.user)(.*)!\2 farmhand!g; \
' /tmp/stage/etc/opentracker/opentracker.conf ; \
# Opentrack configuration file
sed -ri \
-e 's!(.*)(tracker.user)(.*)!\2 farmhand!g;' \
\
/tmp/stage/etc/opentracker/opentracker.conf ; \
install -m 755 opentracker.debug /tmp/stage/bin ; \
make DESTDIR=/tmp/stage BINDIR="/bin" install

Expand Down
90 changes: 33 additions & 57 deletions update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,90 +8,66 @@ variants=(
)

function create_variant() {
declare -a features=(
"-DWANT_FULLSCRAPE"
"-DWANT_FULLLOG_NETWORKS"
"-DWANT_LOG_NUMWANT"
"-DWANT_MODEST_FULLSCRAPES"
"-DWANT_SPOT_WOODPECKER"
)

variant=$1
variantFile="$variant.Dockerfile"
variant_file="$variant.Dockerfile"

touch "${variantFile}"
touch "${variant_file}"

template="Dockerfile.template"

cat <<__EOF__ >"${variantFile}"
cat <<__EOF__ >"${variant_file}"
#
# NOTE: THIS DOCKERFILE IS GENERATED VIA update.sh from ${template}
#
# PLEASE DO NOT EDIT IT DIRECTLY.
#
__EOF__

cat "$template" >>"$variantFile"
cat "$template" >>"$variant_file"

echo "updating $variantFile"
echo "updating $variant_file"

case "$variant" in
open)
cat <<'__EOF__' >/tmp/makefileSedExpressions
# No need to change Makefile to open mode
__EOF__

cat <<'__EOF__' >/tmp/opentrackerSedExpressions
# Opentrack conf whitelist sed expressions
sed -ri -e '\
s!(.*)(tracker.user)(.*)!\2 farmhand!g; \
' /tmp/stage/etc/opentracker/opentracker.conf ; \
__EOF__

features+=()
extra_sed_confs=''
;;

blacklist)
cat <<'__EOF__' >/tmp/makefileSedExpressions
# Makefile blacklist sed expressions
sed -ri -e '\
/^#.*DWANT_ACCESSLIST_BLACK/s/^#//; \
' Makefile ; \
__EOF__

cat <<'__EOF__' >/tmp/opentrackerSedExpressions
# Opentrack conf blacklist sed expressions
sed -ri -e '\
s!(.*)(tracker.user)(.*)!\2 farmhand!g; \
s!(.*)(access.blacklist)(.*)!\2 /etc/opentracker/blacklist!g; \
' /tmp/stage/etc/opentracker/opentracker.conf ; \
touch /tmp/stage/etc/opentracker/blacklist ; \
__EOF__

features+=("-DWANT_ACCESSLIST_BLACK")
extra_sed_confs="-e 's!(.*)(access.blacklist)(.*)!\\\2 /etc/opentracker/blacklist!g;'"
;;

whitelist)
cat <<'__EOF__' >/tmp/makefileSedExpressions
# Makefile whitelist sed expressions
sed -ri -e '\
/^#.*DWANT_ACCESSLIST_WHITE/s/^#//; \
' Makefile ; \
__EOF__

cat <<'__EOF__' >/tmp/opentrackerSedExpressions
# Opentrack conf whitelist sed expressions
sed -ri -e '\
s!(.*)(tracker.user)(.*)!\2 farmhand!g; \
s!(.*)(access.whitelist)(.*)!\2 /etc/opentracker/whitelist!g; \
' /tmp/stage/etc/opentracker/opentracker.conf ; \
touch /tmp/stage/etc/opentracker/whitelist ; \
__EOF__

features+=("-DWANT_ACCESSLIST_WHITE")
extra_sed_confs="-e 's!(.*)(access.whitelist)(.*)!\\\2 /etc/opentracker/whitelist!g;'"
;;

esac

# Replace the variables.
sed -i '/%%MAKEFILE_SED_EXPRESSIONS%%/ {
r /tmp/makefileSedExpressions
d
}' "$variantFile"
features_sed_string=''
for i in "${features[@]}"; do
# Add extra slashes to escape on below sed substitution
features_sed_string+="FEATURES+=${i} \\\\\n "
done

sed -i '/%%OPENTRACKER_CONF_SED_EXPRESSIONS%%/ {
r /tmp/opentrackerSedExpressions
d
}' "$variantFile"
# Replace MAKEFILE_FEATURES variable from template
sed -ri \
-e 's@%%MAKEFILE_FEATURES%%@'"${features_sed_string}"'@g;' \
"$variant_file"

# Replace OPENTRACKER_CONFS variable from template
sed -ri \
-e 's@%%OPENTRACKER_CONFS%%@'"${extra_sed_confs}"'@g;' \
"$variant_file"
}

if [ -z "$1" ]; then
Expand Down
25 changes: 14 additions & 11 deletions whitelist.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ RUN cvs -d :pserver:[email protected]:/cvs -z9 co libowfat ; \

# http://erdgeist.org/arts/software/opentracker/#build-instructions
RUN cd /usr/src/opentracker ; \
# Makefile whitelist sed expressions
sed -ri -e '\
/^#.*DWANT_ACCESSLIST_WHITE/s/^#//; \
' Makefile ; \
# Build opentracker statically to use it in scratch image
LDFLAGS=-static make ; \
LDFLAGS=-static make \
FEATURES+=-DWANT_FULLSCRAPE \
FEATURES+=-DWANT_FULLLOG_NETWORKS \
FEATURES+=-DWANT_LOG_NUMWANT \
FEATURES+=-DWANT_MODEST_FULLSCRAPES \
FEATURES+=-DWANT_SPOT_WOODPECKER \
FEATURES+=-DWANT_ACCESSLIST_WHITE \
;\
bash -c 'mkdir -pv /tmp/stage/{etc/opentracker,bin}' ; \
bash -c 'touch /tmp/stage/etc/opentracker/{white,black}list' ; \
cp -v opentracker.conf.sample /tmp/stage/etc/opentracker/opentracker.conf ; \
# Opentrack conf whitelist sed expressions
sed -ri -e '\
s!(.*)(tracker.user)(.*)!\2 farmhand!g; \
s!(.*)(access.whitelist)(.*)!\2 /etc/opentracker/whitelist!g; \
' /tmp/stage/etc/opentracker/opentracker.conf ; \
touch /tmp/stage/etc/opentracker/whitelist ; \
# Opentrack configuration file
sed -ri \
-e 's!(.*)(tracker.user)(.*)!\2 farmhand!g;' \
-e 's!(.*)(access.whitelist)(.*)!\2 /etc/opentracker/whitelist!g;' \
/tmp/stage/etc/opentracker/opentracker.conf ; \
install -m 755 opentracker.debug /tmp/stage/bin ; \
make DESTDIR=/tmp/stage BINDIR="/bin" install

Expand Down

0 comments on commit a84ab95

Please sign in to comment.