Skip to content

Commit

Permalink
Add script firstboot to change pihole admin password and reconfigure …
Browse files Browse the repository at this point in the history
…defaults of pihole
  • Loading branch information
franklintimoteo committed Dec 2, 2022
1 parent c787b41 commit 628f4bd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
51 changes: 51 additions & 0 deletions overlay/usr/lib/inithooks/bin/pihole.py
@@ -0,0 +1,51 @@
#!/usr/bin/python3
"""Reconfigure defaults configs Pi-hole and set admin password
Option:
--pass= unless provided, will ask interactively
"""

import sys
import getopt
import subprocess
from subprocess import call

from libinithooks.dialog_wrapper import Dialog


def usage(s=None):
if s:
print("Error:", s, file=sys.stderr)
print("Syntax: %s [options]" % sys.argv[0], file=sys.stderr)
print(__doc__, file=sys.stderr)
sys.exit(1)

def main():
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], "h",
['help', 'pass='])
except getopt.GetoptError as e:
usage(e)

password = ""
for opt, val in opts:
if opt in ('-h', '--help'):
usage()
elif opt == '--pass':
password = val

if not password:
d = Dialog('TurnKey GNU/Linux - First boot configuration')
password = d.get_password(
"Pi-hole password",
"Enter new for the Pi-hole 'admin' account")

call(['pihole', '-a', '-p', password])

basicinstall="/etc/.pihole/automated install/basic-install.sh"
call(['sed', '-ri', '/ "\$\{opt1a\}" "\$\{opt1b\}" ./d', basicinstall])
call(['pihole', 'reconfigure'])
call(['git', 'checkout', basicinstall])

if __name__ == "__main__":
main()
7 changes: 7 additions & 0 deletions overlay/usr/lib/inithooks/firstboot.d/40pihole
@@ -0,0 +1,7 @@
#!/bin/bash -e
# reconfigure defaults pihole and set pihole password

. /etc/default/inithooks

[ -e $INITHOOKS_CONF ] && . $INITHOOKS_CONF
$INITHOOKS_PATH/bin/pihole.py

0 comments on commit 628f4bd

Please sign in to comment.