Skip to content

Commit

Permalink
📝 Add timestamp to messages
Browse files Browse the repository at this point in the history
  • Loading branch information
jemrobinson committed Aug 21, 2023
1 parent f72bf18 commit e916a52
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,49 +4,49 @@ CONFIG_PATH="/opt/adguardhome/conf/AdGuardHome.yaml"

# Admin username
if [ -z "$ADMIN_USERNAME" ]; then
echo "Container requires ADMIN_USERNAME environment variable"
echo "$(date -Iseconds) [error] Container requires ADMIN_USERNAME environment variable"
exit 1
fi
sed -i "s|ADMIN_USERNAME|$ADMIN_USERNAME|g" "$CONFIG_PATH"

# Admin password
if [ -z "$ADMIN_PASSWORD" ]; then
echo "Container requires ADMIN_PASSWORD environment variable"
echo "$(date -Iseconds) [error] Container requires ADMIN_PASSWORD environment variable"
exit 1
fi
ADMIN_PASSWORD_ENCRYPTED=$(htpasswd -B -n -b "$ADMIN_USERNAME" "$ADMIN_PASSWORD" | cut -d ":" -f 2)
sed -i "s|ADMIN_PASSWORD_ENCRYPTED|$ADMIN_PASSWORD_ENCRYPTED|g" "$CONFIG_PATH"

# Upstream DNS
if [ -z "$UPSTREAM_DNS" ]; then
echo "Container requires UPSTREAM_DNS environment variable"
echo "$(date -Iseconds) [error] Container requires UPSTREAM_DNS environment variable"
exit 1
fi
sed -i "s|UPSTREAM_DNS|$UPSTREAM_DNS|g" "$CONFIG_PATH"

# Allow filter
echo "Applying allow filter rules (if any)"
echo "$(date -Iseconds) [info] Applying allow filter rules (if any)"
if [ -n "$SPACE_SEPARATED_FILTER_ALLOW" ]; then
# Add each rule from the allow list
echo "$SPACE_SEPARATED_FILTER_ALLOW" | tr ' ' '\n' | while read -r FILTER_ALLOW; do
echo "... allowing '$FILTER_ALLOW'"
sed -i "s: - FILTER_ALLOW: - \"@||$FILTER_ALLOW\"\n - FILTER_ALLOW:g" "$CONFIG_PATH"
echo "$(date -Iseconds) [info] ... allowing '$FILTER_ALLOW'"
sed -i "s: - FILTER_ALLOW: - \"@@||$FILTER_ALLOW\"\n - FILTER_ALLOW:g" "$CONFIG_PATH"
done
fi
# Remove the allow placeholder
sed -i "/FILTER_ALLOW/d" $CONFIG_PATH

# Deny filter
echo "Applying deny filter rules (if any)"
echo "$(date -Iseconds) [info] Applying deny filter rules (if any)"
if [ -n "$SPACE_SEPARATED_FILTER_DENY" ]; then
# Add each rule from the deny list
echo "$SPACE_SEPARATED_FILTER_DENY" | tr ' ' '\n' | while read -r FILTER_DENY; do
echo "... denying '$FILTER_DENY'"
echo "$(date -Iseconds) [info] ... denying '$FILTER_DENY'"
sed -i "s: - FILTER_DENY: - \"$FILTER_DENY\"\n - FILTER_DENY:g" "$CONFIG_PATH"
done
fi
# Remove the deny placeholder
sed -i "/FILTER_DENY/d" "$CONFIG_PATH"

# Final output
cat $CONFIG_PATH
echo "$(date -Iseconds) [info] Finished configuring AdGuardHome"

0 comments on commit e916a52

Please sign in to comment.