From 85eb8318fa79dc3b8fe459a1e396cf179971dcdf Mon Sep 17 00:00:00 2001 From: Terry Chen Date: Tue, 18 Aug 2015 14:21:07 +0800 Subject: [PATCH] add ENV MIRROR_URL to replace apt sources of default mirror.list --- Dockerfile | 5 ++++- README.md | 13 +++++++++++-- mirror.list | 22 +++++++++++----------- setup.sh | 32 ++++++++++++++++++++++---------- 4 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Dockerfile b/Dockerfile index 978e13d..860c71d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,17 @@ MAINTAINER Terry Chen ENV DEBIAN_FRONTEND noninteractive ENV TIMEOUT 12h +ENV MIRROR_URL http://tw.archive.ubuntu.com/ubuntu RUN \ apt-get update && \ apt-get install -y apt-mirror apache2 && \ apt-get clean && \ + mv /etc/apt/mirror.list / && \ rm -rf /var/lib/apt/lists/* -VOLUME /etc/apt EXPOSE 80 COPY setup.sh /setup.sh + +VOLUME ["/etc/apt", "/var/spool/apt-mirror"] CMD ["/bin/bash", "setup.sh"] diff --git a/README.md b/README.md index 9977909..c73b2bc 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,17 @@ docker run -v /path/data:/var/spool/apt-mirror \ ``` /path/data is where to store data, and the TIMEOUT var to repeatedly execute apt-mirror. -If you don't setting variable of mirror.list and TIMEOUT, it will using the default [mirror.list](mirror.list), and -the default TIMEOUT is 6 hours. To see the [TIMEOUT format description](http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/) +If you don't setting variable of mirror.list and TIMEOUT, it will using the [default mirror.list](mirror.list), and +the default TIMEOUT is 12 hours. To see the [TIMEOUT format description](http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/). + +Or running command +``` +docker run -v /path/data:/var/spool/apt-mirror \ + -e MIRROR_URL=http://tw.archive.ubuntu.com/ubuntu \ + -e TIMEOUT=timeout-value \ + -d -p port_number:80 seterrychen/apt-mirror-http-server +``` +MIRROR_URL can used to replace apt sources of [default mirror.list](mirror.list) ## Note It will take time to download, then start http server. Using ``docker logs -f container-id`` to check the process. diff --git a/mirror.list b/mirror.list index b2a7d77..498930e 100644 --- a/mirror.list +++ b/mirror.list @@ -14,16 +14,16 @@ set _tilde 0 # ############# end config ############## -deb http://tw.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse -deb http://tw.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse -deb http://tw.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse -#deb http://tw.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse -#deb http://tw.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse +deb http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse +deb http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse +deb http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse +#deb http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse +#deb http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse -deb-src http://tw.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse -deb-src http://tw.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse -deb-src http://tw.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse -#deb-src http://tw.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse -#deb-src http://tw.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse +deb-src http://archive.ubuntu.com/ubuntu trusty main restricted universe multiverse +deb-src http://archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse +deb-src http://archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse +#deb-src http://archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse +#deb-src http://archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse -clean http://tw.archive.ubuntu.com/ubuntu +clean http://archive.ubuntu.com/ubuntu diff --git a/setup.sh b/setup.sh index 9c0c6b7..6c81870 100755 --- a/setup.sh +++ b/setup.sh @@ -1,12 +1,5 @@ #!/bin/bash - -# read mirror.list to link /var/www/package folder -mkdir /var/www/package -sed -i '12s/DocumentRoot \/var\/www\/html/DocumentRoot \/var\/www\/package/' /etc/apache2/sites-enabled/000-default.conf -service apache2 restart - -while true; do - +function create_link { # parse mirror.list to share under /var/www/package path for i in `egrep -o '(rsync|ftp|https?)://[^ ]+' /etc/apt/mirror.list`; do url=${i/http:\/\//''} @@ -15,13 +8,32 @@ while true; do IFS='/' read -a distName <<< "$url" dest=$target${distName[-1]} if [ ! -h $dest ]; then - echo "create $dest" + echo "Create $dest" ln -s /var/spool/apt-mirror/mirror/$url $dest fi done +} +# read mirror.list to link /var/www/package folder +mkdir /var/www/package +sed -i '12s|DocumentRoot /var/www/html|DocumentRoot /var/www/package|' /etc/apache2/sites-enabled/000-default.conf +service apache2 restart + +# If user doesn't provide mirror.list, using default setting +need_create_line=true +if [ ! -e /etc/apt/mirror.list ]; then + echo "Using default mirror.list" + ln -s /mirror.list /etc/apt/mirror.list + sed -i "s|http://archive.ubuntu.com/ubuntu|$MIRROR_URL|g" /etc/apt/mirror.list + create_link + need_create_line=false +fi + +while true; do + if $need_create_line; then + create_link + fi apt-mirror printf "\n\n====== wait $TIMEOUT to execute apt-mirror again ======\n\n" sleep $TIMEOUT - done