Filip Borum Poulsen 2 years ago
parent 5697acff83
commit aebf4de1a3

@ -38,26 +38,26 @@
#!/bin/bash #!/bin/bash
# Print the ip address of the raspberry pi # Print the ip address of the raspberry pi
current_ip=$(hostname -I | cut -d' ' -f1) current_ip=\$(hostname -I | cut -d' ' -f1)
# Print the ip address # Print the ip address
echo "The current ip address is $current_ip" echo "The current ip address is \$current_ip"
# Ask if they want to change the ip address # Ask if they want to change the ip address
echo -n "Do you want to change the ip address? (Y/n) " echo -n "Do you want to change the ip address? (Y/n) "
read change_ip read change_ip
# Exit if they don't want to change the ip address # Exit if they don't want to change the ip address
if [ "$change_ip" = "n" ]; then if [ "\$change_ip" = "n" ]; then
exit 0 exit 0
fi fi
# Ask if they want to use dhcp # Ask if they want to use dhcp
echo -n "Do you want to use dhcp? (y/N) " echo -n "Do you want to use dhcp? (y/N) "
read use_dhcp read use_dhcp
if [ "$use_dhcp" = "y" ]; then if [ "\$use_dhcp" = "y" ]; then
# Set the ip address to dhcp # Set the ip address to dhcp
sudo nmcli device modify eth0 ipv4.method auto sudo nmcli c modify "Wired connection 1" ipv4.method auto ipv4.addresses "" ipv4.gateway ""
# Restart the network # Restart the network
sudo nmcli c down "Wired connection 1" sudo nmcli c down "Wired connection 1"
@ -72,20 +72,20 @@
# Ask for the new subnet mask # Ask for the new subnet mask
echo -n "Enter the new CIDR subnet mask (press enter for default of 24) " echo -n "Enter the new CIDR subnet mask (press enter for default of 24) "
read subnet_mask read subnet_mask
if [ -z "$subnet_mask" ]; then if [ -z "\$subnet_mask" ]; then
subnet_mask="24" subnet_mask="24"
fi fi
# Ask for the new gateway # Ask for the new gateway
echo -n "Enter the new gateway (press enter for default of 192.168.25.1) " echo -n "Enter the new gateway (press enter for default of 192.168.25.1) "
read gateway read gateway
if [ -z "$gateway" ]; then if [ -z "\$gateway" ]; then
gateway="192.168.25.1" gateway="192.168.25.1"
fi fi
# Set the new ip address # Set the new ip address
sudo nmcli c mod "Wired connection 1" ipv4.addresses $new_ip/$subnet_mask ipv4.method manual sudo nmcli c mod "Wired connection 1" ipv4.addresses \$new_ip/\$subnet_mask ipv4.method manual
sudo nmcli c mod "Wired connection 1" ipv4.gateway $gateway sudo nmcli c mod "Wired connection 1" ipv4.gateway \$gateway
# Restart the network # Restart the network
sudo nmcli c down "Wired connection 1" sudo nmcli c down "Wired connection 1"
@ -104,6 +104,8 @@
```bash ```bash
sudo useradd ip --shell /ip.sh -p ip --create-home sudo useradd ip --shell /ip.sh -p ip --create-home
echo -e "ip\nip" | sudo passwd ip
```
1. Silence the login message 1. Silence the login message

Loading…
Cancel
Save