Ubuntu 静默安装DEB包(非交互式)

在Ubuntu环境下安装DEB包时,比如安装MySQL式经常会弹出交互式要输入密码的操作。有时候我们期望编写Shell脚本一键部署MySQL时不想要弹窗交互时,则可以使用以下方式实现自动化安装Deb软件。

概述

debconf-utils是一个可以在Ubuntu下预先配置要安装程序的小工具,它可以避免在安装一个DEB程序时的弹窗输入问题,这可能在编写一键部署脚本的时候非常有用。
以下我们用安装MySQL-APT源作为示例。

1、安装debconf-utils

root@ubuntu:~# apt-get -y install debconf-utils

2、更新APT源

root@ubuntu:~# apt-get update

3、先手动安装一遍MySQL-APT源

此时有弹窗!根据弹窗和自己的需求输入并安装一遍。

root@ubuntu:~# wget https://repo.mysql.com/mysql-apt-config_0.8.13-1_all.deb
root@ubuntu:~# dpkg -i mysql-apt-config_0.8.13-1_all.deb

4、查询想要预先配置的DEB程序的相关配置信息

通过已安装的DEB程序,获取到想要静默安装预配置信息。

root@ubuntu:~# debconf-get-selections |grep 'mysql-apt-config'
mysql-apt-config	mysql-apt-config/select-tools	select	Enabled
mysql-apt-config	mysql-apt-config/select-server	select	mysql-5.7
mysql-apt-config	mysql-apt-config/repo-url	string	http://repo.mysql.com/apt
mysql-apt-config	mysql-apt-config/preview-component	string	
mysql-apt-config	mysql-apt-config/repo-codename	select	xenial
mysql-apt-config	mysql-apt-config/tools-component	string	mysql-tools
mysql-apt-config	mysql-apt-config/select-preview	select	Disabled
mysql-apt-config	mysql-apt-config/select-product	select	Ok
mysql-apt-config	mysql-apt-config/repo-distro	select	ubuntu
mysql-apt-config	mysql-apt-config/unsupported-platform	select	abort
mysql-apt-config	mysql-apt-config/dmr-warning	note	

5、然后卸载已安装的DEB包

卸载刚刚需要通过图形化弹窗安装程序。

root@ubuntu:~# apt-get -y remove  mysql-apt-config

6、重新安装DEB包,预配置软件

根据上面获取到预配置信息,预配置软件。

root@ubuntu:~# debconf-set-selections << EOF
mysql-apt-config mysql-apt-config/select-tools select Enabled
mysql-apt-config mysql-apt-config/select-server select mysql-5.7
mysql-apt-config mysql-apt-config/repo-url string http://repo.mysql.com/apt
mysql-apt-config mysql-apt-config/preview-component string	
mysql-apt-config mysql-apt-config/repo-codename select xenial
mysql-apt-config mysql-apt-config/tools-component string mysql-tools
mysql-apt-config mysql-apt-config/select-preview select Disabled
mysql-apt-config mysql-apt-config/select-product select Ok
mysql-apt-config mysql-apt-config/repo-distro select ubuntu
mysql-apt-config mysql-apt-config/unsupported-platform select abort
mysql-apt-config mysql-apt-config/dmr-warning note	
EOF

6、关闭交互式的静默安装DEB包

你会发现没有弹窗提示了!

root@ubuntu:~# DEBIAN_FRONTEND=noninteractive apt-get -y install ./mysql-apt-config_0.8.13-1_all.deb

如果您觉得本文章受用,请点个赞,给个评论!谢谢.~~~

乐在分享!~~
原文地址:https://www.cnblogs.com/network-ren/p/14574060.html