anduin revised this gist . Go to revision
1 file changed, 6 deletions
Upgrade.sh
@@ -18,12 +18,6 @@ fi | |||
18 | 18 | echo "Setting timezone..." | |
19 | 19 | sudo timedatectl set-timezone UTC | |
20 | 20 | ||
21 | - | echo "Setting proxy..." | |
22 | - | echo '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 | - | ||
27 | 21 | echo "Detecting space issues..." | |
28 | 22 | CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') | |
29 | 23 | THRESHOLD=60 |
anduin revised this gist . Go to revision
1 file changed, 146 insertions
Upgrade.sh(file created)
@@ -0,0 +1,146 @@ | |||
1 | + | #!/bin/bash | |
2 | + | ||
3 | + | echo "Suppress Ubuntu ESM..." | |
4 | + | export DEBIAN_FRONTEND=noninteractive | |
5 | + | sudo pro config set apt_news=false | |
6 | + | sudo rm /var/lib/ubuntu-advantage/messages/* | |
7 | + | sudo rm /etc/apt/apt.conf.d/20apt-esm-hook.conf > /dev/null 2>&1 | |
8 | + | ||
9 | + | echo "Checking default password..." | |
10 | + | username="anduin" | |
11 | + | password="Password@1234_Super" | |
12 | + | ||
13 | + | if 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!" | |
16 | + | fi | |
17 | + | ||
18 | + | echo "Setting timezone..." | |
19 | + | sudo timedatectl set-timezone UTC | |
20 | + | ||
21 | + | echo "Setting proxy..." | |
22 | + | echo '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 | + | ||
27 | + | echo "Detecting space issues..." | |
28 | + | CURRENT=$(df / | grep / | awk '{ print $5}' | sed 's/%//g') | |
29 | + | THRESHOLD=60 | |
30 | + | if [ "$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 | |
32 | + | fi | |
33 | + | ||
34 | + | echo "Setting hosts..." | |
35 | + | sudo cp /mnt/Shared/hosts /etc/ | |
36 | + | cat /etc/hosts | |
37 | + | ||
38 | + | echo "Syncing time..." | |
39 | + | echo "server openwrt prefer iburst" | sudo tee "/etc/ntp.conf" | |
40 | + | sudo systemctl enable ntp | |
41 | + | ntpstat | |
42 | + | ||
43 | + | echo "Setting netplan..." | |
44 | + | sudo rm /etc/netplan/* | |
45 | + | sudo touch /etc/netplan/00-default-config.yaml | |
46 | + | HOSTNAME=$(hostname) | |
47 | + | IP_ADDRESS=$(awk -v host="$HOSTNAME" '$2 == host {print $1}' /etc/hosts) | |
48 | + | # If not found, crash the script: | |
49 | + | if [ -z "$IP_ADDRESS" ]; then | |
50 | + | echo "IP address not found for $HOSTNAME" | |
51 | + | exit 1 | |
52 | + | fi | |
53 | + | echo "IP should be set to $IP_ADDRESS" | |
54 | + | sudo tee /etc/netplan/00-default-config.yaml > /dev/null << EOF | |
55 | + | network: | |
56 | + | version: 2 | |
57 | + | renderer: NetworkManager | |
58 | + | ethernets: | |
59 | + | ens192: | |
60 | + | addresses: | |
61 | + | - $IP_ADDRESS/12 | |
62 | + | dhcp4: no | |
63 | + | EOF | |
64 | + | sudo systemctl mask systemd-networkd-wait-online.service | |
65 | + | sudo chown root:root /etc/netplan/00-default-config.yaml | |
66 | + | sudo chmod 600 /etc/netplan/00-default-config.yaml | |
67 | + | sudo netplan apply | |
68 | + | ||
69 | + | echo "Setting network..." | |
70 | + | #sudo systemctl restart NetworkManager | |
71 | + | sudo ip route list | |
72 | + | sudo ip route del default | |
73 | + | sudo ip route del default | |
74 | + | sudo ip route add default via 10.0.0.1 dev ens160 proto dhcp metric 100 # Green network | |
75 | + | sudo ip route add default via 10.64.0.1 dev ens192 proto dhcp metric 101 # Blue network | |
76 | + | ||
77 | + | echo "Removing snap..." | |
78 | + | sudo systemctl disable --now snapd | |
79 | + | sudo apt purge -y snapd | |
80 | + | sudo rm -rf /snap /var/snap /var/lib/snapd /var/cache/snapd /usr/lib/snapd ~/snap | |
81 | + | cat << EOF | sudo tee -a /etc/apt/preferences.d/no-snap.pref | |
82 | + | Package: snapd | |
83 | + | Pin: release a=* | |
84 | + | Pin-Priority: -10 | |
85 | + | EOF | |
86 | + | sudo chown root:root /etc/apt/preferences.d/no-snap.pref | |
87 | + | echo "Snap removed" | |
88 | + | ||
89 | + | echo "Removing prometheus..." | |
90 | + | sudo apt autoremove prometheus-node-exporter -y | |
91 | + | sudo rm /etc/systemd/system/multi-user.target.wants/prometheus-node-exporter.service > /dev/null 2>&1 | |
92 | + | sudo rm /etc/systemd/system/multi-user.target.wants/smartmontools.service > /dev/null 2>&1 | |
93 | + | sudo rm /etc/systemd/system/multi-user.target.wants/unattended-upgrades.service > /dev/null 2>&1 | |
94 | + | ||
95 | + | echo "Removing 45drives..." | |
96 | + | sudo rm /etc/apt/sources.list.d/45drives.sources > /dev/null 2>&1 | |
97 | + | sudo rm /usr/share/keyrings/45drives-archive-keyring.gpg > /dev/null 2>&1 | |
98 | + | ||
99 | + | echo "Setting ufw..." | |
100 | + | sudo ufw allow 22 | |
101 | + | ||
102 | + | echo "Updating packages..." | |
103 | + | sudo apt update | |
104 | + | ||
105 | + | echo "Installing monitoring..." | |
106 | + | curl -sL http://monitoring:48466/install.sh | sudo bash | |
107 | + | ||
108 | + | echo "Installing packages..." | |
109 | + | sleep 5 | |
110 | + | sudo 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 | |
132 | + | sleep 5 | |
133 | + | sudo DEBIAN_FRONTEND=noninteractive apt upgrade -y | |
134 | + | ||
135 | + | echo "Removing deprecated packages..." | |
136 | + | sleep 3 | |
137 | + | sudo DEBIAN_FRONTEND=noninteractive apt autoremove unattended-upgrades -y | |
138 | + | sleep 3 | |
139 | + | sudo DEBIAN_FRONTEND=noninteractive apt --purge autoremove -y | |
140 | + | sleep 3 | |
141 | + | sudo DEBIAN_FRONTEND=noninteractive apt install --fix-broken -y | |
142 | + | sleep 3 | |
143 | + | sudo DEBIAN_FRONTEND=noninteractive apt install --fix-missing -y | |
144 | + | sleep 3 | |
145 | + | sudo DEBIAN_FRONTEND=noninteractive dpkg --configure -a | |
146 | + | sleep 3 |