Skip to content

Commit

Permalink
fix usage with multiple ip addresses (ipv4/ipv6)
Browse files Browse the repository at this point in the history
use single call to get all information during installation
show and read out only first ip in webui
  • Loading branch information
AlvinSchiller committed Nov 14, 2023
1 parent 65e9547 commit f3b1c6f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 19 deletions.
3 changes: 1 addition & 2 deletions installation/includes/05_finish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

finish() {
local local_hostname=$(hostname)
local local_ip_address=$(hostname -I)
echo "####################### FINISHED ########################
Installation complete!
Expand All @@ -13,7 +12,7 @@ In order to start, you need to reboot your Raspberry Pi.
Your SSH connection will disconnect.
After the reboot, you can access the WebApp in your browser at
http://${local_hostname}.local or http://${local_ip_address}.
http://${local_hostname}.local or http://${CURRENT_IP_ADDRESS}.
Don't forget to upload files.
Do you want to reboot now? [Y/n]" 1>&3
Expand Down
13 changes: 10 additions & 3 deletions installation/routines/customize_options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@

_option_static_ip() {
# ENABLE_STATIC_IP
CURRENT_IP_ADDRESS=$(hostname -I)
# Using the dynamically assigned IP address as it is the best guess to be free
# Reference: https://unix.stackexchange.com/a/505385
CURRENT_ROUTE=$(ip route get 8.8.8.8)
CURRENT_INTERFACE=$(echo "${CURRENT_ROUTE}" | awk '{ print $3; exit }')
CURRENT_GATEWAY=$(echo "${CURRENT_ROUTE}" | awk '{ print $5; exit }')
CURRENT_IP_ADDRESS=$(echo "${CURRENT_ROUTE}" | awk '{ print $7; exit }')
clear 1>&3
echo "----------------------- STATIC IP -----------------------
Setting a static IP will save a lot of start up time.
The adress will be '${CURRENT_IP_ADDRESS}'.
The static adress will be '${CURRENT_IP_ADDRESS}'
from interface '${CURRENT_INTERFACE}'
with the gateway '${CURRENT_GATEWAY}'.
Set a static IP? [Y/n]" 1>&3
read -r response
Expand Down Expand Up @@ -265,8 +272,8 @@ Do you want to install Node? [Y/n]" 1>&3
customize_options() {
echo "Customize Options starts"

_option_static_ip
_option_ipv6
_option_static_ip
_option_autohotspot
_option_bluetooth
_option_disable_onboard_audio
Expand Down
19 changes: 5 additions & 14 deletions installation/routines/optimize_boot_time.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,26 +40,17 @@ _optimize_handle_network_connection() {
echo " Skipping. Already set up!" | tee /dev/fd/3
else
# DHCP has not been configured
# Reference: https://unix.stackexchange.com/a/307790/478030
INTERFACE=$(route | grep '^default' | grep -o '[^ ]*$')

# Reference: https://serverfault.com/a/31179/431930
GATEWAY=$(route -n | grep 'UG[ \t]' | awk '{print $2}')

# Using the dynamically assigned IP address as it is the best guess to be free
# Reference: https://unix.stackexchange.com/a/48254/478030
CURRENT_IP_ADDRESS=$(hostname -I)
echo " * ${INTERFACE} is the default network interface" | tee /dev/fd/3
echo " * ${GATEWAY} is the Router Gateway address" | tee /dev/fd/3
echo " * ${CURRENT_INTERFACE} is the default network interface" | tee /dev/fd/3
echo " * ${CURRENT_GATEWAY} is the Router Gateway address" | tee /dev/fd/3
echo " * Using ${CURRENT_IP_ADDRESS} as the static IP for now" | tee /dev/fd/3

sudo tee -a $DHCP_CONF <<-EOF
## Jukebox DHCP Config
interface ${INTERFACE}
interface ${CURRENT_INTERFACE}
static ip_address=${CURRENT_IP_ADDRESS}/24
static routers=${GATEWAY}
static domain_name_servers=${GATEWAY}
static routers=${CURRENT_GATEWAY}
static domain_name_servers=${CURRENT_GATEWAY}
EOF

Expand Down
3 changes: 3 additions & 0 deletions src/jukebox/components/hostif/linux/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ def get_ip_address():
ip_address = p.stdout.strip().decode()
else:
ip_address = '127.0.0.1'

# only get first if multiple adresses are present (ipv4/ipv6)
ip_address = ip_address.split(' ')[0]
return ip_address


Expand Down

0 comments on commit f3b1c6f

Please sign in to comment.