Skip to content

Commit

Permalink
Pi-hole for Android 1.7
Browse files Browse the repository at this point in the history
Update p4a-install, rc.local, add ntp
  • Loading branch information
DesktopECHO committed Oct 6, 2022
1 parent e2fbed3 commit 60a0605
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .motd
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Pi-hole for Android 1.6 [20220908]
Pi-hole for Android 1.7 [20221005]

Pi-hole Stats -> padd
Install or Update -> p4a-install
Expand Down
2 changes: 2 additions & 0 deletions .poweroff
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ service crond stop
service syslog-ng stop
bash -c "unchroot am start -a com.android.internal.intent.action.REQUEST_SHUTDOWN" > /dev/null 2>&1
bash -c "unchroot am start -n android/com.android.internal.app.ShutdownActivity" > /dev/null 2>&1
sleep 3
read -p "Powering Off..."
2 changes: 2 additions & 0 deletions .reboot
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ service xrdp stop
service crond stop
service syslog-ng stop
bash -c "unchroot am start -a android.intent.action.REBOOT" > /dev/null 2>&1
sleep 3
read -p "Rebooting..."
37 changes: 21 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@ Pi-hole for Android is a CentOS disk image for [Linux Deploy](https://play.googl
- Android 4.x requires an older release: **https://github.com/meefik/linuxdeploy/releases/tag/2.5.1**

- Download the latest Pi-hole for Android disk image:
- **[Release v1.6 - September 8, 2022](https://github.com/DesktopECHO/Pi-hole-for-Android/releases/download/v1.6/p4a16.tgz)**
- **[Release v1.7 - Octover 5, 2022](https://github.com/DesktopECHO/Pi-hole-for-Android/releases/download/v1.7/p4a17.tgz)**

- Open **Linux Deploy** and change ONLY these settings:
- Open Properties Menu (Bottom Right)
- Distribution: **rootfs.tar**
- Source Path - This varies depending on the device, ie: **${EXTERNAL_STORAGE}/Download/p4a16.tgz**
- Image size (MB): **4000** (Recommmended, for smaller devices minimum is 2000 MB)
- Set password for user **android**
- Init -> **Enable**
- Go back to main window, click **Options** Menu (Three dots, usually at top right of screen) and click **Install**
- Wait a few minutes for the image to install before proceeding to the next step. When install is complete, the Linux Deploy console window will show the following at the end of the console output:
- Open the 'Hamburger menu' (Symbol with three dashes at top left of screen) then touch **Settings**. Place a checkmark on these options:
- **Lock Screen** (If you want to keep display always on)
- **Lock Wi-Fi** (If your device has Wi-Fi)
- **Wake Lock**
- **Autostart**
- **Debug Mode** (Provides console output for Pi-hole status)
- Open **Properties Menu** (To the right of the 'Stop' button)
- Distribution: **rootfs.tar**
- Source Path - This varies depending on the device, ie: **${EXTERNAL_STORAGE}/Download/p4a17.tgz**
- Image size (MB): **4000** (Recommmended, for smaller devices minimum is 2000 MB)
- Set password for user **android**
- Init -> **Enable**
- Open **Options** Menu (Three dots at top right of screen)
- Select **Install** and "OK" to confirm.
- Wait a few minutes for the image to install.

- When install is complete, the Linux Deploy console window will show the following at the end of the console output:

`````[HH:mm:ss] >>> :: Configuring core/profile ...`````

Expand All @@ -42,13 +51,9 @@ Pi-hole for Android is a CentOS disk image for [Linux Deploy](https://play.googl

`````[HH:mm:ss] >>> deploy`````

- **Before you continue, make sure the Linux Deploy Console is free of error messages.** If there are errors, troubleshoot by verifying the location of **p4a16.tgz** using a [file manager](https://github.com/DesktopECHO/Pi-hole-for-Android/wiki/Trouble-finding-path-where-Pi%E2%80%90hole-image-is-downloaded,-or-errors-are-reported-during-creation-of-Pi%E2%80%90hole-disk-image.) as the path can vary by device. If you have trouble installing the image in Linux Deploy it may be because of SELinux. See this [post on XDA](https://forum.xda-developers.com/t/app-tool-2-0-official-the-selinux-switch.3656502/) for an APK to disable SELinux.

- Open the 'Hamburger menu' (Three dashes at top left) and touch **Settings**
- Place checkmark on **Lock Wi-Fi** (If your device has Wi-Fi)
- Place checkmark on **Autostart**

Touch the **[ ▸ START ]** button and confirm.
- **Before you continue, make sure the Linux Deploy Console is free of error messages.** If there are errors, troubleshoot by verifying the location of **p4a17.tgz** using a [file manager](https://github.com/DesktopECHO/Pi-hole-for-Android/wiki/Trouble-finding-path-where-Pi%E2%80%90hole-image-is-downloaded,-or-errors-are-reported-during-creation-of-Pi%E2%80%90hole-disk-image.) as the path can vary by device. If you have trouble installing the image in Linux Deploy it may be because of SELinux. See this [post on XDA](https://forum.xda-developers.com/t/app-tool-2-0-official-the-selinux-switch.3656502/) for an APK to disable SELinux.

Touch the **[ ▸ START ]** button, and "OK" to confirm - The instance takes a few seconds to "boot"

-----------------------------------------------------------
**INSTALLATION COMPLETE - PI-HOLE IS RUNNING ON YOUR ANDROID DEVICE!**
Expand Down
154 changes: 154 additions & 0 deletions etc/init.d/ntpd
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#!/bin/bash
#
# ntpd This shell script takes care of starting and stopping
# ntpd (NTPv4 daemon).
#
# chkconfig: - 58 74
# description: ntpd is the NTPv4 daemon. \
# The Network Time Protocol (NTP) is used to synchronize the time of \
# a computer client or server to another server or reference time syntaxhighlight, \
# such as a radio or satellite receiver or modem.

# Source function library.
. /etc/init.d/functions

if [ -f /etc/sysconfig/ntpd ];then
. /etc/sysconfig/ntpd
fi

ntpconf=/etc/ntp.conf
ntpstep=/etc/ntp/step-tickers

RETVAL=0
prog="ntpd"

sync_hwclock() {
ARC=0
SRM=0
UTC=0

if [ -f /etc/sysconfig/clock ]; then
. /etc/sysconfig/clock

# convert old style clock config to new values
if [ "${CLOCKMODE}" = "GMT" ]; then
UTC=true
elif [ "${CLOCKMODE}" = "ARC" ]; then
ARC=true
fi
fi

CLOCKFLAGS="$CLOCKFLAGS --systohc"

case "$UTC" in
yes|true) CLOCKFLAGS="$CLOCKFLAGS --utc";;
no|false) CLOCKFLAGS="$CLOCKFLAGS --localtime";;
esac
case "$ARC" in
yes|true) CLOCKFLAGS="$CLOCKFLAGS --arc";;
esac
case "$SRM" in
yes|true) CLOCKFLAGS="$CLOCKFLAGS --srm";;
esac

action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS
}

readconf() {
dostep=''
dropstr=''
OPTIND=1
while getopts ":46aAbc:dD:f:gi:k:l:LnN:p:P:qr:s:t:u:v:V:x" args $OPTIONS;
do
case "$args" in
x) dostep=yes;;
c) ntpconf="$OPTARG";;
u) dropstr="-U $(echo $OPTARG | sed 's/:.*//')";;
esac
done

