Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set static IP if DHCP doesn't work #697

Merged
merged 16 commits into from
Nov 18, 2018
68 changes: 60 additions & 8 deletions nextcloud-startup-script.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,60 @@ SETDHCP
wait
check_command service network-manager restart
echo "Checking connection..."
sleep 3
sleep 1
if ! nslookup github.com
then
msg_box "Network NOT OK. You must have a working network connection to run this script
If you think that this is a bug, please report it to https://github.com/nextcloud/vm/issues."
exit 1
msg_box "The script failed to get an address from DHCP.
You must have a working network connection to run this script.

You will now be provided with the option to set a static IP manually instead."

# Copy old interfaces file
msg_box "Copying old netplan.io config file file to:
/tmp/01-netcfg.yaml_backup"
check_command cp -v /etc/netplan/01-netcfg.yaml /tmp/01-netcfg.yaml_backup

# Ask for IP address
cat << ENTERIP
+----------------------------------------------------------+
| Please enter the static IP address you want to set, |
| including the subnet. Example: 192.168.1.100/24 |
+----------------------------------------------------------+
ENTERIP
echo
read -r LANIP
echo

# Ask for gateway address
cat << ENTERGATEWAY
+----------------------------------------------------------+
| Please enter the gateway address you want to set, |
| Example: 192.168.1.1 |
+----------------------------------------------------------+
ENTERGATEWAY
echo
read -r GATEWAYIP
echo

# Create the Static IP file
cat <<-IPCONFIG > /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
$IFACE: #object name
dhcp4: no # dhcp v4 disable
dhcp6: no # dhcp v6 disable
addresses: [$LANIP] # client IP address
gateway4: $GATEWAYIP # gateway address
nameservers:
addresses: [9.9.9.9,149.112.112.112] #name servers
IPCONFIG

msg_box "These are your settings, please make sure they are correct:

$(cat /etc/netplan/01-netcfg.yaml)"
netplan try
fi
fi

Expand All @@ -109,8 +157,12 @@ if network_ok
then
printf "${Green}Online!${Color_Off}\n"
else
msg_box "Network NOT OK. You must have a working network connection to run this script
If you think that this is a bug, please report it to https://github.com/nextcloud/vm/issues."
msg_box "Network NOT OK. You must have a working network connection to run this script.

Please contact us for support:
https://shop.hanssonit.se/product/premium-support-per-30-minutes/

Please also post this issue on: https://github.com/nextcloud/vm/issues"
exit 1
fi

Expand Down Expand Up @@ -175,7 +227,7 @@ is_process_running dpkg

echo
echo "Getting scripts from GitHub to be able to run the first setup..."
# All the shell scripts in static (.sh)
# Scripts in static (.sh, .php, .py)
download_static_script temporary-fix
download_static_script update
download_static_script trusted
Expand Down Expand Up @@ -450,7 +502,7 @@ do

"Static IP")
clear
run_static_script set_static_ip
run_static_script static_ip
;;

*)
Expand Down
58 changes: 0 additions & 58 deletions static/ip.sh

This file was deleted.

58 changes: 0 additions & 58 deletions static/ip2.sh

This file was deleted.

67 changes: 0 additions & 67 deletions static/set_static_ip.sh

This file was deleted.

108 changes: 108 additions & 0 deletions static/static_ip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/bash

# T&M Hansson IT AB © - 2018, https://www.hanssonit.se/

# shellcheck disable=2034,2059
true
# shellcheck source=lib.sh
FIRST_IFACE=1 . <(curl -sL https://raw.githubusercontent.com/nextcloud/vm/master/lib.sh)
unset FIRST_IFACE

# Check for errors + debug code and abort if something isn't right
# 1 = ON
# 0 = OFF
DEBUG=0
debug_mode

clear

# Copy old interfaces file
msg_box "Copying old netplan.io config file file to:

/tmp/01-netcfg.yaml_backup"
check_command cp -v /etc/netplan/01-netcfg.yaml /tmp/01-netcfg.yaml_backup

echo
while true
do
# Ask for domain name
cat << ENTERIP
+-------------------------------------------------------------+
| Please enter the static IP address you want to set, |
| including the subnet. Like this: 192.168.1.100/24 |
+-------------------------------------------------------------+
ENTERIP
echo
read -r LANIP
echo
if [[ "yes" == $(ask_yes_or_no "Is this correct? $LANIP") ]]
then
break
fi
done

echo
while true
do
# Ask for domain name
cat << ENTERGATEWAY
+-------------------------------------------------------------+
| Please enter the gateway address you want to set, |
| Like this: 192.168.1.1 |
+-------------------------------------------------------------+
ENTERGATEWAY
echo
read -r GATEWAYIP
echo
if [[ "yes" == $(ask_yes_or_no "Is this correct? $GATEWAYIP") ]]
then
break
fi
done

# Check if IFACE is empty, if yes, try another method:
if ! [ -z "$IFACE" ]
then
cat <<-IPCONFIG > "$INTERFACES"
network:
version: 2
renderer: networkd
ethernets:
$IFACE: #object name
dhcp4: no # dhcp v4 disable
dhcp6: no # dhcp v6 disable
addresses: [$LANIP] # client IP address
gateway4: $GATEWAYIP # gateway address
nameservers:
addresses: [$DNS1,$DNS2] #name servers
IPCONFIG

msg_box "These are your settings, please make sure they are correct:

$(cat /etc/netplan/01-netcfg.yaml)"
netplan try
else
cat <<-IPCONFIGnonvmware > "$INTERFACES"
network:
version: 2
renderer: networkd
ethernets:
$IFACE2: #object name
dhcp4: no # dhcp v4 disable
dhcp6: no # dhcp v6 disable
addresses: [$ADDRESS/24] # client IP address
gateway4: $GATEWAY # gateway address
nameservers:
addresses: [$DNS1,$DNS2] #name servers
IPCONFIGnonvmware
msg_box "These are your settings, please make sure they are correct:

$(cat /etc/netplan/01-netcfg.yaml)"
netplan try
fi

if test_connection
then
sleep 1
msg_box "Static IP sucessfully set!"
fi