Teste
Teste
/bin/bash
# FIND DETAILS
details=$(cat /etc/os-release)
# FIND DIST
dist=$(echo "$details" | grep ^ID= | grep -Eo [a-z]+)
# FIND VERSION
version=$(echo "$details" | grep ^VERSION= | grep -Eo [0-9]+ | head -n 1)
# FIND NAME
name=$(ls /sys/class/net | head -n 1)
# NETMASK SCRIPT
cat <<EOF > /etc/cidr.py
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('netmask')
args = parser.parse_args()
cidr = 0
bits = bin(int(bits)).count('1')
print(cidr)
EOF
# UBUNTU
function ubuntuIP {
# START
ifup $name
# UBUNTU
function ubuntuIPWithRoute {
# START
ifup $name
# DEBIAN
function debianIP {
# START
ifup $name
# DEBIAN
function debianIPWithRoute {
# START
ifup $name
}
# CENTOS
function centosIP {
# START
ifup $name
# NETMASK TO CIDR
if which python3; then
# NETPLAN
function netplanIP {
# START
netplan apply
# NETPLAN
function netplanIPWithRoute {
# START
netplan apply
# NETPLAN
if [ -d /etc/netplan ]; then
if [ $cidr == 32 ]; then
netplanIPWithRoute
else
netplanIP
fi
else
# UBUNTU
if [ "$dist" == ubuntu ]; then
if [ $cidr == 32 ]; then
ubuntuIPWithRoute
else
ubuntuIP
fi
fi
# DEBIAN
if [ "$dist" == debian ]; then
if [ $version == 8 ]; then
if [ $cidr == 32 ]; then
debianIPWithRoute
else
debianIP
fi
else
debianIP
fi
fi
# CENTOS
if [ "$dist" == centos ]; then
centosIP
fi
# ALMA
if [ "$dist" == almalinux ]; then
centosIP
fi
# ROCKY
if [ "$dist" == rocky ]; then
centosIP
fi
fi
# RESIZE PARTITION
(echo d; echo n; echo p; echo ; echo ; echo ; echo w; echo n; echo w) | fdisk
/dev/sda
# RESIZE FILESYSTEM
partprobe && resize2fs /dev/sda1
# LOGIN BY PASSWORD
(echo @password; echo @password) | passwd @username
# LOGIN BY RSA
if [ ! -z "@publicKey" ]; then
# DELETE FILE
rm /home/setup.sh