Explain DEBIAN 您所在的位置:网站首页 debian_frontend=noninteractive Explain DEBIAN

Explain DEBIAN

2024-01-19 23:18| 来源: 网络整理| 查看: 265

See all Debian/Ubuntu Linux related FAQCan you explain DEBIAN_FRONTEND apt or apt-get variable? How and why I need to use this in Docker or shell scripts under a Debian and Ubuntu Linux? Debian, Ubuntu, and clones use the Debian package configuration system called debconf. One can use debconf before packages installed onto your Linux desktop or cloud server. For example, one can configure the apt command or apt-get command using various options for sysadmin tasks. This page explains DEBIAN_FRONTEND environment variable. Tutorial details Difficulty level Easy Root privileges Yes Requirements Linux terminal Category Package Manager Prerequisites apt-get command OS compatibility Debian • Linux • Mint • Pop!_OS • Ubuntu Est. reading time 5 minutes nixCraft: Privacy First, Reader Supported nixCraft is a one-person operation. I create all the content myself, with no help from AI or ML. I keep the content accurate and up-to-date. Your privacy is my top priority. I don’t track you, show you ads, or spam you with emails. Just pure content in the true spirit of Linux and FLOSS. Fast and clean browsing experience. nixCraft is designed to be fast and easy to use. You won’t have to deal with pop-ups, ads, cookie banners, or other distractions. Support independent content creators. nixCraft is a labor of love, and it’s only possible thanks to the support of our readers. If you enjoy the content, please support us on Patreon or share this page on social media or your blog. Every bit helps.

Join Patreon ➔ Explain DEBIAN_FRONTEND apt-get variable

One of debconf’s unique features is that the interface it presents to you is only one of many that can be swapped in at will. There are many debconf frontends available:

dialog – The default frontend for apt/apt-get under Debian/Ubuntu Linux. It displays questions to you. It works in text mode over ssh based session. readline – The most traditional frontend, this looks quite similar to how Debian configuration options are: a series of questions, printed out at the console using plain text. Best suited when you are working with slow remote connections and entirely comfortable with Linux command-line options. noninteractive – You use this mode when you need zero interaction while installing or upgrading the system via apt. It accepts the default answer for all questions. It might mail an error message to the root user, but that’s it all. Otherwise, it is totally silent and humble, a perfect frontend for automatic installs. One can use such mode in Dockerfile, shell scripts, cloud-init script, and more. gnome – This is a modern X GUI using the gtk and gnome libraries. kde – Another frontend provides a simple X GUI written with the Qt library. It fits well the KDE desktop. editor – This is for those fanatics who have to do everything in a text editor. It runs your editor on a file that looks something like a typical unix config file, and you edit those files to communicate with debconf. web – This frontend acts as a web server, that you connect to with your web browser, to browse the questions and answer them. Again it is a proof of concept, and one should avoid using web frontend for security reasons. How to use apt DEBIAN_FRONTEND environment variable

The syntax is as follows: $ DEBIAN_FRONTEND={name_here} apt-get install pkg $ DEBIAN_FRONTEND={name_here} apt install pkg $ DEBIAN_FRONTEND=noninteractive apt-get -y update $ DEBIAN_FRONTEND=noninteractive apt-get -y upgrade For longer scripts and other swapping process you may want to export shell variable: $ export DEBIAN_FRONTEND=noninteractive $ apt -y install nginx $ apt-get -y update $ apt-get -y upgrade We can find out if our Ubuntu/Debian Linux server needs a reboot including service restart using the needrestart command. The needrestart checks which daemons need to be restarted after library upgrades. Set the restart mode to automatic: $ NEEDRESTART_MODE=a $ export NEEDRESTART_MODE=a

How to apt-get update and upgrade automate and unattended

The following will force apt-get to work automatic and unattended mode.

export NEEDRESTART_MODE=a export DEBIAN_FRONTEND=noninteractive ## Questions that you really, really need to see (or else). ## export DEBIAN_PRIORITY=critical apt-get -qy clean apt-get -qy update apt-get -qy -o "Dpkg::Options::=--force-confdef" -o "Dpkg::Options::=--force-confold" upgrade

Another nice feature of debconf is that the questions it asks you are prioritized. If you don’t want to be bothered about every little thing, you can set up debconf to only ask you the most important questions. Hence, we set DEBIAN_PRIORITY to critical. The -q produces output suitable for logging, omitting progress indicators.

AWS EC2/Lightsail VM example

One can run script using Linode or AWS or service providers cloud-init system. In other words add a shell script that will run on your instance the first time it launches on AWS Lightsail: Ubuntu Debian DEBIAN_FRONTEND=noninteractive Linux script on AWS EC2

For EC2 run aws cli as follows: aws ec2 run-instances --image-id ami-abcd1234 --count 1 \ --instance-type m3.medium --key-name my-ssh-key \ --subnet-id subnet-abcd1234 --security-group-ids sg-abcd1234 \ --user-data file://ubuntu-server-script.txt Stackscripts

You can write and use a script to configure your VM when it starts up. These scripts can add software, update software, or configure your instance in some other way on Linode: Explain DEBIAN_FRONTEND apt-get in Debian or Ubuntu Linux on Linode

Sample shell script

The following script force apt-get to skip any interactive post-install configuration steps and do other stuff too before we can use Ansible for other stuff:

#!/bin/bash ## Tested for AWS only. May need modification and subnet for other cloud hosting providers ## Author: Vivek Gite, under GPL v2.+ {https://www.cyberciti.biz/} ## ------------------------------------------------------------------------------------------ ## admin_IP_1|short_description_1 admin_IP_2|short_description_2 _admin_ip="1.2.3.4|MUM_ADM 3.2.4.5|DEL_IDC 6.7.8.9|VPN_SG_1"   ## set server hostname, we can get it from gcp/aws conf too _hostname="server1.cyberciti.biz"   ## update system when vm creted via cloud-init ## export DEBIAN_FRONTEND=noninteractive apt-get -y update apt-get -y upgrade   ## set hostname ## hostnamectl set-hostname "${_hostname}"   ## get security settings ## wget -q -O /etc/sysctl.d/1000-custom.conf https://www.cyberciti.biz/files/1000-custom.conf   ## enable firewall ## yes | ufw enable   ## open ssh port to our admin ips only ## for e in $_admin_ip do ufw allow from "${e%%|*}" to any port 22 proto tcp comment 'Open SSH port for ${e##*|}' done   ## extra rule allow vpc ufw allow from 172.26.0.0/16 to 172.26.0.0/16 proto any comment 'Allow communitcation between AWS VPC peers' ufw allow from 172.31.0.0/16 to 172.26.0.0/16 proto any comment 'Allow communitcation between AWS VPC peers'   ## sync and reboot vm ## sync reboot   ## Rest config will be done by Ansbile ## Conclusion

You learned how to use DEBIAN_FRONTEND to change the frontend debconf uses temporarily. See debconf and apt-get man pages for more information using the man command or by passing the --help option as follows: $ man 7 debconf $ apt-get --help $ man 8 apt $ man 8 apt-get

Did you notice? 🧐 nixCraft is ad-free to protect your privacy and security. We rely on reader support to keep the site running. Please consider subscribing to us on Patreon or supporting us with a one-time support through PayPal or purchase official merchandise. Your support will help us cover the costs of hosting, CDN, DNS, and tutorial creation.

Patreon ➔    PayPal ➔    Shop ➔


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有