Skip to content

Instantly share code, notes, and snippets.

@kagesenshi
Last active April 21, 2024 03:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kagesenshi/bbfd1a45a6053b4fe383b87ada291460 to your computer and use it in GitHub Desktop.
Save kagesenshi/bbfd1a45a6053b4fe383b87ada291460 to your computer and use it in GitHub Desktop.
Node initializer
#!/bin/bash
PARSED=$(getopt -a -n setup-node -o :n:i: --long name:,ip: -- "$@")
VALID_ARGS=$?
GATEWAY=10.210.14.1
DNS=10.210.14.2
HOSTSUFFIX=home.kagesenshi.org
usage() {
echo "Usage: $0 -n [NAME] -i [IP]"
exit 1
}
if [ "$VALID_ARGS" != "0" ];then
usage
fi
eval set -- "$PARSED"
while :
do
case "$1" in
-n | --name) NAME="$2"; shift 2 ;;
-i | --ip) IP="$2"; shift 2 ;;
--) shift; break;;
*) echo "Invalid option $1"; usage;;
esac
done
if [ "x$NAME" == "x" ];then
usage
fi
if [ "x$IP" == "x" ];then
usage
fi
set -x
nmcli con mod enp1s0 ipv4.addresses ${IP}/24
nmcli con mod enp1s0 ipv4.gateway ${GATEWAY}
nmcli con mod enp1s0 ipv4.dns ${DNS}
nmcli con mod enp1s0 ipv4.method manual
nmcli con mod enp1s0 ipv4.dns-options ndots:1
cat << EOF > /etc/NetworkManager/conf.d/99-dns-none.conf
[main]
dns=none
rc-manager=unmanaged
EOF
cat << EOF > /etc/resolv.conf
nameserver ${DNS}
EOF
ENDIP=`echo ${IP}|cut -d'.' -f4`
echo ${NAME}.${ENDIP}.${HOSTSUFFIX} > /etc/hostname
systemctl restart NetworkManager
nmcli con up enp1s0
hostname `cat /etc/hostname`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment