Created
December 24, 2018 11:29
-
-
Save harasou/460efe82c0e3a0e57eb9e28080ece471 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -exv | |
readonly MAINTAINER="harasou <harasou5@gmail.com>" | |
readonly REPOSITORY="harasou/centos-core" | |
function usage(){ | |
cat<<EOD 1>&2 | |
Usage: | |
$0 version | |
Examples: | |
$0 6.4 | |
$0 7.6.1810 | |
EOD | |
exit 1 | |
} | |
readonly version=$1 | |
readonly workdir="$(cd $(dirname $0) && pwd)/centos-core-$version" | |
readonly repodir="$workdir/etc/yum.repos.d" | |
readonly rootdir="$workdir/root" | |
mkdir -p $repodir $rootdir | |
cd $rootdir | |
url="http://ftp.jaist.ac.jp/pub/Linux/CentOS/$version/isos/x86_64"; curl -sf $url || | |
url="http://ftp.jaist.ac.jp/pub/Linux/CentOS-vault/$version/isos/x86_64"; curl -sf $url || | |
url="http://archive.kernel.org/centos-vault/$version/isos/x86_64" | |
readonly releasever=${version%%.*} | |
case $releasever in | |
6) readonly iso="CentOS-$version-x86_64-minimal.iso" | |
;; | |
7) readonly releaseday=${version##*.} | |
readonly iso="CentOS-$releasever-x86_64-Minimal-$releaseday.iso" | |
;; | |
*) usage | |
;; | |
esac | |
# | |
# download iso image | |
# | |
[ -f "$iso" ] || curl -O $url/$iso | |
expect=$(curl $url/sha256sum.txt|grep $iso) | |
test "$expect" == "$(shasum -a 256 $iso)" | |
# | |
# create /etc/yum.repos.d/CentOS-ISO.repo | |
# | |
isomountpoint="/mnt" | |
cat<<EOD>$repodir/CentOS-ISO.repo | |
[iso] | |
name=CentOS-$releasever - ISO | |
baseurl=file://$isomountpoint | |
enabled=1 | |
gpgcheck=1 | |
gpgkey=file://$isomountpoint/RPM-GPG-KEY-CentOS-$releasever | |
EOD | |
# | |
# create make world scripts | |
# | |
mkworld="mkworld" | |
cat<<EOC>$mkworld | |
#!/bin/bash -exv | |
mount -o loop /root/$iso $isomountpoint | |
yum --installroot='/tmp/root' --skip-broken --exclude='*-firmware' groupinstall Core -y | |
$( [ $releasever -eq 6 ] && echo "chroot /tmp/root rpm --rebuilddb") | |
tar zcvf /root/centos-core-$releasever.tar.gz -C /tmp/root . | |
EOC | |
# | |
# groupinstall from iso image on container | |
# | |
docker container run --privileged -it --rm \ | |
-v $repodir:/etc/yum.repos.d \ | |
-v $rootdir:/root \ | |
centos \ | |
/bin/bash -exv /root/$mkworld | |
# | |
# build docker image from groupinstall | |
# | |
cat<<EOD>Dockerfile | |
FROM scratch | |
MAINTAINER $MAINTAINER | |
ADD centos-core-$releasever.tar.gz / | |
CMD ["/bin/bash"] | |
EOD | |
docker build -t $REPOSITORY:$version . |
Author
harasou
commented
Dec 24, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment