Created
August 15, 2019 17:54
-
-
Save ramcoelho/7496c8f9311b6a7aba9e5f5a0f33929e to your computer and use it in GitHub Desktop.
Template pods
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 | |
export TERM=xterm-256color | |
echo -ne "\n$(tput setaf 3;tput setab 0;tput bold)\n\n" | |
echo -ne " Este servidor foi criado com base em um modelo.\n" | |
echo -ne " Para alterar o nome e o IP, utilize o script $(tput setaf 7)reconfigure$(tput setaf 3). \n" | |
echo -ne "$(tput sgr0)\n\n" |
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 | |
me=$(/usr/bin/basename $0) | |
if [ 0 -ne $(/usr/bin/id -u) ]; then | |
/bin/echo "Sem poderes de super-vaca" | |
exit 1 | |
fi | |
if [ 2 -gt $# ]; then | |
/bin/echo "Uso: $me <hostname> <ip/maskbits> [<gw> [<dns1,dns2,dns3>]]" | |
/bin/echo | |
/bin/echo "Ex.: $me servidor 10.0.7.2/24 10.0.7.1 172.20.2.212,172.20.2.8" | |
/bin/echo | |
/bin/echo "Se omitidos, gw = 10.0.7.1 e dns = 172.20.2.212,172.20.2.8" | |
/bin/echo | |
exit 1 | |
fi | |
nhostname=$1 | |
ipmask=$2 | |
gw='10.0.7.1' | |
dns='172.20.2.212,172.20.2.8' | |
if [ 3 -le $# ]; then | |
gw=$3 | |
fi | |
if [ 4 -le $# ]; then | |
dns=$4 | |
fi | |
echo "Alterando hostname para $nhostname" | |
/bin/sed -i "s/template/$nhostname/g" /etc/hostname | |
/bin/sed -i "s/template/$nhostname/g" /etc/hosts | |
/bin/hostname $nhostname | |
/bin/echo "Alterando configuração de rede para $ipmask, gateway $gw e DNS $dns" | |
/bin/echo "# This file describes the network interfaces available on your system | |
# For more information, see netplan(5). | |
network: | |
version: 2 | |
renderer: networkd | |
ethernets: | |
ens160: | |
dhcp4: no | |
addresses: [$ipmask] | |
gateway4: $gw | |
nameservers: | |
addresses: [$dns] | |
" > /etc/netplan/01-netcfg.yaml | |
/bin/echo "Para aplicar, use: netplan apply." | |
/bin/echo " Se seu IP foi alterado, este terminal pode ser desconectado." | |
/bin/chmod a-x /etc/update-motd.d/99-reconfigure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment