Skip to content

Commit

Permalink
Merge pull request #458 from tu1h/import_iso_ubuntu
Browse files Browse the repository at this point in the history
Support import for ubuntu iso
  • Loading branch information
ErikJiang authored Jan 5, 2023
2 parents 17ca681 + a6a8449 commit ab2248b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 12 deletions.
69 changes: 58 additions & 11 deletions artifacts/gen_repo_conf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ REPO_BASE_URL=''
ISO_MOUNT_PATH=''

MARK_NAME=Kubean
ISO_REPO_CONF=${MARK_NAME}-ISO.repo
URL_REPO_CONF=${MARK_NAME}-URL.repo
YUM_ISO_REPO_CONF=${MARK_NAME}-ISO.repo
YUM_URL_REPO_CONF=${MARK_NAME}-URL.repo

YUM_REPOS_PATH=/etc/yum.repos.d
YUM_REPOS_BAK_PATH=/etc/yum.repos.d.bak

APT_REPOS_DIR=/etc/apt/sources.list.d
APT_REPOS_PATH=/etc/apt/sources.list
APT_ISO_REPO_CONF=${MARK_NAME}-ISO.list
APT_URL_REPO_CONF=${MARK_NAME}-URL.list

function check_iso_img() {
if [ -z "${ISO_IMG_FILE}" ] || [ ! -f ${ISO_IMG_FILE} ]; then
echo "iso image: \${ISO_IMG_FILE} should exist."
Expand Down Expand Up @@ -49,7 +54,7 @@ function generate_yum_repo() {

if [ ${MODE} == "iso" ]; then
if [ "${OS}" == "rhel" ]; then
cat >${YUM_REPOS_PATH}/${ISO_REPO_CONF} <<EOF
cat >${YUM_REPOS_PATH}/${YUM_ISO_REPO_CONF} <<EOF
[kubean-iso-BaseOS]
name=Kubean ISO Repo BaseOS
baseurl=file://${ISO_MOUNT_PATH}/BaseOS
Expand All @@ -65,7 +70,7 @@ gpgcheck=0
sslverify=0
EOF
else
cat >${YUM_REPOS_PATH}/${ISO_REPO_CONF} <<EOF
cat >${YUM_REPOS_PATH}/${YUM_ISO_REPO_CONF} <<EOF
[kubean-iso]
name=Kubean ISO Repo
baseurl=file://${ISO_MOUNT_PATH}
Expand All @@ -74,19 +79,58 @@ gpgcheck=0
sslverify=0
EOF
fi
echo "generate: ${YUM_REPOS_PATH}/${ISO_REPO_CONF}"
echo "generate: ${YUM_REPOS_PATH}/${YUM_ISO_REPO_CONF}"
fi

if [ ${MODE} == "url" ]; then
cat >${YUM_REPOS_PATH}/${URL_REPO_CONF} <<EOF
cat >${YUM_REPOS_PATH}/${YUM_URL_REPO_CONF} <<EOF
[kubean-extra]
name=Kubean Extra Repo
baseurl=${REPO_BASE_URL}
enabled=1
gpgcheck=0
sslverify=0
EOF
echo "generate: ${YUM_REPOS_PATH}/${URL_REPO_CONF}"
echo "generate: ${YUM_REPOS_PATH}/${YUM_URL_REPO_CONF}"
fi
}

function backup_apt_repo() {
if [ $(ls -A ${APT_REPOS_DIR} | grep ${MARK_NAME} | wc -l) -eq 0 ]; then
mv ${APT_REPOS_DIR}{,.bak}
mkdir -p ${APT_REPOS_DIR}
fi
[ -f ${APT_REPOS_PATH} ] && mv ${APT_REPOS_PATH}{,.bak} || true
}

function get_apt_codename_from_os_release() {
echo "$(cat /etc/os-release | sed -n -r 's/^VERSION_CODENAME=|^UBUNTU_CODENAME=//p' | head -n1)"
}

function get_apt_codename_from_iso() {
for codename in $(find ${ISO_MOUNT_PATH}/dists/ -maxdepth 1 -type d -exec basename {} \;); do
[[ "${codename}" =~ xenial|bionic|focal|jammy ]] && { echo "${codename}"; return; }
done
echo $(get_apt_codename_from_os_release)
}

function generate_apt_repo() {
MODE=$1
echo "MODE: $MODE"
backup_apt_repo

if [ ${MODE} == "iso" ]; then
cat >${APT_REPOS_DIR}/${APT_ISO_REPO_CONF} <<EOF
deb file://${ISO_MOUNT_PATH} $(get_apt_codename_from_iso) main restricted
EOF
echo "generate: ${APT_REPOS_DIR}/${APT_ISO_REPO_CONF}"
fi

if [ ${MODE} == "url" ]; then
cat >${APT_REPOS_DIR}/${APT_URL_REPO_CONF} <<EOF
deb ${REPO_BASE_URL} $(get_apt_codename_from_os_release) main restricted
EOF
echo "generate: ${APT_REPOS_DIR}/${APT_URL_REPO_CONF}"
fi
}

Expand All @@ -109,7 +153,9 @@ function gen_repo_conf_with_iso() {
generate_yum_repo iso rhel
;;
debian | ubuntu)
echo "this linux distribution is temporarily not supported."
check_iso_img
mount_iso_file
generate_apt_repo iso
;;

*)
Expand All @@ -132,7 +178,8 @@ function gen_repo_conf_with_url() {
;;

debian | ubuntu)
echo "this linux distribution is temporarily not supported."
check_repo_url
generate_apt_repo url
;;

