dpkg-reconfigure tzdata에 대한 비대화 형 방법
Ubuntu 서버를 처음 설정할 때 I를 확인한 aptitude install tzdata다음 dpkg-reconfigure tzdata시간대를 올바르게 설정합니다.
스크립트를 사용하여 서버 설정을 자동화하려고하는데, 사용자 개입이있는 대화 형 세션이 필요하기 때문에이 부분이 자동으로 작동하는 것을 발견했습니다.
인터랙티브하지 않고 dpkg-reconfigure를 사용하는 방법이 있습니까?
업데이트 :이 질문은 이제 StackOverflow에서 주제를 벗어났습니다. ServerFault에서 정답을
참조하십시오 .
swill의 대답은 그것이 어떻게 제대로 수행되는지가 아닙니다. 패키지의 무인 / 스크립트 dpkg 구성을 원한다면 debconf 미리 설정 메커니즘을 사용하고 싶습니다.
귀하의 경우 이것은 다음을 수행해야 함을 의미합니다.
debconf가 사용자에게 질문을하지 않도록 다음 환경 변수를 설정하십시오.
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true다음 preseed.txt 파일 (또는 원하는 다른 설정)을 사용하여 debconf를 미리 시드합니다.
tzdata tzdata/Areas select Europe tzdata tzdata/Zones/Europe select Berlin다음을 실행하여 위의 사전 시드 파일을 설정합니다.
debconf-set-selections /your/preseed.txt이제 tzdata를 설치하거나 (아직 설치되지 않은 경우)를 통해 설치할 수
apt있습니다dpkg-reconfigure. 결국 tzdata는 debconf preseed 파일에 지정한 내용에 따라 설정됩니다.
debconf 미리 설정을 사용하면 더 많은 것을 자동화 할 수 있습니다. 예를 들어 내 preseeds에서 항상 설정합니다.
locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8
locales locales/default_environment_locale select en_US.UTF-8
를 실행하여 언제든지 현재 시스템의 debconf 설정을 검사 할 수 있습니다 debconf-get-selections. 출력은 debconf 미리 설정을 사용하여 자동화 할 수있는 시스템 구성의 양에 대한 아이디어를 제공합니다.
16.04에 버그 ( https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1554806 ,이 답변을 작성하는 시점에 수정되지 않음)가있어의 내용을 /etc/timezone이전 내용 으로 덮어 씁니다. 실행할 때 값 dpkg-reconfigure -f noninteractive tzdata. 수정 사항은 다음과 같습니다 (위의 버그 보고서에서).
$ sudo ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
$ sudo dpkg-reconfigure --frontend noninteractive tzdata
Current default time zone: 'America/New_York'
Local time is now: Mon Feb 20 07:30:33 EST 2017.
Universal Time is now: Mon Feb 20 12:30:33 UTC 2017.
$ cat /etc/timezone
America/New_York
의 내용을 수동으로 변경할 필요가 없습니다 /etc/timezone. 이것은 Ubuntu 16.04.2 LTS에서 나를 위해 일했습니다.
다음에서 수행 Dockerfile:
FROM ubuntu:xenial
## for apt to be noninteractive
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
## preesed tzdata, update package index, upgrade packages and install needed software
RUN echo "tzdata tzdata/Areas select Europe" > /tmp/preseed.txt; \
echo "tzdata tzdata/Zones/Europe select Berlin" >> /tmp/preseed.txt; \
debconf-set-selections /tmp/preseed.txt && \
rm /etc/timezone && \
rm /etc/localtime && \
apt-get update && \
apt-get install -y tzdata
## cleanup of files from setup
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
내 실험에서 필자는 /etc필요 에 따라 파일을 제거하기로 결정했습니다 .
전진 josch 의 대답을; debconf db 값을 설정하고 실행하기 전에 제거하십시오/etc/{localtime,timezone}dpkg-reconfigure :-
$ echo "tzdata tzdata/Areas select Europe" > some/file.txt
$ echo "tzdata tzdata/Zones/Europe select Berlin" >> some/file.txt
$ sudo debconf-set-selections some/file.txt
$ sudo rm /etc/timezone
$ sudo rm /etc/localtime
$ sudo dpkg-reconfigure -f noninteractive tzdata
Current default time zone: 'Europe/Berlin'
Local time is now: Thu Sep 1 17:13:16 CEST 2016.
Universal Time is now: Thu Sep 1 15:13:16 UTC 2016.
이 방법은 다음에서 작동하는 것으로 알려져 있습니다.
- Ubunty Trusty (14.04.5 LTS)
Here's my Dockerfile for the latest Ubuntu 18.04 LTS distro, adapted from the answer by @NilsBallmann. I also removed temp file creation and compacted the package installation into a single layer:
FROM ubuntu:bionic
RUN export DEBIAN_FRONTEND=noninteractive; \
export DEBCONF_NONINTERACTIVE_SEEN=true; \
echo 'tzdata tzdata/Areas select Etc' | debconf-set-selections; \
echo 'tzdata tzdata/Zones/Etc select UTC' | debconf-set-selections; \
apt-get update -qqy \
&& apt-get install -qqy --no-install-recommends \
tzdata \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
참고URL : https://stackoverflow.com/questions/8671308/non-interactive-method-for-dpkg-reconfigure-tzdata
'developer tip' 카테고리의 다른 글
| 향후 버전의 .NET은 C #에서 튜플을 지원합니까? (0) | 2020.11.03 |
|---|---|
| 구분 기호는 영숫자 또는 백 슬래시 및 preg_match가 아니어야합니다. (0) | 2020.11.03 |
| Qt에서 크기가 고정 된 크기 조정이 불가능한 QDialog? (0) | 2020.11.03 |
| Android 툴바 다른 조각에 대한 메뉴 항목 추가 (0) | 2020.11.03 |
| 알파벳을 열거하는 가장 빠른 방법 (0) | 2020.11.03 |