diff --git a/README.md b/README.md index 6c57c6f..7d05e76 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Similar Project: [Backport OpenSSH for Debian / Ubuntu distros](https://github.c ## Supported (tested) Distro: -- CentOS 5/6/7/8/Stream 8 +- CentOS 5/6/7/8/Stream 8/9 - Amazon Linux 1/2/2023 - UnionTech OS Server 20 - openEuler 22.03 (LTS-SP1) @@ -36,14 +36,14 @@ yum install -y gcc44 1. Install build requirements listed above. 2. Edit `version.env` file if necessary. 3. Download source packages. -```bash -./pullsrc.sh -``` -if any error comes up, manally download the source files into the `downloads` dir. + ```bash + ./pullsrc.sh + ``` + if any error comes up, manually download the source files into the `downloads` dir. 4. Run the script to build RPMs. -```bash -./compile.sh -``` + ```bash + ./compile.sh + ``` ### Install RPMs diff --git a/compile.sh b/compile.sh index 05b6a2d..6cd228a 100755 --- a/compile.sh +++ b/compile.sh @@ -37,8 +37,9 @@ GUESS_DIST() { fi local dist=$(rpm --eval '%{?dist}' | tr -d '.') - + # fallback to el7 + [[ $dist == "el9" ]] && dist="el7" [[ $dist == "el8" ]] && dist="el7" [[ $dist == "an7" ]] && dist="el7" [[ $dist == "an8" ]] && dist="el7" @@ -145,7 +146,7 @@ if [[ -z $arg1 ]]; then rpm -q gcc44 && export CC=gcc44 ;; *) - echo "Distro undefined, please specify manualy: el5 el6 el7 amzn1 amzn2 amzn2023" + echo "Distro undefined, please specify manually: el5 el6 el7 amzn1 amzn2 amzn2023" echo -e "\nCurrent OS:" [[ -f /etc/os-release ]] && cat /etc/os-release [[ -f /etc/redhat-release ]] && cat /etc/redhat-release diff --git a/docker.README.md b/docker.README.md index 469057b..8a92141 100644 --- a/docker.README.md +++ b/docker.README.md @@ -23,9 +23,9 @@ COMPONENT="$SERVER/cloudteam/openssh-rpm-builder" ```shell # Specify build versions -VERSIONS=("7" "6" "5") +VERSIONS=("8" "7" "6" "5") # Define whether to enable Tsinghua University mirror source. (Very useful for Chinese users) -CHINA_MIRROR=0 # Setting this variable to non-zero means enabling +CHINA_MIRROR=1 # Setting this variable to non-zero means enabling for VERSION in "${VERSIONS[@]}" do @@ -45,7 +45,7 @@ echo 'The building has been completed!' ```shell # Specify build versions - VERSIONS=("7" "6" "5") + VERSIONS=("8" "7" "6" "5") for VERSION in "${VERSIONS[@]}" do @@ -63,6 +63,52 @@ echo 'The building has been completed!' echo 'Push has been completed!' ``` +#### CentOS Stream + +##### Build images + +```shell +# Specify build versions +VERSIONS=("9" "8") +# Define whether to enable Tsinghua University mirror source. (Very useful for Chinese users) +CHINA_MIRROR=1 # Setting this variable to non-zero means enabling + +for VERSION in "${VERSIONS[@]}" +do + echo "Building version: ${VERSION}" + # Build docker image + docker build \ + -t $COMPONENT:centos-stream$VERSION \ + --build-arg VERSION_NUM=$VERSION \ + --build-arg CHINA_MIRROR=$CHINA_MIRROR \ + -f docker/Dockerfile.centos-stream . +done + +echo 'The building has been completed!' +``` + +##### Push images + +```shell + # Specify build versions + VERSIONS=("9" "8") + + for VERSION in "${VERSIONS[@]}" + do + echo "Pushing version: ${VERSION}" + # Tag image + docker tag $COMPONENT:centos-stream$VERSION $COMPONENT:centos-stream.$VERSION + docker tag $COMPONENT:centos-stream$VERSION $COMPONENT:centos-stream.$VERSION.$(date +%Y%m%d) + docker tag $COMPONENT:centos-stream$VERSION $COMPONENT:el$VERSION + # Push image + docker push $COMPONENT:centos-stream$VERSION + docker push $COMPONENT:centos-stream.$VERSION + docker push $COMPONENT:centos-stream.$VERSION.$(date +%Y%m%d) + docker push $COMPONENT:el$VERSION + done + echo 'Push has been completed!' +``` + #### Amazon Linux ##### Build images @@ -71,7 +117,7 @@ echo 'The building has been completed!' # Specify build versions VERSIONS=("2023" "2" "1") # Define whether to enable China mirror source. (Very useful for Chinese users) -CHINA_MIRROR=0 # Setting this variable to non-zero means enabling +CHINA_MIRROR=1 # Setting this variable to non-zero means enabling for VERSION in "${VERSIONS[@]}" do @@ -135,7 +181,7 @@ docker run -it --rm \ OUT_PATH="$PWD" # Specify the name of tags. -IMAGE_TAGS=("amzn2023" "amzn2" "amzn1" "el7" "el6" "el5") +IMAGE_TAGS=("amzn2023" "amzn2" "amzn1" "el9" "el8" "el7" "el6" "el5") for IMAGE_TAG in "${IMAGE_TAGS[@]}" do diff --git a/docker/Dockerfile.amazonlinux b/docker/Dockerfile.amazonlinux index 79c44c9..3f141b1 100644 --- a/docker/Dockerfile.amazonlinux +++ b/docker/Dockerfile.amazonlinux @@ -21,6 +21,7 @@ RUN if [ "$CHINA_MIRROR" != "0" ]; then \ fi && \ yum groupinstall -y "Development Tools" && \ yum install -y rpm-build pam-devel krb5-devel zlib-devel libXt-devel libX11-devel perl perl-IPC-Cmd && \ + yum clean all && \ find . -type f -name '.keep' -delete && \ bash ./pullsrc.sh diff --git a/docker/Dockerfile.centos b/docker/Dockerfile.centos index bca44fc..c36b354 100644 --- a/docker/Dockerfile.centos +++ b/docker/Dockerfile.centos @@ -9,16 +9,32 @@ WORKDIR /data # Copy all files COPY . /data -RUN if [ "$CHINA_MIRROR" != "0" ]; then \ +RUN if [ "$VERSION_NUM" = "8" ]; then \ + MIRROR_URL="https://vault.centos.org" && \ + sed -e "s|^mirrorlist=|#mirrorlist=|g" \ + -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=${MIRROR_URL}/8.4.2105|g" \ + -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=${MIRROR_URL}/8.4.2105|g" \ + -i /etc/yum.repos.d/CentOS-*.repo; \ + elif [ "$VERSION_NUM" = "5" ]; then \ + MIRROR_URL="http://archive.kernel.org" && \ + sed -e "s|^mirrorlist=|#mirrorlist=|g" \ + -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=${MIRROR_URL}/centos-vault/5.11|g" \ + -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=${MIRROR_URL}/centos-vault/5.11|g" \ + -i.bak /etc/yum.repos.d/*.repo; \ + fi && \ + if [ "$CHINA_MIRROR" != "0" ]; then \ bash ./docker/modify_yum_source.sh; \ fi && \ - if [ "$VERSION_NUM" = "7" ] || [ "$VERSION_NUM" = "6" ]; then \ - yum install -y perl-IPC-Cmd; \ + if [ "$VERSION_NUM" = "8" ]; then \ + yum install -y perl perl-IPC-Cmd; \ + elif [ "$VERSION_NUM" = "7" ] || [ "$VERSION_NUM" = "6" ]; then \ + yum install -y perl-IPC-Cmd imake; \ elif [ "$VERSION_NUM" = "5" ]; then \ - yum install -y gcc44; \ + yum install -y gcc44 imake; \ fi && \ yum groupinstall -y "Development Tools" && \ - yum install -y imake rpm-build pam-devel krb5-devel zlib-devel libXt-devel libX11-devel gtk2-devel && \ + yum install -y rpm-build pam-devel krb5-devel zlib-devel libXt-devel libX11-devel gtk2-devel && \ + yum clean all && \ find . -type f -name '.keep' -delete && \ LINE_NO=$(grep -n -- "--define 'skip_x11_askpass 1'" /data/compile.sh | cut -d: -f1) && \ sed -i "$LINE_NO a\--define \"debug_package %{nil}\" \\\\" ./compile.sh && \ diff --git a/docker/Dockerfile.centos-stream b/docker/Dockerfile.centos-stream new file mode 100644 index 0000000..46419a7 --- /dev/null +++ b/docker/Dockerfile.centos-stream @@ -0,0 +1,25 @@ +# Official: https://quay.io/repository/centos/centos?tab=tags +ARG VERSION_NUM="9" +FROM quay.io/centos/centos:stream$VERSION_NUM +ARG CHINA_MIRROR=0 +LABEL Author="Rex Zhou " + +WORKDIR /data + +# Copy all files +COPY . /data + +RUN if [ "$CHINA_MIRROR" != "0" ]; then \ + yum install -y perl && \ + perl /data/docker/modify_dnf_source.pl /etc/yum.repos.d/*.repo; \ + fi && \ + yum clean all && yum makecache && \ + yum groupinstall -y "Development Tools" && \ + yum install -y rpm-build pam-devel krb5-devel zlib-devel libXt-devel libX11-devel gtk2-devel && \ + yum clean all && \ + find . -type f -name '.keep' -delete && \ + LINE_NO=$(grep -n -- "--define 'skip_x11_askpass 1'" /data/compile.sh | cut -d: -f1) && \ + sed -i "$LINE_NO a\--define \"debug_package %{nil}\" \\\\" ./compile.sh && \ + bash ./pullsrc.sh + +CMD ["bash", "/data/compile.sh"] \ No newline at end of file diff --git a/docker/modify_dnf_source.pl b/docker/modify_dnf_source.pl new file mode 100644 index 0000000..ab843d4 --- /dev/null +++ b/docker/modify_dnf_source.pl @@ -0,0 +1,37 @@ +#!/usr/bin/perl + +use strict; +use warnings; +use autodie; + +my $mirrors = 'https://mirrors.tuna.tsinghua.edu.cn/centos-stream'; + +if (@ARGV < 1) { + die "Usage: $0 ...\n"; +} + +while (my $filename = shift @ARGV) { + my $backup_filename = $filename . '.bak'; + rename $filename, $backup_filename; + + open my $input, "<", $backup_filename; + open my $output, ">", $filename; + + while (<$input>) { + s/^metalink/# metalink/; + + if (m/^name/) { + my (undef, $repo, $arch) = split /-/; + $repo =~ s/^\s+|\s+$//g; + ($arch = defined $arch ? lc($arch) : '') =~ s/^\s+|\s+$//g; + + if ($repo =~ /^Extras/) { + $_ .= "baseurl=${mirrors}/SIGs/\$releasever-stream/extras" . ($arch eq 'source' ? "/${arch}/" : "/\$basearch/") . "extras-common\n"; + } else { + $_ .= "baseurl=${mirrors}/\$releasever-stream/$repo" . ($arch eq 'source' ? "/" : "/\$basearch/") . ($arch ne '' ? "${arch}/tree/" : "os") . "\n"; + } + } + + print $output $_; + } +} \ No newline at end of file diff --git a/docker/modify_yum_source.sh b/docker/modify_yum_source.sh index f5bc414..3be8459 100644 --- a/docker/modify_yum_source.sh +++ b/docker/modify_yum_source.sh @@ -7,10 +7,17 @@ RELEASE_VER=$(rpm --eval '%{?dist}') [ -z "$RELEASE_VER" ] && RELEASE_VER=".el5" -MIRROR_URL="https://mirrors.tuna.tsinghua.edu.cn" +MIRROR_URL="http://mirrors.tuna.tsinghua.edu.cn" AWS_REGION="cn-northwest-1" case $RELEASE_VER in + .el8) + sed -e "s|^mirrorlist=|#mirrorlist=|g" \ + -e "s|^baseurl=https://vault.centos.org|baseurl=${MIRROR_URL}/centos-vault|g" \ + -i.bak /etc/yum.repos.d/CentOS-*.repo && \ + rm -rf /var/cache/yum/ && \ + yum makecache timer + ;; .el7) sed -e 's|^mirrorlist=|#mirrorlist=|g' \ -e "s|^#baseurl=http://mirror.centos.org/centos|baseurl=${MIRROR_URL}/centos|g" \ @@ -22,17 +29,14 @@ case $RELEASE_VER in sed -e "s|^mirrorlist=|#mirrorlist=|g" \ -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=${MIRROR_URL}/centos-vault/6.10|g" \ -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=${MIRROR_URL}/centos-vault/6.10|g" \ - -i.bak \ - /etc/yum.repos.d/CentOS-*.repo && \ + -i.bak /etc/yum.repos.d/CentOS-*.repo && \ rm -rf /var/cache/yum/ && \ yum makecache fast ;; .el5) sed -e "s|^mirrorlist=|#mirrorlist=|g" \ - -e "s|^#baseurl=http://mirror.centos.org/centos/\$releasever|baseurl=${MIRROR_URL}/centos-vault/5.11|g" \ - -e "s|^#baseurl=http://mirror.centos.org/\$contentdir/\$releasever|baseurl=${MIRROR_URL}/centos-vault/5.11|g" \ - -i.bak \ - /etc/yum.repos.d/*.repo && \ + -e "s|^baseurl=http://archive.kernel.org|baseurl=${MIRROR_URL}|g" \ + -i.bak /etc/yum.repos.d/*.repo && \ rm -rf /var/cache/yum/ && \ yum makecache fast ;; @@ -44,6 +48,9 @@ case $RELEASE_VER in echo "amazonaws.com.cn" > /etc/yum/vars/awsdomain echo "$AWS_REGION" > /etc/yum/vars/awsregion ;; + .amzn2023) + echo "Amazon Linux 2023 is NOT need to change any settings." + ;; *) echo "rpm dist undefined, please specify: el5 el6 el7" exit 1