在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
如果您覺得本文章受用,請點個贊,給個評論!謝謝.~~~