1
0
ubuntu.22.04/1-install.sh

106 lines
3.5 KiB
Bash

#!/usr/bin/sh
# wget https://git.kosenka.ru/kosenka/ubuntu.22.04/raw/branch/master/install.sh
ColorRed='\033[0;31m'
ColorGreen='\033[0;32m'
ColorOff='\033[0m'
# Function to display the confirmation prompt
function confirm() {
while true; do
read -p "$1? (y/n) " yn
case $yn in
[Yy]* ) return 0;;
[Nn]* ) return 1;;
esac
done
}
clear
# check if running as root in a bash script
# https://stackoverflow.com/a/28776100
if [ `id -u` -ne 0 ]
then echo Please run this script as root or using sudo!
exit
fi
echo -e "${ColorGreen}Введите IP-адрес сервера (пример: 192.168.1.1/24):${ColorOff}"
read server_ip
echo -e "${ColorGreen}Введите IP-адреса для nameserver's (пример: 192.168.1.1, 192.168.1.2):${ColorOff}"
read nameserver_ip
echo -e "${ColorGreen}Введите IP-адреса для gateway сервера (пример: 192.168.0.1):${ColorOff}"
read gatewayserver_ip
ip -o link show | awk '{print $2,$9}'
echo -e "${ColorGreen}Введите имя сеетвого устройства (пример: enp6s19):${ColorOff}"
read netdevice
apt-get -y update && apt-get -y upgrade
### https://dondub.com/2021/07/udalenie-cloud-init-iz-ubuntu-server-21-04/
sed -i -e 's/datasource_list:/# datasource_list:/g' /etc/cloud/cloud.cfg.d/90_dpkg.cfg
echo "datasource_list: [ None ]" >> /etc/cloud/cloud.cfg.d/90_dpkg.cfg
dpkg-reconfigure cloud-init
apt purge -y cloud-init && rm -rf /etc/cloud/ && rm -rf /var/lib/cloud/
apt-get -y remove unattended-upgrades
systemctl stop apt-daily.timer
systemctl disable apt-daily.timer
systemctl stop apt-daily-upgrade.timer
systemctl disable apt-daily-upgrade.timer
systemctl disable apt-daily.service
systemctl daemon-reload
sed -i -e 's/APT::Periodic::Update-Package-Lists "1";/APT::Periodic::Update-Package-Lists "0";/g' /etc/apt/apt.conf.d/20auto-upgrades
sed -i -e 's/APT::Periodic::Unattended-Upgrade "1";/APT::Periodic::Unattended-Upgrade "0";/g' /etc/apt/apt.conf.d/20auto-upgrades
snap remove --purge snapd && apt-get -y remove snapd && apt-get -y autoremove
apt install -y netplan.io isc-dhcp-client isc-dhcp-common mc net-tools iputils-ping inetutils-traceroute htop ca-certificates
apt install -y apt-utils aptitude locales git squashfs-tools tzdata fdisk gdisk mc net-tools iputils-ping inetutils-traceroute iproute2
### ? systemctl disable snapd.service && systemctl disable snapd.socket && systemctl disable snapd.seeded.service && systemctl mask snapd.service && rm -rf /var/cache/snapd/ && apt autoremove --purge snapd -y && rm -rf ~/snap
timedatectl set-timezone Europe/Moscow
apt -y install ntp
aptitude install console-cyrillic
update-locale LANG=ru_RU.UTF-8
sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen
sed -i -e 's/# ru_RU.UTF-8 UTF-8/ru_RU.UTF-8 UTF-8/' /etc/locale.gen
dpkg-reconfigure --frontend=noninteractive locales
localectl set-locale LANG=ru_RU.UTF-8
export LANG=ru_RU.UTF-8
rm /etc/netplan/50-cloud-init.yaml
touch /etc/netplan/10-netplan-config.yaml
echo "# This is the network config written by 'subiquity'
network:
version: 2
ethernets:
$netdevice:
dhcp4: no
addresses:
- $server_ip
nameservers:
addresses: [$nameserver_ip]
routes:
- to: default
via: $gatewayserver_ip
" >> /etc/netplan/10-netplan-config.yaml
chmod 600 /etc/netplan/10-netplan-config.yaml
netplan try
netplan apply
systemctl restart systemd-networkd
if confirm "Перезагружаемся "; then
shutdown -r now
fi