Files
onefinity-firmware/scripts/sethostname
OneFinityCNC 24dfa6c64d Verison 1.0.3 Release
Based on Buildbotics 0.4.14
2020-08-27 23:20:27 -04:00

27 lines
572 B
Bash

#!/bin/bash -e
HOSTNAME="$(echo "$1" | tr '[:upper:]' '[:lower:]')"
if [ "$HOSTNAME" == "" ]; then
echo "Usage: $0 <hostname>"
exit 1
fi
if [ "$HOSTNAME" == "localhost" ]; then
echo "Cannot set hostname to 'localhost'"
exit 1
fi
if [ "$HOSTNAME" =~ ^.*\.local$ ]; then
echo "Hostname cannot end with '.local'"
exit 1
fi
if [[ ! "$HOSTNAME" =~ ^[a-zA-Z][a-zA-Z0-9-]{0,62}$ ]]; then
echo "Invalid hostname '$HOSTNAME'"
exit 1
fi
sed -i "s/^127.0.1.1\([[:space:]]*\).*$/127.0.1.1\1$HOSTNAME/" /etc/hosts
echo "$HOSTNAME" > /etc/hostname