[ -x /sbin/ntpd -a -f $ntpconf ] || exit 0

tickers=''
if [ -s "$ntpstep" ]; then
tickers=$(sed 's/#.*//' $ntpstep)
echo "$tickers" | grep -qi '[a-z0-9]' && dostep=yes || tickers=''
fi
if [ -n "$dostep" -a -z "$tickers" ]; then
# -x option is used, but step-tickers doesn't exist or contain
# anything useful, use servers from ntp.conf instead
tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \
fgrep -v 127.127.1.0)
fi
}

start() {
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 1

readconf;

if [ -n "$dostep" ]; then
echo -n $"$prog: Synchronizing with time server: "
/sbin/ntpdate $dropstr -s -b $NTPDATE_OPTIONS $tickers &>/dev/null
RETVAL=$?
[ $RETVAL -eq 0 ] && success || failure
echo
if [ $RETVAL -eq 0 ]; then
[ "$SYNC_HWCLOCK" = "yes" ] && sync_hwclock
else
OPTIONS="$OPTIONS -g"
fi
else
# -g can replace the grep for time servers
# as it permits ntpd to violate its 1000s limit once.
OPTIONS="$OPTIONS -g"
fi
# Start daemons.
echo -n $"Starting $prog: "
daemon ntpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch /var/lock/subsys/ntpd
return $RETVAL
}

