最後活躍 1711441349

All servers should run regularly

修訂 b19614d4ef3790fdfb660ac1165b45740d0a8398

Upgrade.sh 原始檔案
1#!/bin/bash
2
3echo "Suppress Ubuntu ESM..."
4export DEBIAN_FRONTEND=noninteractive
5sudo pro config set apt_news=false
6sudo rm /var/lib/ubuntu-advantage/messages/*
7sudo rm /etc/apt/apt.conf.d/20apt-esm-hook.conf > /dev/null 2>&1
8
9echo "Checking default password..."
10username="anduin"
11password="Password@1234_Super"
12
13if echo "$password" | sudo -u anduin su - "$username" -c "true" > /dev/null 2>&1; then
14 echo "Current machine using default password!" | sudo tee -a /etc/motd
15 echo "Is default password. Should change!"
16fi
17
18echo "Setting timezone..."
19sudo timedatectl set-timezone UTC
20
21echo "Setting proxy..."
22echo 'Acquire::http { Proxy "http://proxy:3142"; }' | sudo tee /etc/apt/apt.conf.d/proxy
23
24#echo "Setting tmp..."
25#(sudo cat /etc/fstab | grep -q /tmp) || (echo "Mouting tmp..." && echo "tmpfs /tmp tmpfs rw,nosuid,nodev" | sudo tee -a /etc/fstab)
26
27echo "Detecting space issues..."
28CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g')
29THRESHOLD=60
30if [ "$CURRENT" -gt "$THRESHOLD" ] ; then
31 echo "Disk space alert! `date +"%Y-%m-%d %H:%M:%S"` Your root partition remaining free space is critically low. Used: $CURRENT%" | sudo tee -a /etc/motd
32fi
33
34echo "Setting hosts..."
35sudo cp /mnt/Shared/hosts /etc/
36cat /etc/hosts
37
38echo "Syncing time..."
39echo "server openwrt prefer iburst" | sudo tee "/etc/ntp.conf"
40sudo systemctl enable ntp
41ntpstat
42
43echo "Setting netplan..."
44sudo rm /etc/netplan/*
45sudo touch /etc/netplan/00-default-config.yaml
46HOSTNAME=$(hostname)
47IP_ADDRESS=$(awk -v host="$HOSTNAME" '$2 == host {print $1}' /etc/hosts)
48# If not found, crash the script:
49if [ -z "$IP_ADDRESS" ]; then
50 echo "IP address not found for $HOSTNAME"
51 exit 1
52fi
53echo "IP should be set to $IP_ADDRESS"
54sudo tee /etc/netplan/00-default-config.yaml > /dev/null << EOF
55network:
56 version: 2
57 renderer: NetworkManager
58 ethernets:
59 ens192:
60 addresses:
61 - $IP_ADDRESS/12
62 dhcp4: no
63EOF
64sudo systemctl mask systemd-networkd-wait-online.service
65sudo chown root:root /etc/netplan/00-default-config.yaml
66sudo chmod 600 /etc/netplan/00-default-config.yaml
67sudo netplan apply
68
69echo "Setting network..."
70#sudo systemctl restart NetworkManager
71sudo ip route list
72sudo ip route del default
73sudo ip route del default
74sudo ip route add default via 10.0.0.1 dev ens160 proto dhcp metric 100 # Green network
75sudo ip route add default via 10.64.0.1 dev ens192 proto dhcp metric 101 # Blue network
76
77echo "Removing snap..."
78sudo systemctl disable --now snapd
79sudo apt purge -y snapd
80sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd ~/snap
81cat << EOF | sudo tee -a /etc/apt/preferences.d/no-snap.pref
82Package: snapd
83Pin: release a=*
84Pin-Priority: -10
85EOF
86sudo chown root:root /etc/apt/preferences.d/no-snap.pref
87echo "Snap removed"
88
89echo "Removing prometheus..."
90sudo apt autoremove prometheus-node-exporter -y
91sudo rm /etc/systemd/system/multi-user.target.wants/prometheus-node-exporter.service > /dev/null 2>&1
92sudo rm /etc/systemd/system/multi-user.target.wants/smartmontools.service > /dev/null 2>&1
93sudo rm /etc/systemd/system/multi-user.target.wants/unattended-upgrades.service > /dev/null 2>&1
94
95echo "Removing 45drives..."
96sudo rm /etc/apt/sources.list.d/45drives.sources > /dev/null 2>&1
97sudo rm /usr/share/keyrings/45drives-archive-keyring.gpg > /dev/null 2>&1
98
99echo "Setting ufw..."
100sudo ufw allow 22
101
102echo "Updating packages..."
103sudo apt update
104
105echo "Installing monitoring..."
106curl -sL http://monitoring:48466/install.sh | sudo bash
107
108echo "Installing packages..."
109sleep 5
110sudo DEBIAN_FRONTEND=noninteractive apt install -y \
111 apt-transport-https \
112 ca-certificates \
113 curl \
114 lsb-release \
115 software-properties-common \
116 wget \
117 git \
118 jq \
119 zip \
120 unzip \
121 vim \
122 net-tools \
123 dnsutils \
124 nmap \
125 htop \
126 iotop \
127 iftop \
128 ntp \
129 ntpdate \
130 ntpstat \
131 open-vm-tools
132sleep 5
133sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y
134
135echo "Removing deprecated packages..."
136sleep 3
137sudo DEBIAN_FRONTEND=noninteractive apt autoremove unattended-upgrades -y
138sleep 3
139sudo DEBIAN_FRONTEND=noninteractive apt --purge autoremove -y
140sleep 3
141sudo DEBIAN_FRONTEND=noninteractive apt install --fix-broken -y
142sleep 3
143sudo DEBIAN_FRONTEND=noninteractive apt install --fix-missing -y
144sleep 3
145sudo DEBIAN_FRONTEND=noninteractive dpkg --configure -a
146sleep 3
147