From ac8329fecd823230d52991ba8f73570e60b76972 Mon Sep 17 00:00:00 2001 From: Terry Chen Date: Fri, 28 Apr 2017 00:56:18 +0800 Subject: [PATCH] fix #1 https isn't handle correctly in setup.sh --- Dockerfile | 16 +++++++-------- README.md | 11 +++++++++-- setup.sh | 57 +++++++++++++++++++++++++++++------------------------- 3 files changed, 47 insertions(+), 37 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0d67a6e..4556cf2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,16 +1,14 @@ -FROM ubuntu:14.04 +FROM ubuntu:16.04 MAINTAINER Terry Chen ENV DEBIAN_FRONTEND noninteractive -ENV TIMEOUT 12h -ENV MIRROR_URL http://archive.ubuntu.com/ubuntu +ENV RESYNC_PERIOD 12h -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/* +RUN apt-get update \ + && apt-get install --no-install-recommends -y apt-mirror apache2 \ + && mv /etc/apt/mirror.list / \ + && apt-get autoclean \ + && rm -rf /var/lib/apt/lists/* EXPOSE 80 COPY setup.sh /setup.sh diff --git a/README.md b/README.md index fbb0c6e..1b51d9c 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,12 @@ docker run -d \ ### More options with docker command * `-v /path/your/mirror.list:/etc/apt/mirror.list`: to replace [Ubuntu default mirror.list](https://github.com/seterrychen/apt-mirror-http-server/blob/master/mirror.list) -* `-e MIRROR_URL=http://tw.archive.ubuntu.com/ubuntu`: to overwrite the mirror.list when you use this option to specify the mirror site -* `-e TIMEOUT=timeout-value`: to set the resync period, default is 12 hours. To set the [TIMEOUT format description](http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/) +* `-e RESYNC_PERIOD=timeout-value`: to set the resync period, default is 12 hours. To set the [TIMEOUT format description](http://www.cyberciti.biz/faq/linux-unix-sleep-bash-scripting/) + +## Changelog + +* 2017-04-27: version 0.1 + * Update base image to Ubuntu 16.04 + * remove option `MIRROR_URL` + * rename `TIMEOUT` environment value to `RESYNC_PERIOD` + * fix issue [#1 https isn't handle correctly in setup.sh](https://github.com/seterrychen/apt-mirror-http-server/issues/1) diff --git a/setup.sh b/setup.sh index 5128e25..3b7b07c 100755 --- a/setup.sh +++ b/setup.sh @@ -1,41 +1,46 @@ #!/bin/bash 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:\/\//''} - target='/var/www/package/' + grep '^deb' /etc/apt/mirror.list | awk '{print $2}' | while IFS= read -r line + do + local mirror_path= + mirror_path=$(echo "$line" | sed -e 's|^ftp||' -e 's|^https\?||' -e 's|^rsync||' -e 's|://||' -e 's|/$||') + local target="/var/www/package" - IFS='/' read -a distName <<< "$url" - dest=$target${distName[-1]} - if [ ! -h $dest ]; then - echo "Create $dest" - ln -s /var/spool/apt-mirror/mirror/$url $dest + local dest= + case "$line" in + *ubuntu*) + dest="$target/ubuntu" + ;; + *debian*) + dest="$target/debian" + ;; + esac + if [ ! -h "$dest" ] && [ x"$dest" != x"" ]; then + echo "[$(date)] Create $dest" + ln -s "/var/spool/apt-mirror/mirror/$mirror_path" "$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 +# To setup http server config at first time +if [ ! -d /var/www/package ]; then + mkdir -p /var/www/package + sed -i '12s|DocumentRoot /var/www/html|DocumentRoot /var/www/package|' /etc/apache2/sites-enabled/000-default.conf + service apache2 restart >/dev/null -# 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 and apt source is: $MIRROR_URL" - ln -s /mirror.list /etc/apt/mirror.list - sed -i "s|http://archive.ubuntu.com/ubuntu|$MIRROR_URL|g" /etc/apt/mirror.list + # If user doesn't provide mirror.list, using default setting + if [ ! -e /etc/apt/mirror.list ]; then + echo "[$(date)] Using default mirror.list" + ln -s /mirror.list /etc/apt/mirror.list + fi create_link - need_create_line=false fi while true; do - if $need_create_line; then - create_link - fi - printf "\n\n====== Starting apt-mirror ======\n\n" + echo "[$(date)] Starting apt-mirror" apt-mirror - printf "\n\n====== Completed ======\n\n" - printf "====== Sleeping $TIMEOUT to execute apt-mirror again ======\n\n" - sleep $TIMEOUT + echo "[$(date)] Completed" + echo "[$(date)] Sleeping $RESYNC_PERIOD to execute apt-mirror again ======" + sleep "$RESYNC_PERIOD" done