Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore commented lines when reading PRIVACYLEVEL from config file #5177

Merged
merged 1 commit into from
Mar 22, 2023

Conversation

yubiuser
Copy link
Member

@yubiuser yubiuser commented Feb 16, 2023

What does this PR aim to accomplish?:

During updates, we extract PRIVACYLEVEL from /etc/pihole/pihole-FTL.conf and later set it again

# Get the privacy level if it exists (default is 0)
if [[ -f "${FTL_CONFIG_FILE}" ]]; then
PRIVACY_LEVEL=$(sed -ne 's/PRIVACYLEVEL=\(.*\)/\1/p' "${FTL_CONFIG_FILE}")
# If no setting was found, default to 0
PRIVACY_LEVEL="${PRIVACY_LEVEL:-0}"
fi

addOrEditKeyValPair "${FTL_CONFIG_FILE}" "PRIVACYLEVEL" "${PRIVACY_LEVEL}"

However, if /etc/pihole/pihole-FTL.conf contains a commented line containing PRIVACYLEVEL, setting it during update will fail because it did not ignore the commented line.

+ addOrEditKeyValPair /etc/pihole/pihole-FTL.conf PRIVACYLEVEL '#; 3
0'
+ local file=/etc/pihole/pihole-FTL.conf
+ local key=PRIVACYLEVEL
+ local 'value=#; 3
0'

This was reported here: #5174

How does this PR accomplish the above?:

Adding a sed to remove all commented lines from /etc/pihole/pihole-FTL.conf before extracting PRIVACYLEVEL


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code and I have tested my changes.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

@yubiuser yubiuser requested a review from a team February 16, 2023 14:33
@yubiuser yubiuser added the PR: Approval Required Open Pull Request, needs approval label Feb 16, 2023
@yubiuser yubiuser linked an issue Feb 16, 2023 that may be closed by this pull request
@rdwebdesign rdwebdesign changed the title Ignore commented lines when reding PRIVACYLEVEL from config file Ignore commented lines when reading PRIVACYLEVEL from config file Feb 16, 2023
@dschaper dschaper self-requested a review February 16, 2023 19:43
@dschaper
Copy link
Member

Can you squash to 1 commit and FP?

Create dedicated getVal function in utils.sh as it might be useful somewhere else
Account for tailing comments and $key not being on the first line

Signed-off-by: Christian König <ckoenig@posteo.de>
@yubiuser
Copy link
Member Author

Done.

@dschaper dschaper closed this Mar 22, 2023
@dschaper dschaper reopened this Mar 22, 2023
@dschaper dschaper merged commit fb032ea into development Mar 22, 2023
@dschaper dschaper deleted the fix/privay_level branch March 22, 2023 19:23
@yubiuser yubiuser mentioned this pull request Mar 22, 2023
1 task
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: Approval Required Open Pull Request, needs approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sed: -e expression #1, char 37: invalid usage of line address 0
2 participants