Skip to content

Commit

Permalink
Merge pull request #2607 from OSInside/debian_mandatory_script_runs
Browse files Browse the repository at this point in the history
Mandatory package scripts for Debian bootstrap
  • Loading branch information
Conan-Kudo authored Aug 6, 2024
2 parents 1b3265f + 716bcc4 commit 759f63c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
32 changes: 25 additions & 7 deletions kiwi/package_manager/apt.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import os
import glob
import logging
from textwrap import dedent
from typing import (
List, Dict
)
Expand Down Expand Up @@ -243,22 +244,39 @@ def _process_install_requests_bootstrap(self) -> CommandCallT:
'-oDebug::pkgDPkgPm=1',
f'-oDPkg::Pre-Install-Pkgs::=cat >{package_names.name}',
'?essential',
'?exact-name(usr-is-merged)'
'?exact-name(usr-is-merged)',
'base-passwd'
] + self.package_requests
result = Command.run(
download_bootstrap, self.command_env
)
log.debug(
'Apt download: {0} {1}'.format(result.output, result.error)
)
script = dedent('''\n
set -e
while read -r deb;do
echo "Unpacking $deb"
dpkg-deb --fsys-tarfile $deb | tar -C {0} -x
done < {1}
while read -r deb;do
pushd "$(dirname "$deb")" >/dev/null || exit 1
if [[ "$(basename "$deb")" == base-passwd* ]];then
echo "Running pre/post package scripts for $(basename "$deb")"
dpkg -e "$deb" "{0}/DEBIAN"
test -e {0}/DEBIAN/preinst && chroot {0} bash -c "/DEBIAN/preinst install"
test -e {0}/DEBIAN/postinst && chroot {0} bash -c "/DEBIAN/postinst"
rm -rf {0}/DEBIAN
fi
popd >/dev/null || exit 1
done < {1}
''')

script.format(self.root_dir, package_names.name)

with open(package_extract.name, 'w') as install:
install.write(
'while read -r deb;do echo "{0}";{1}|{2};done <{3}'.format(
'Unpacking $deb',
'dpkg-deb --fsys-tarfile $deb',
f'tar -C {self.root_dir} -x',
package_names.name
)
script.format(self.root_dir, package_names.name)
)
result = Command.run(
['bash', package_extract.name], self.command_env
Expand Down
23 changes: 21 additions & 2 deletions test/unit/package_manager/apt_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import io
from textwrap import dedent
from unittest.mock import (
patch, call, Mock, MagicMock
)
Expand Down Expand Up @@ -127,9 +128,26 @@ def test_process_install_requests_bootstrap(
mock_open.return_value = MagicMock(spec=io.IOBase)
file_handle = mock_open.return_value.__enter__.return_value
self.manager.process_install_requests_bootstrap()
script = dedent('''\n
set -e
while read -r deb;do
echo "Unpacking $deb"
dpkg-deb --fsys-tarfile $deb | tar -C {0} -x
done < {1}
while read -r deb;do
pushd "$(dirname "$deb")" >/dev/null || exit 1
if [[ "$(basename "$deb")" == base-passwd* ]];then
echo "Running pre/post package scripts for $(basename "$deb")"
dpkg -e "$deb" "{0}/DEBIAN"
test -e {0}/DEBIAN/preinst && chroot {0} bash -c "/DEBIAN/preinst install"
test -e {0}/DEBIAN/postinst && chroot {0} bash -c "/DEBIAN/postinst"
rm -rf {0}/DEBIAN
fi
popd >/dev/null || exit 1
done < {1}
''')
file_handle.write.assert_called_once_with(
'while read -r deb;do echo "Unpacking $deb";dpkg-deb'
' --fsys-tarfile $deb|tar -C root-dir -x;done <temporary'
script.format('root-dir', 'temporary')
)
assert mock_Command_run.call_args_list == [
call(
Expand All @@ -142,6 +160,7 @@ def test_process_install_requests_bootstrap(
'-oDPkg::Pre-Install-Pkgs::=cat >temporary',
'?essential',
'?exact-name(usr-is-merged)',
'base-passwd',
'vim',
'apt'
], ['env']
Expand Down

0 comments on commit 759f63c

Please sign in to comment.