Bash
1 前言
一个问题,一篇文章,一出故事。
笔者最近需要安装Debian系统,于是想着安装软件方便,于是写一个安装脚本,以便快速部署自己所需的软件。
2 最佳实践
2.1 挂载包含安装程序的U盘
mount /dev/sdb3 /mnt
2.2 创建安装配置脚本
vim /mnt/installConfig.sh
加入如下脚本,
#!/bin/bash hostName='will_pc.cmdschool.org' timeZone='Asia/Shanghai' insallSoftwares="\ net-tools \ chrony \ vinagre \ deepin-terminal \ bumblebee" installSoftwareDir='installSoftware' # base config hostnamectl set-hostname "$hostName" timedatectl set-timezone "$timeZone" systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target # apt source config sed -i "s/^deb cdrom/#deb cdrom/g" /etc/apt/sources.list cat > /etc/apt/sources.list.d/aliyun.list << EOF deb https://mirrors.aliyun.com/debian/ bookworm main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bookworm main non-free contrib deb https://mirrors.aliyun.com/debian-security/ bookworm-security main deb-src https://mirrors.aliyun.com/debian-security/ bookworm-security main deb https://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib deb https://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib deb-src https://mirrors.aliyun.com/debian/ bookworm-backports main non-free contrib EOF cat > /etc/apt/sources.list.d/firmware.list << EOF deb http://mirrors.163.com/debian/ bookworm main non-free-firmware deb-src http://mirrors.163.com/debian/ bookworm main non-free-firmware deb http://mirrors.163.com/debian/ bookworm-updates main non-free-firmware deb-src http://mirrors.163.com/debian/ bookworm-updates main non-free-firmware deb http://security.debian.org/debian-security bookworm-security main non-free-firmware deb-src http://security.debian.org/debian-security bookworm-security main non-free-firmware EOF nstallTools="apt apt-get " for i in $installTools; do installToolPID="`pgrep -u root $i`" if [ "$installToolPID" = "" ]; then continue fi killall -9 $i done apt update -y # openssh install & config apt install -y openssh-server sshdConfig='/etc/ssh/sshd_config' permitRootLogin=`grep ^PermitRootLogin $sshdConfig` if [ "$permitRootLogin" = "" ]; then sed -i "s/#PermitRootLogin prohibit-password/#PermitRootLogin prohibit-password\nPermitRootLogin yes/g" $sshdConfig else sed -i "s~$permitRootLogin~PermitRootLogin yes~g" $sshdConfig fi systemctl reload sshd # config vim apt install -y vim vimConfig='/etc/vim/vimrc.local' if [ ! -f "$vimConfig" ]; then echo "source /usr/share/vim/vim*/defaults.vim" > "$vimConfig" echo "let skip_defaults_vim = 1" >> "$vimConfig" echo "if has('mouse')" >> "$vimConfig" echo " set mouse=r" >> "$vimConfig" echo "endif" >> "$vimConfig" fi if [ ! -d "$installSoftwareDir" ]; then exit fi find "$installSoftwareDir" -name *.deb -exec apt install -y ./{} \; apt install -y $insallSoftwares exit #config im im-config -n fcitx systemctl restart gdm.service
根据脚本的要求,你需要创建本地安装的软件目录,
mkdir /mnt/installSoftware/
然后,你可以把需要安装的软件直接下载到“installSoftware”目录,
cd /mnt/installSoftware/ wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb wget http://archive.ubuntukylin.com/software/pool/partner/weixin_2.1.1_amd64.deb wget https://dldir1.qq.com/qqfile/qq/QQNT/ad5b5393/linuxqq_3.1.2-13107_arm64.deb wget https://ime.sogouimecdn.com/202209140001/5b47916113b2d86a857b4184fd390bde/dl/gzindex/1656597217/sogoupinyin_4.0.1.2800_x86_64.deb
2.3 执行安装配置
sh /mnt/installConfig.sh
没有评论