3

I would like to install Pi-Hole automatically inside Vagrant (VirtualBox).  Therefore, in an automated script, it has to run to box start.  Unfortunately, normally, you have to answer multiple installation questions to install Pi-Hole, e.g., IPv4 or 6, ..., and you need keyboard interaction with the setup (by the user).

Is there any way or solution to install it without any interaction?  How can I write it in a Bash script or Vagrantfile?

Kutsubato
  • 85
  • 1
  • 8

2 Answers2

5

This discussion says you can create the configuration options in the file /etc/pihole/setupVars.conf (documented here) and run with the --unattended flag, eg:

curl -L https://install.pi-hole.net | bash /dev/stdin --unattended
meuh
  • 49,672
  • 2
  • 52
  • 114
  • Do you know by any chance what kind of hash is supposed to be used in WEBPASSWORD var? – Drew Apr 24 '18 at 20:42
  • Judging from the example and this [source file](https://github.com/pi-hole/AdminLTE/blob/master/scripts/pi-hole/php/password.php#L41), it is created with `hash('sha256',hash('sha256',$_POST["pw"]))`. – meuh Apr 24 '18 at 20:52
  • so for example the output of `echo -n P@ssw0rd | sha256sum`, which is `b03ddf3ca2e714a6548e7495e2a03f5e824eaac9837cd7f159c67b90fb4b7342` should set the pihole web interface password to `P@ssw0rd`... Wondering, why it might not work... – Drew Apr 24 '18 at 22:03
  • I guess because it's a double hash... Should be `echo -n P@ssw0rd | sha256sum | cut -d ' ' -f 1 | sha256sum` – Drew Apr 24 '18 at 22:12
  • 1
    Nope... Still doesn't work ((( – Drew Apr 24 '18 at 22:13
  • Says wrong password – Drew Apr 24 '18 at 22:27
  • You might have to replace your `cut` with something like `awk '{printf "%s",$1 }'` to exclulde the newline at the end for the second hash. – meuh Apr 25 '18 at 07:28
  • Returns error `255 Failed to open terminal` everytime! – Jishan Dec 01 '19 at 21:09
  • Install and set your password up then copy the password value from /etc/pihole/setupVars.conf then you can tear down and install with your Terraform/Ansible scripts. – Brian Di Palma Jul 11 '21 at 08:39
0

To get the value for the passord, according to the source:

You can do the following: (I don't recommend leaving your password in your bash history)

export PASSWORD="p@ssword"
return=$(echo -n "$PASSWORD" | sha256sum | sed 's/\s.*$//')
return=$(echo -n "$return" | sha256sum | sed 's/\s.*$//')
Abdou
  • 1