Add options to apt-get install call
This change also adds an apt-get update call and a possibility to provide debconf options that might be needed for some packages. In case of dpkg interruptions dpkg --configure -a is added to try to handle the failures. Change-Id: Ib1f9a412bc544b4f7754634740fb04569bae6d34
This commit is contained in:
parent
04745a1f88
commit
da532c32aa
@ -59,9 +59,25 @@ load_package_list_with_versions $(dpkg -l | awk 'NR>5 {print $2"="$3}')
|
||||
|
||||
{{- if hasKey .Values.conf "apt" }}
|
||||
{{- if hasKey .Values.conf.apt "packages" }}
|
||||
apt-get update
|
||||
|
||||
# Set all debconf selections up front
|
||||
{{- range .Values.conf.apt.packages }}
|
||||
if [[ "${CURRENT_PACKAGES[{{ .name | squote }}]+isset}" != "isset"{{- if .version }} || "${CURRENT_PACKAGES[{{ .name | squote }}]}" != {{ .version | squote }}{{- end }} ]]; then
|
||||
apt-get install -y{{ if .repo }} -t {{ .repo | squote }}{{ end }} {{ .name | squote -}} {{- if .version }}={{ .version | squote }}{{ end }}
|
||||
{{- $pkg_name := .name }}
|
||||
{{- range .debconf }}
|
||||
debconf-set-selections <<< "{{ $pkg_name }} {{ .question }} {{ .question_type }} {{ .answer }}"
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
|
||||
# Run dpkg in case of interruption of previous dpkg operation
|
||||
dpkg --configure -a
|
||||
|
||||
# Perform package installs
|
||||
{{- range .Values.conf.apt.packages }}
|
||||
{{- $pkg_name := .name }}
|
||||
if [[ "${CURRENT_PACKAGES[{{ .name | squote }}]+isset}" != "isset"{{- if .version }} || "${CURRENT_PACKAGES[{{ .name | squote }}]}" != {{ .version }}{{- end }} ]]; then
|
||||
# Run this in case some package installation was interrupted
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -o Dpkg::Options::=--force-confdef -o Dpkg::Options::=--force-confold{{- if .repo }} -t {{ .repo }}{{ end }} {{ .name -}} {{- if .version }}={{ .version }}{{ end }}
|
||||
INSTALLED_THIS_TIME="$INSTALLED_THIS_TIME {{ .name }}"
|
||||
fi
|
||||
REQUESTED_PACKAGES="$REQUESTED_PACKAGES {{ .name }}"
|
||||
@ -80,6 +96,7 @@ if [ -f ${persist_path}/packages ]; then
|
||||
TO_DELETE=$(comm -23 ${persist_path}/packages ${persist_path}/packages.requested)
|
||||
TO_KEEP=$(echo "$TO_DELETE" | comm -23 ${persist_path}/packages -)
|
||||
if [ ! -z "$TO_DELETE" ]; then
|
||||
dpkg --configure -a
|
||||
for pkg in "$TO_DELETE"; do
|
||||
apt-get purge -y $pkg
|
||||
done
|
||||
@ -102,6 +119,7 @@ fi
|
||||
######################################################
|
||||
|
||||
{{- if hasKey .Values.conf.apt "blacklistpkgs" }}
|
||||
dpkg --configure -a
|
||||
{{- range .Values.conf.apt.blacklistpkgs }}
|
||||
{{- $package := . }}
|
||||
apt-get remove --autoremove -y {{ $package | squote }}
|
||||
|
@ -158,6 +158,18 @@ Here is an example configuration for it::
|
||||
version: <VERSION1>
|
||||
- name: <PACKAGE2>
|
||||
|
||||
It is also possible to provide debconf settings for packages the following
|
||||
way::
|
||||
|
||||
conf:
|
||||
apt:
|
||||
packages:
|
||||
- name: openssh-server
|
||||
debconf:
|
||||
- question: openssh-server/permit-root-login
|
||||
question_type: boolean
|
||||
answer: false
|
||||
|
||||
Operations
|
||||
----------
|
||||
|
||||
|
@ -49,7 +49,7 @@ USERNAME4=userfour
|
||||
USERNAME4_SUDO=false
|
||||
APT_PACKAGE1=python-pbr
|
||||
APT_VERSION1=1.8.0-4ubuntu1
|
||||
APT_PACKAGE2=python-yaml
|
||||
APT_PACKAGE2=mysql-server
|
||||
APT_PACKAGE3=python-simplejson
|
||||
APT_VERSION3=3.8.1-1ubuntu2
|
||||
APT_PACKAGE4=less
|
||||
@ -804,12 +804,25 @@ test_apt(){
|
||||
apt:
|
||||
packages:
|
||||
- name: $APT_PACKAGE2
|
||||
debconf:
|
||||
- question: mysql-server/root_password
|
||||
question_type: password
|
||||
answer: rootpw
|
||||
- question: mysql-server/root_password_again
|
||||
question_type: password
|
||||
answer: rootpw
|
||||
- name: $APT_PACKAGE3
|
||||
version: $APT_VERSION3" > "${overrides_yaml}"
|
||||
install_base "--values=${overrides_yaml}"
|
||||
get_container_status apt
|
||||
_test_apt_package_version $APT_PACKAGE1 none
|
||||
_test_apt_package_version $APT_PACKAGE2 any
|
||||
# Each entry in passwords.dat contains question value in Name and Template
|
||||
# field, so grepping root_password should return 4 lines
|
||||
if [[ $(grep root_password /var/cache/debconf/passwords.dat | wc -l) != 4 ]]; then
|
||||
echo "[FAIL] Package $APT_PACKAGE2 should have debconf values configured" >> "${TEST_RESULTS}"
|
||||
return 1
|
||||
fi
|
||||
_test_apt_package_version $APT_PACKAGE3 $APT_VERSION3
|
||||
echo '[SUCCESS] apt test2 passed successfully' >> "${TEST_RESULTS}"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user