Browse Source

set public_IP to local_ip if no PublicIP found on startup

dev
openoms 6 years ago
parent
commit
8b23baea8a
  1. 3
      dietpi/README.md
  2. 8
      home.admin/_bootstrap.sh
  3. 2
      home.admin/assets/bootstrap.service

3
dietpi/README.md

@ -158,3 +158,6 @@ Allows you to automatically execute a custom script at the end of DietPi install
Option 1 = Copy your script to /boot/Automation_Custom_Script.sh and it will be executed automatically.
Option 2 = Host your script online, then use AUTO_SETUP_CUSTOM_SCRIPT_EXEC=http://myweb.com/myscript.sh, it will be downloaded and executed automatically. | 0=disabled
NB: Executed script log /var/tmp/dietpi/logs/dietpi-automation_custom_script.log
### Guide to clone your SD-cards and shrink the image in linux:
https://beebom.com/how-clone-raspberry-pi-sd-card-windows-linux-macos/

8
home.admin/_bootstrap.sh

@ -283,16 +283,16 @@ if [ ${configExists} -eq 1 ]; then
source ${configFile}
# update public IP on boot
# wait otherwise looking for publicIP fails
sleep 5
freshPublicIP=$(curl -s http://v4.ipv6-test.com/api/myip.php)
if [ ${#freshPublicIP} -eq 0 ]; then
echo "WARNING: Was not able to determine external IP on startup." >> $logFile
echo "WARNING: Was not able to determine external IP on startup. Setting publicIP to local_ip" >> $logFile
local_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
sed -i "s/^publicIP=.*/publicIP=${local_ip}/g" ${configFile}
else
publicIPValueExists=$( sudo cat ${configFile} | grep -c 'publicIP=' )
if [ ${publicIPValueExists} -gt 1 ]; then
# remove one
echo "more then one publiIp entry - removing one" >> $logFile
echo "more then one publicIp entry - removing one" >> $logFile
sed -i "s/^publicIP=.*//g" ${configFile}
publicIPValueExists=$( sudo cat ${configFile} | grep -c 'publicIP=' )
fi

2
home.admin/assets/bootstrap.service

@ -8,7 +8,7 @@ After=network.target
[Service]
User=root
Group=root
Type=simple
Type=oneshot
RemainAfterExit=true
ExecStart=/home/admin/_bootstrap.sh
StandardOutput=journal

Loading…
Cancel
Save