set public_IP to local_ip if no PublicIP found on startup

This commit is contained in:
openoms
2019-02-12 14:57:50 +00:00
parent f0b8f46e5c
commit 8b23baea8a
3 changed files with 8 additions and 5 deletions

View File

@@ -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/

View File

@@ -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

View File

@@ -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