#!/bin/bash # >/dev/null 2>&1 不显示输出 echo -en '----------\n' echo '设置 变量' echo -en '----------\n' Variable () { su="sudo" download="aria2c -c -x 16 -s 999 --file-allocation=none" deepin="https://mirrors.tuna.tsinghua.edu.cn/deepin/beige/pool/main/l/" old_image="$(dpkg --get-selections | grep "linux-image.*amd64-desktop" | head -n -1 | sed -e "s/\tinstall//g")" old_headers="$(dpkg --get-selections | grep "linux-headers.*amd64-desktop" | head -n -1 | sed -e "s/\tinstall//g")" old_linux="$(dpkg --get-selections | grep "linux-image.*amd64-desktop" | sort -ru | head -n 1 | sed -e "s/\tinstall//g")" new_firmware="$(curl -L ${deepin}linux-firmware/ | grep "linux-firmware.*amd64.*" | cut -f4 -d ">" | cut -f1 -d "<")" new_image="$(curl -L ${deepin}linux-upstream/ | grep "linux-image.*amd64-desktop-hwe" | cut -f4 -d ">" | cut -f1 -d "<" | sort -ru | head -n 1)" new_headers="$(curl -L ${deepin}linux-upstream/ | grep "linux-headers.*amd64-desktop-hwe" | cut -f4 -d ">" | cut -f1 -d "<" | sort -ru | head -n 1)" } Variable 2> /dev/null if [ ${old_linux} = ${new_image//hwe*/hwe} ]; then echo '卸载 旧内核' ${su} apt autoremove --purge --yes ${old_image} ${old_headers} && ${su} update-grub && ${su} update-grub2 else echo '系统 设置' Setting () { gsettings set com.deepin.dde.mouse disable-touchpad true ## 插入鼠标 触控板 禁用 ## gsettings set com.deepin.dde.dock.module.keyboard enable false ## 任务栏 cn按钮 关闭 ## gsettings set com.deepin.dde.power battery-lock-delay 900 ## 使用电池 自动锁屏 15分钟 ## gsettings set com.deepin.dde.power battery-sleep-delay 1800 ## 使用电池 进入待机模式 30分钟 ## gsettings set com.deepin.dde.power battery-screen-black-delay 600 ## 使用电池 关闭显示器 10分钟 ## gsettings set com.deepin.dde.power battery-press-power-button 'shutdown' ## 使用电池 按电源按钮时 关机 ## gsettings set com.deepin.dde.power battery-lid-closed-action 'turnOffScreen' ## 使用电池 笔记本合盖时 关闭屏幕 ## gsettings set com.deepin.dde.power line-power-lock-delay 1800 ## 连接电源 自动锁屏 30分钟 ## gsettings set com.deepin.dde.power line-power-sleep-delay 0 ## 连接电源 进入待机模式 永不 ## gsettings set com.deepin.dde.power line-power-screen-black-delay 600 ## 连接电源 关闭显示器 10分钟 ## gsettings set com.deepin.dde.power line-power-press-power-button 'shutdown' ## 连接电源 按电源按钮时 关机 ## gsettings set com.deepin.dde.power line-power-lid-closed-action 'turnOffScreen' ## 使用电源 笔记本合盖时 关闭屏幕 ## busctl call com.deepin.lastore /com/deepin/lastore com.deepin.lastore.Updater SetUpdateNotify b 0 ## 更新提醒 关闭 ## busctl call com.deepin.lastore /com/deepin/lastore com.deepin.lastore.Updater SetAutoCheckUpdates b 0 ## 更新检查 关闭 ## busctl call com.deepin.lastore /com/deepin/lastore com.deepin.lastore.Updater SetAutoDownloadUpdates b 0 ## 更新下载 关闭 ## } Setting echo -en '----------\n' echo '卸载 应用列表如下:' echo -en '----------\n' echo '帮助手册、画板、启动盘制作工具、日志收集工具、深度之家、文档查看器、用户反馈、邮箱、语音记事本、欢迎、连连看、LibreOffice、LibreOffice Base、LibreOffice Calc、LibreOffice Draw、LibreOffice Impress、LibreOffice Math、LibreOffice Writer、浏览器、五子棋、下载器、Deepin Union Code、社区、Laptop Mode Tools Configuration、磁盘管理器、打印管理器、计算器、截图录屏、看图、扫描易、设备管理器、相册、相机、音乐、影院、字体管理器' echo -en '----------\n' Uninstall () { ${su} apt autoremove --purge --yes deepin-manual deepin-draw deepin-boot-maker deepin-log-viewer deepin-home deepin-reader deepin-feedback deepin-mail deepin-voice-note dde-introduction com.deepin.lianliankan libreoffice-common libreoffice-base libreoffice-calc libreoffice-draw libreoffice-impress libreoffice-math libreoffice-writer org.deepin.browser com.deepin.gomoku org.deepin.downloader deepin-unioncode deepin-forum laptop-mode-tools deepin-diskmanager dde-printer deepin-calculator deepin-screen-recorder deepin-image-viewer simple-scan deepin-devicemanager deepin-album deepin-camera deepin-music deepin-movie deepin-font-manager } Uninstall echo -en '----------\n' echo '系统 优化' echo -en '----------\n' Optimize () { # 终端 修改&禁用 ${su} rm -rf ~/.bash_history && ${su} touch ~/.bash_history && ${su} chattr +i ~/.bash_history ${su} rm -rf /root/.bash_history && ${su} touch /root/.bash_history && ${su} chattr +i /root/.bash_history # 自启 添加&修改 echo -e '\n#启动延时\nsleep 5 && notify-send "用户命令设定启动"' | ${su} tee -a /etc/profile echo -e 'amixer -c 0 sset "Headphone" 3 && amixer -c 0 sset "Headphone Mixer" 11' | ${su} tee -a /etc/profile echo -e 'amixer -c 0 sset "Headphone" unmute && amixer -c 0 sset "Right Headphone Mixer Right DAC" unmute' | ${su} tee -a /etc/profile # swap 创建&使用 ${su} truncate -s 0 /swapfile && ${su} chattr +C /swapfile && ${su} btrfs property set /swapfile compression none ${su} fallocate -l 512M /swapfile && ${su} mkswap /swapfile && ${su} chmod 0600 /swapfile && ${su} swapon /swapfile ${su} sed -i '$a\\n# swapfile\n/swapfile\t\tnone\t\tswap\t\tdefaults\t\t0\t\t0' /etc/fstab && ${su} sed -i '$a\vm.swappiness=50\n' /etc/sysctl.conf # 配置 修改&优化 ${su} sed -i 's/env_reset/env_reset,pwfeedback/g' /etc/sudoers ${su} sed -i "/^127.0.0.1.*/a 127.0.0.1 $(whoami)" /etc/hosts ${su} sed -i '/^#.*/d;/^$/d;/^Fast*/a AutoEnable = true' /etc/bluetooth/main.conf ${su} sed -i 's/community-packages.deepin.com/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list && ${su} chattr -R +i /etc/apt/sources.list.d # GRUB 修改&更新 ${su} sed -i '2,6d' /etc/default/grub.d/12_deepin_ab_recovery.cfg && ${su} cp -rf /etc/default/grub /etc/default/grub.bak #${su} sed -i 's/^GRUB_THEME=.*/GRUB_THEME=""/g;s/^GRUB_BACKGROUND=.*/GRUB_BACKGROUND=""/g;s/^GRUB_TIMEOUT=.*/GRUB_TIMEOUT=0\nGRUB_TIMOUT_STYLE=hidden/g' /etc/default/grub ${su} sed -i 's/^GRUB_CMDLINE_LINUX_DEFAULT=.*/GRUB_CMDLINE_LINUX_DEFAULT="splash quiet loglevel=0 "\nGRUB_CMDLINE_LINUX="intel_pstate=disable zswap.enabled=1 zswap.compressor=lz4hc "/g' /etc/default/grub # 应用 安装&卸载 ${su} rm -rf /var/lib/apt/lists/lock && ${su} update-grub && ${su} update-grub2 && ${su} apt update ${su} apt --fix-broken install -fy && ${su} apt dist-upgrade -fy && ${su} apt reinstall -fy cups telnet aria2 vsftpd ${su} ${download} ${deepin}linux-upstream/${new_image} && ${su} ${download} ${deepin}linux-upstream/${new_headers} && ${su} ${download} ${deepin}linux-firmware/${new_firmware} && ${su} dpkg -i ./*.deb && ${su} rm -rf ./*.deb ./deepin-fix-init* /deepin-fix-init* # 修改 配置文件 ${su} sed -i "s/^#write_enable=YES/write_enable=YES\nlocal_root=\/media/g" /etc/vsftpd.conf ${su} sed -i "//a Allow all;s/Browsing Off/Browsing On/g;//a Allow all;//a Allow all;//a Allow all;s/Listen localhost:631/Listen 0.0.0.0:631/g" /etc/cups/cupsd.conf # 服务 屏蔽&启用 ${su} systemctl restart ssh && ${su} systemctl enable ssh ${su} systemctl restart cups && ${su} systemctl enable cups ${su} systemctl restart vsftpd && ${su} systemctl enable vsftpd ${su} systemctl mask nmbd.service exim4.service apt-daily.service apt-daily-upgrade.service plymouth-quit-wait.service NetworkManager-wait-online.service } Optimize fi read -p '完成 部分功能重启后生效 回车结束!' exit 0