Signed-off-by: Yu Chuan 13186087857@163.com --- jobs/iso2rootfs.yaml | 4 ++++ tests/iso2rootfs | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/jobs/iso2rootfs.yaml b/jobs/iso2rootfs.yaml index c67faf44147d..a84f7583de94 100644 --- a/jobs/iso2rootfs.yaml +++ b/jobs/iso2rootfs.yaml @@ -34,6 +34,10 @@ iso2rootfs: # - no_fstab: will comment all line in /etc/fstab. config_rootfs:
+ ## install pkgs for result rootfs + ## - example: vim, git, xxx + rootfs_install_pkgs: + ################# # dailybuild related fields ################# diff --git a/tests/iso2rootfs b/tests/iso2rootfs index dbb409d16923..c8c9318436c9 100755 --- a/tests/iso2rootfs +++ b/tests/iso2rootfs @@ -203,17 +203,24 @@ get_cgz() tar -xf "${cgz_path_t}" -C "${CGZ_PATH}" }
-install_pkgs() +get_pkg_installer() { - local pkg_installer - command -v yum && pkg_installer="yum" + local installer + + [ -d "/etc/yum/" ] && installer=yum + [ -d "/etc/apt/" ] && installer=apt
- [[ -n "$pkg_installer" ]] || die "cannot find pkg installer." + [ -n "$installer" ] || die "cannot find pkg installer." + echo $installer +} + +install_pkgs() +{ + local installer=$(get_pkg_installer)
- local pt for pt do - "$pkg_installer" install -y "$pt" || die "cannot install pkg: $pt." + "$installer" install -y "$pt" || die "cannot install pkg: $pt." done }
@@ -367,11 +374,26 @@ disable_fstab() sed -i 's/^([^#])/#\1/g' "${ROOTFS_DES_DIR}/etc/fstab" }
+rootfs_install_pkgs() +{ + [ -n "$rootfs_install_pkgs" ] || return 0 + + local installer=$(get_pkg_installer) + + if [ "$installer" == "yum" ]; then + "$installer" install -y --installroot=${ROOTFS_DES_DIR} ${rootfs_install_pkgs//,/ } + elif [ "$installer" == "apt" ]; then + "$installer" install -y -o RootDir=${ROOTFS_DES_DIR} ${rootfs_install_pkgs//,/ } + fi +} + config_rootfs() { config_dns_resolver disable_selinux disable_fstab + + rootfs_install_pkgs }
############ test rootfs ############
On Thu, Dec 10, 2020 at 02:19:09PM +0800, Yu Chuan wrote:
Signed-off-by: Yu Chuan 13186087857@163.com
jobs/iso2rootfs.yaml | 4 ++++ tests/iso2rootfs | 34 ++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/jobs/iso2rootfs.yaml b/jobs/iso2rootfs.yaml index c67faf44147d..a84f7583de94 100644 --- a/jobs/iso2rootfs.yaml +++ b/jobs/iso2rootfs.yaml @@ -34,6 +34,10 @@ iso2rootfs: # - no_fstab: will comment all line in /etc/fstab. config_rootfs:
- ## install pkgs for result rootfs
- ## - example: vim, git, xxx
- rootfs_install_pkgs:
- ################# # dailybuild related fields #################
diff --git a/tests/iso2rootfs b/tests/iso2rootfs index dbb409d16923..c8c9318436c9 100755 --- a/tests/iso2rootfs +++ b/tests/iso2rootfs @@ -203,17 +203,24 @@ get_cgz() tar -xf "${cgz_path_t}" -C "${CGZ_PATH}" }
-install_pkgs() +get_pkg_installer() {
- local pkg_installer
- command -v yum && pkg_installer="yum"
- local installer
- [ -d "/etc/yum/" ] && installer=yum
- [ -d "/etc/apt/" ] && installer=apt
how about use has_cmd
- [[ -n "$pkg_installer" ]] || die "cannot find pkg installer."
- [ -n "$installer" ] || die "cannot find pkg installer."
- echo $installer
+}
+install_pkgs() +{
- local installer=$(get_pkg_installer)
- local pt for pt do
"$pkg_installer" install -y "$pt" || die "cannot install pkg: $pt."
"$installer" install -y "$pt" || die "cannot install pkg: $pt."
--skip-broken
done }
@@ -367,11 +374,26 @@ disable_fstab() sed -i 's/^([^#])/#\1/g' "${ROOTFS_DES_DIR}/etc/fstab" }
+rootfs_install_pkgs()
install_pkgs_for_rootfs
+{
- [ -n "$rootfs_install_pkgs" ] || return 0
- local installer=$(get_pkg_installer)
- if [ "$installer" == "yum" ]; then
"$installer" install -y --installroot=${ROOTFS_DES_DIR} ${rootfs_install_pkgs//,/ }
--skip-broken
Thanks, Shenwei
- elif [ "$installer" == "apt" ]; then
"$installer" install -y -o RootDir=${ROOTFS_DES_DIR} ${rootfs_install_pkgs//,/ }
- fi
+}
config_rootfs() { config_dns_resolver disable_selinux disable_fstab
- rootfs_install_pkgs
}
############ test rootfs ############
2.23.0
- [ -d "/etc/yum/" ] && installer=yum
- [ -d "/etc/apt/" ] && installer=apt
how about use has_cmd
Good !
"$pkg_installer" install -y "$pt" || die "cannot install pkg: $pt."
"$installer" install -y "$pt" || die "cannot install pkg: $pt."
--skip-broken
Good, but this is unnecessary here.
+rootfs_install_pkgs()
install_pkgs_for_rootfs
Good.
+{
- [ -n "$rootfs_install_pkgs" ] || return 0
- local installer=$(get_pkg_installer)
- if [ "$installer" == "yum" ]; then
"$installer" install -y --installroot=${ROOTFS_DES_DIR} ${rootfs_install_pkgs//,/ }
--skip-broken
ok, it look more suitable here.
-------- Thanks Yu Chuan
Thanks, Shenwei
- elif [ "$installer" == "apt" ]; then
"$installer" install -y -o RootDir=${ROOTFS_DES_DIR} ${rootfs_install_pkgs//,/ }
- fi
+}
config_rootfs() { config_dns_resolver disable_selinux disable_fstab
- rootfs_install_pkgs
}
############ test rootfs ############
2.23.0