#!/bin/sh

# 禁用内核更新
sudo apt-mark hold linux-generic linux-image-generic linux-headers-generic
# 锁定内核
sudo apt-mark hold linux-generic linux-image-generic linux-headers-generic
sudo apt-mark hold linux-image-generic linux-headers-generic

sudo apt update

# 禁用内核更新
sudo apt-mark hold linux-generic linux-image-generic linux-headers-generic
# 锁定内核
sudo apt-mark hold linux-generic linux-image-generic linux-headers-generic
sudo apt-mark hold linux-image-generic linux-headers-generic

sudo timedatectl set-timezone Asia/Shanghai
sudo cat /etc/timezone

# sudo mkdir -p /root/snap/chromium/common/chromium/BrowserMetrics

sudo apt install language-pack-zh-hans -y
sudo locale-gen zh_CN.UTF-8
sudo update-locale LANG=zh_CN.UTF-8

export LANG=zh_CN.UTF-8

sudo apt-get install vim -y && sudo apt-get remove nano -y
sudo apt install fonts-wqy-zenhei fonts-wqy-microhei fonts-noto-cjk -y
sudo apt install -y fontconfig
sudo apt install -y fonts-dejavu-core fonts-liberation

sudo apt install fonts-wqy-zenhei fonts-wqy-microhei fonts-noto-cjk -y
sudo apt install -y git
sudo apt install net-tools -y
sudo apt install openssh-server -y
sudo apt install -y fontconfig
sudo apt install -y fonts-dejavu-core fonts-liberation

# 禁用自动更新
sudo sed -i 's/APT::Periodic::Update-Package-Lists "1";/APT::Periodic::Update-Package-Lists "0";/g' /etc/apt/apt.conf.d/10periodic
sudo sed -i 's/APT::Periodic::Unattended-Upgrade "1";/APT::Periodic::Unattended-Upgrade "0";/g' /etc/apt/apt.conf.d/10periodic

# 禁用无人值守升级
sudo sed -i 's/APT::Periodic::Update-Package-Lists "1";/APT::Periodic::Update-Package-Lists "0";/g' /etc/apt/apt.conf.d/20auto-upgrades
sudo sed -i 's/APT::Periodic::Unattended-Upgrade "1";/APT::Periodic::Unattended-Upgrade "0";/g' /etc/apt/apt.conf.d/20auto-upgrades

# 禁用 apt-daily 服务和计时器
sudo systemctl stop apt-daily.service
sudo systemctl disable apt-daily.service
sudo systemctl mask apt-daily.service
sudo systemctl daemon-reload
sudo systemctl stop apt-daily.timer
sudo systemctl disable apt-daily.timer
sudo systemctl mask apt-daily.timer
sudo systemctl daemon-reload

# 禁用 unattended-upgrades 服务
sudo systemctl disable unattended-upgrades

# 禁用 Snap 自动更新
sudo snap refresh --hold

# 禁用自动更新
sudo systemctl stop apt-daily.service
sudo systemctl disable apt-daily.service
sudo systemctl kill --kill-who=main apt-daily.service
sudo systemctl disable apt-daily.timer
sudo systemctl mask apt-daily.timer
sudo systemctl stop unattended-upgrades.service
sudo systemctl disable unattended-upgrades.service

sudo systemctl daemon-reload

# Ubuntu自动登录和开机锁屏取消
## 禁用自动锁屏：
# gsettings set org.gnome.desktop.screensaver lock-enabled false
# gsettings set org.gnome.desktop.lockdown disable-lock-screen true

# 禁用内核更新
sudo apt-mark hold linux-generic linux-image-generic linux-headers-generic
# 恢复内核更新
sudo apt-mark unhold linux-generic linux-image-generic linux-headers-generic

sudo sed -i 's/1/0/' /etc/apt/apt.conf.d/10periodic
sudo sed -i 's/2/0/' /etc/apt/apt.conf.d/10periodic

sudo sed -i 's/1/0/' /etc/apt/apt.conf.d/20auto-upgrades
sudo sed -i 's/2/0/' /etc/apt/apt.conf.d/20auto-upgrades

sudo apt remove update-notifier -y

# 禁用屏幕休眠
# gsettings set org.gnome.desktop.session idle-delay 0

sudo mkdir -p /home/ubuntu/.ssh

sudo touch /home/ubuntu/.ssh/authorized_keys


# Linux优化-Ulimit
# 写入文件内容

sudo bash -c 'cat <<EOF > /etc/security/limits.conf
* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535
EOF'

# >> 表示 追加 到文件末尾，不会破坏原有内容
sudo bash -c 'cat <<EOF > /etc/systemd/system.conf
[Manager]
DefaultLimitNOFILE=1048576
EOF'

# >> 表示 追加 到文件末尾，不会破坏原有内容
sudo bash -c 'cat <<EOF > /etc/sysctl.conf
net.ipv4.ip_forward = 1
fs.file-max = 1048576
fs.inotify.max_user_instances=512
fs.inotify.max_user_watches=262144
EOF'

# 安装chrome谷歌浏览器
sudo apt update

# 谷歌浏览器取消登录密钥环**然后重启系统，首次打开 Chrome 时会提示创建新密钥环，直接留空密码并继续即可
rm -rf /home/ubuntu/.local/share/keyrings/*
sudo rm -rf /home/ubuntu/.local/share/keyrings/*

# 调整电视连接显示配置
sudo sed -i 's/#HandleLidSwitch=suspend/HandleLidSwitch=ignore/g' /etc/systemd/logind.conf

sudo apt autoremove -y

# 配置密钥允许
sudo bash -c 'cat <<EOF >> /home/ubuntu/.ssh/authorized_keys

ssh-rsa [payload removed: 544 characters] Administrator@DESKTOP-12ALS0Q
ssh-rsa [payload removed: 544 characters] root@sop

EOF'

#
sudo apt autoremove -y
# sudo reboot
# sudo systemctl restart systemd-logind