stop() {
echo -n $"Shutting down $prog: "
killproc ntpd
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/ntpd
return $RETVAL
}

# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status ntpd
RETVAL=$?
;;
restart|reload)
stop
start
RETVAL=$?
;;
condrestart)
if [ -f /var/lock/subsys/ntpd ]; then
stop
start
RETVAL=$?
fi
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
RETVAL=3
esac

exit $RETVAL
5 changes: 0 additions & 5 deletions etc/motd

This file was deleted.

12 changes: 11 additions & 1 deletion etc/rc.local
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/bash

# Clean-up environment for startup, update PADD, install unbound for new deployment
ntpd -gq
curl --silent --output /bin/padd https://raw.githubusercontent.com/pi-hole/PADD/master/padd.sh
rm -rf /sbin/service /var/lock/subsys/* /tmp/* /var/run/*.pid /sbin/poweroff /sbin/reboot /bin/pihole
/bin/cp /.service /sbin/service ; /bin/cp /.poweroff /sbin/poweroff ; /bin/cp /.reboot /sbin/reboot; /bin/cp /.service /bin/update-rc.d ; ln -s /usr/local/bin/pihole /bin/pihole ; /bin/cp /.systemctl /usr/bin/systemctl ; /bin/cp /.motd /etc/motd
Expand Down Expand Up @@ -34,13 +35,22 @@ sed -i "/IPV4_ADDRESS/c\IPV4_ADDRESS=$ipaddr/$subnetmask" /etc/pihole/setupVars.
sed -i "/PIHOLE_INTERFACE/c\PIHOLE_INTERFACE=$device" /etc/pihole/setupVars.conf

# Start Services
yes ' ' | sed 40q
echo '_______________________________________'
echo ' '
echo ' Pi-hole for Android '
echo ' '
service syslog-ng start
service crond start
service dropbear start
service xrdp start
service lighttpd start
service unbound start
service pihole-FTL start

# Quietly start FTL and get better reporting from pihole status
service pihole-FTL start > /var/log/pihole.log 2>&1
pihole status
echo '_______________________________________'

# This needs to be at the end of rc.local
touch /var/lock/subsys/local
29 changes: 5 additions & 24 deletions usr/local/bin/p4a-install
Original file line number Diff line number Diff line change
@@ -1,31 +1,12 @@
#!/bin/bash
[[ ! -f /opt/rh/devtoolset-9/root/usr/bin/gcc ]] && yum -y install https://buildlogs.centos.org/c7-devtoolset-9.armhfp/devtoolset-9-binutils/20211015132728/2.32-16.el7.2.armhfp/devtoolset-9-binutils-2.32-16.el7.2.armv7hl.rpm https://buildlogs.centos.org/c7-devtoolset-9.armhfp/devtoolset-9-gcc/20211014113237/9.3.1-2.2.el7.armhfp/devtoolset-9-gcc-9.3.1-2.2.el7.armv7hl.rpm https://buildlogs.centos.org/c7-devtoolset-9.armhfp/devtoolset-9-gcc/20211014113237/9.3.1-2.2.el7.armhfp/devtoolset-9-gcc-c++-9.3.1-2.2.el7.armv7hl.rpm https://buildlogs.centos.org/c7-devtoolset-9.armhfp/devtoolset-9-gcc/20211014113237/9.3.1-2.2.el7.armhfp/devtoolset-9-libstdc++-devel-9.3.1-2.2.el7.armv7hl.rpm https://buildlogs.centos.org/c7-devtoolset-9.armhfp/devtoolset-9/20211013151212/9.1-1.el7.armhfp/devtoolset-9-runtime-9.1-1.el7.armv7hl.rpm scl-utils policycoreutils-python python3-pip python-IPy nettle-devel libidn-devel readline-devel cmake3
export PIHOLE_SKIP_OS_CHECK=true
touch /etc/lighttpd/external.conf
mkdir -p /etc/pihole ; /bin/cp -f /.setupVars /etc/pihole/setupVars.conf
echo v5.16.3 > /etc/pihole/ftlbranch ; export PIHOLE_SKIP_OS_CHECK=true
mkdir -p /etc/pihole
[[ ! -f /etc/pihole/setupVars.conf ]] && /bin/cp -f /.setupVars /etc/pihole/setupVars.conf
subnetmask=$(ip route list table main | tail -n1) ; subnetmask=$(cut -d "/" -f2 <<< "$subnetmask") ; subnetmask=$(cut -d " " -f1 <<< "$subnetmask")
device=$(ip route list table main | tail -n1 | cut -d' ' -f 3)
ipaddr=$(ip route list table main | tail -n1) ; ipaddr=`echo $ipaddr | awk -F' ' ' { print $(NF-0) } '`
clear ; echo Pi-hole for Android // Device: $device // IP: $ipaddr // SubNet: $subnetmask ; echo
printf "\nPi-hole for Android // Device: $device // IP: $ipaddr // SubNet: $subnetmask\n"
sed -i "/IPV4_ADDRESS/c\IPV4_ADDRESS=$ipaddr/$subnetmask" /etc/pihole/setupVars.conf
sed -i "/PIHOLE_INTERFACE/c\PIHOLE_INTERFACE=$device" /etc/pihole/setupVars.conf
curl -L https://install.pi-hole.net | bash /dev/stdin --unattended
python -c "print('\033[A\033[A\033[A\033[A')"
cd /tmp
rm -rf FTL ; git clone --depth=1 https://github.com/pi-hole/FTL.git
cd FTL

# Fixups
sed -i 's/cmake/cmake3/g' build.sh
sed -i '/BUS_MCEERR_AR/d' src/signals.c
sed -i '/BUS_MCEERR_AO/d' src/signals.c
sed -i 's/--dirty//g' src/gen_version.cmake

# Build pihole-FTL with updated CentOS 7 toolchain
echo ; echo "Building pihole-FTL from source. This will take a few minutes..."
scl enable devtoolset-9 ./build.sh >/etc/pihole/install.log 2>&1

# Install and Restart pihole-FTL
mkdir -p /var/log/pihole ; chown -R pihole:pihole /var/log/pihole
bash -c "service pihole-FTL stop ; pkill pihole-FTL ; /bin/cp pihole-FTL /usr/bin/pihole-FTL ; service pihole-FTL start ; service lighttpd restart ; pihole-FTL -v > /etc/pihole/ftlbranch" >>/etc/pihole/install.log 2>&1
echo ; pihole -v ; pihole status ; echo
curl -sSL https://raw.githubusercontent.com/DesktopECHO/pi-hole/master/automated%20install/basic-install.sh | bash /dev/stdin --unattended
5 changes: 4 additions & 1 deletion usr/local/bin/sysprep
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ rm -rf /root/.bash_history
rm -rf /var/log/*.log
rm -rf /var/tmp/*
rm -rf /var/log/pihole/*
rm -rf /var/log/*.gz
rm -rf /var/log/cron
rm -rf /var/log/kern
rm -rf /var/log/systemctl.log
rm -rf /var/log/lighttpd/*.log
rm -rf /var/log/messages /var/log/secure
rm -rf /etc/xrdp/*.pem /etc/xrdp/rsakeys.ini
rm -rf /var/cache/yum/armhfp/7/*
cd /home/android ; rm -rf .cache .pcsc* .ssh .vnc .rnd .pki .local .Xauthority .xsession* PADD.pid piHoleVersion thinclient_drives /tmp/* /tmp/.*
rpm -e unbound ; rpm -e unbound-libs ; rm -rf /etc/unbound ; rm -rf /var/lib/unbound /var/lib/unbound/root.key.rpmsave
rpm -e unbound ; rpm -e unbound-libs ; rm -rf /etc/unbound ; rm -rf /var/lib/unbound
clear
echo Turn off this instance and run image backup.
sleep 60

0 comments on commit 60a0605

Please sign in to comment.