Automated Installation Enhancements and Fixes

I have been spending the better part of a week trying to figure out why a manual installation works on Ubuntu 18.04 and my Ansible automated installation succeeds but Pi-hole does not work. On the positive side, I know the basic-install.sh pretty good now.

The problem was the pihole-setupVars.conf file. The basic-install.sh would check to see if pihole-setupVars.conf existed. If it did, it would import it with source "${setupVars}". What I have found was that it did not interpret any value with a true/false value. All of the other variables were imported correctly.

The root cause was the tool I was using to edit the code (Visual Studio Code). It was appending a CRLF to the end of each line instead of a LF. It was an easy fix to just change the setting in VS Code. However, to help anyone else in the future that might run into this, I fixed the basic-install.sh to look for and replace CRLF with LF.

The question I have is, should the fix be implemented in basic-install.sh or in the Ansible playbook that is used to put the file on the server? In the installation script it will help everyone (there is already similar functions happening in the code). If I put it in the Ansible playbook, the script will not have to change but it will only help people who use Ansible to deploy Pi-hole.
Choices:

  1. basic-install.sh with accountForRefactor (accountForRefactor performs similar actions)
  2. basic-install.sh before source
  3. Ansible playbook

Related to this…
After performing a lot more testing to see if I could break my fix, (each test was on a fresh install of Ubuntu 18.04.4) I noticed more issues with setupVars.conf. I added comments to the top of the file noting what I had found and used the standard # to indicate a comment. I also left the WEBPASSWORD variable with a hashed password in the file.

During the installation I have two main ssh sessions open into the new pi-hole server monitoring the following files:

  • tail -f /var/log/unattended-pihole-install.log (my command to install is “~/pihole-install.sh --unattended >> /var/log/unnattended-pihole-install.log”
  • cat -v /etc/pihole/setupVars.conf (I would repeat this multiple times during the installation)

After adding the notes and performing additional installations, I notice errors on the settings page of the GUI. Errors like PHP error (2): syntax error, unexpected '=' in /etc/pihole/setupVars.conf on line 14

When I looked at the setupVars.conf file, they were in a completely different order than I put them and two of the lines were combined into one. I found two issues;

  1. The finalExports function deletes most of the lines in the setupVars.conf file and then puts them back in a predefined order. The better solution would be to replace the value of the variables if they changed.
  2. The function uses the echo command to append the variables back to the file. The echo command appends to the end of the last line of the file, not after. If there is not a blank line after the last one in the file, the first variable added back will be on the same line as the last one that was not deleted. That’s the root cause of the error in the GUI.

The fix for the combined lines is similar to the CRLF issue and can be fixed at the same time. For this, we just need to ensure the file ends with a newline. So same question as earlier, should the fix be implemented in basic-install.sh or in the Ansible playbook that is used to put the file on the server?
Choices:

  1. basic-install.sh with accountForRefactor (accountForRefactor performs similar actions)
  2. basic-install.sh before source
  3. Ansible playbook

Last question, should we change the delete & echo commands to simply replace the value. This has to be fixed in the basic-install.sh. Keep in mind, when you change settings in the GUI, the new variable and value get appended to the setupVars.conf file. If you copy that file and use if for other implementations, it will be rearranged if the code stays as is.
Choices:

  1. yes, I want to keep the order the way I set it.
  2. no, leave it as is.

Last note…
One more thing we might have to monitor in down the road, the setupVars.conf file is used as a variable file for the Bash install script and as a PHP ini file for /var/www/html/admin/settings.php. Bash reads comments as “#” and PHP reads comments as “;” (As of PHP 7.0.0, “#” are no longer recognized as PHP comments).

When you add comments to the setupVars.conf file you have to add both “# ;” or you will have errors.

I already have the code worked out and tested for the first two issues, I just need to know where to put it so I can do a pull request. Changing the delete & echo should not be that hard to figure out.

I see you’ve had some issues with forking and cloning. Here’s the process that works with GitHub based repositories.

The process would be to:

  1. Fork https://github.com/pi-hole/pi-hole/ to a repo under your namespace. It looks like you’ve done that with https://github.com/jlagermann/pi-hole

  2. Clone https://github.com/jlagermann/pi-hole

  3. Checkout the development branch with your clone of https://github.com/jlagermann/pi-hole

  4. Create your topic branch, based on the development branch code.

  5. Make your changes, push the topic branch to your repo.

  6. Open a Pull Request to merge your repo’s branch in to our repo.

1 Like

Thanks,

That’s basically what I did the very first time, switching to the development branch first.

The main purpose for fixing the basic-install.sh script is to enable using the setupVars.conf file and Ansible. With Ansible, I have an example inventory file the playbook to run. I also created a short readme with some instructions. Should I include all of those file in the same pull request? They are all related to the same solution.

I’ll wait to see if anyone responds before I summit the pull request again.

The PR should include just the changes to the existing files. Ansible Galaxy would be a better place for the rest of the information and guides.

I did not know you have Ansible Galaxy. It did not come up in any internet searches I did on how to install Pi-hole with Ansible.

We don’t have a Pi-hole namespace on Galaxy for the project. I meant that you could host your Ansible playbooks on Galaxy and provide them to users that way.