Last active
April 21, 2024 03:30
-
-
Save kagesenshi/bbfd1a45a6053b4fe383b87ada291460 to your computer and use it in GitHub Desktop.
Node initializer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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