-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpiNet.sh
More file actions
30 lines (25 loc) · 767 Bytes
/
piNet.sh
File metadata and controls
30 lines (25 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
#Bash script to rename a Raspberry pi Hostname, and install avahi/bonjour
#Use at own risk
#Read current hostname
oldHostname=$(hostname)
echo "Current hostname: "$oldHostname
#Enter new hostname
echo "Please enter new host name:"
read hostName
if [ -z "${hostName}" ]; then
echo "Host name cannot be blank"
echo "Please enter new host name:"
read hostName
fi
#Install avahi
sudo apt-get update
sudo apt-get install --assume-yes avahi-daemon
#Permanantly change hostname from current hostname
string='s/'$oldHostname'/'$hostName'/g'
sudo sed -i $string /etc/hostname
sudo sed -i $string /etc/hosts
sudo /etc/init.d/hostname.sh
hostname
echo "Please reboot"
# sudo reboot #Uncomment this if you want to automatically reboot when done