*)
Expand All @@ -146,14 +193,14 @@ function show_usage() {
cat <<EOF
Usage
$cmd [ -im | --iso-mode ] <linux_distribution> <iso_image_file>
$cmd [ -um | --url-mode ] <linux_distribution> <iso_image_file>
$cmd [ -um | --url-mode ] <linux_distribution> <repo_base_url>
Commands
-im, --iso-mode use the iso image as the repo source
-um, --url-mode use url as repo source
Arguments
linux_distribution supported for centos, redhat(rhel) only
linux_distribution supported for centos, redhat(rhel), ubuntu only
iso_image_file path to iso image file
repo_base_url url to access remote repo
Expand Down
13 changes: 13 additions & 0 deletions artifacts/import_iso.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ function unmount_iso_file() {

function iso_os_version_arch() {
for path in $(find $ISO_MOUNT_PATH); do
if [ -L "$path" ]; then
if echo "$path" | grep 'ubuntu' &>/dev/null; then
echo "/ubuntu-iso"
return
fi
fi
if [ -f "$path" ]; then
if echo "$path" | grep 'ky10.x86_64.rpm' >/dev/null 2>&1; then
echo "/kylin-iso/10/os/x86_64"
Expand Down Expand Up @@ -122,6 +128,13 @@ function import_iso_data() {
if [ -d "$ISO_MOUNT_PATH/AppStream" ]; then
dirArray+=("$ISO_MOUNT_PATH/AppStream")
fi

if [ -d "$ISO_MOUNT_PATH/dists" ]; then
dirArray+=("$ISO_MOUNT_PATH/dists")
fi
if [ -d "$ISO_MOUNT_PATH/pool" ]; then
dirArray+=("$ISO_MOUNT_PATH/pool")
fi

if [ "${#dirArray[@]}" -gt 0 ]; then
for dirName in "${dirArray[@]}"; do
Expand Down
2 changes: 1 addition & 1 deletion docs/zh/offline.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ $ MINIO_USER=${username} MINIO_PASS=${password} ./import_ospkgs.sh ${minio_addre
OS Packages 主要用于解决 docker-ce 的安装依赖, 但在实际的离线部署过程中, 可能还需要使用到发行版系统的其他包, 此时需要建立本地
ISO 镜像源.

> 注: 我们需要提前下载主机对应的 ISO 系统发行版镜像, 当前仅支持 Centos 发行版的 ISO 镜像源创建;
> 注: 我们需要提前下载主机对应的 ISO 系统发行版镜像, 当前支持 Centos、Redhat、Ubuntu 发行版的 ISO 镜像源创建;
这里可以使用脚本 `artifacts/gen_repo_conf.sh`, 执行如下命令即可挂载 ISO 镜像文件, 并创建 Repo 配置文件:

Expand Down

0 comments on commit ab2248b

Please sign in to comment.