fix #1 https isn't handle correctly in setup.sh

This commit is contained in:
Terry Chen 2017-04-28 00:56:18 +08:00
parent af0f82107a
commit ac8329fecd
3 changed files with 47 additions and 37 deletions

View File

@ -1,16 +1,14 @@
FROM ubuntu:14.04 FROM ubuntu:16.04
MAINTAINER Terry Chen <seterrychen@gmail.com> MAINTAINER Terry Chen <seterrychen@gmail.com>
ENV DEBIAN_FRONTEND noninteractive ENV DEBIAN_FRONTEND noninteractive
ENV TIMEOUT 12h ENV RESYNC_PERIOD 12h
ENV MIRROR_URL http://archive.ubuntu.com/ubuntu
RUN \ RUN apt-get update \
apt-get update && \ && apt-get install --no-install-recommends -y apt-mirror apache2 \
apt-get install -y apt-mirror apache2 && \ && mv /etc/apt/mirror.list / \
apt-get clean && \ && apt-get autoclean \
mv /etc/apt/mirror.list / && \ && rm -rf /var/lib/apt/lists/*
rm -rf /var/lib/apt/lists/*
EXPOSE 80 EXPOSE 80
COPY setup.sh /setup.sh COPY setup.sh /setup.sh

View File

@ -20,5 +20,12 @@ docker run -d \
### More options with docker command ### 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) * `-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 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/)
* `-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/)
## 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)

View File

@ -1,41 +1,46 @@
#!/bin/bash #!/bin/bash
function create_link { function create_link {
# parse mirror.list to share under /var/www/package path # parse mirror.list to share under /var/www/package path
for i in `egrep -o '(rsync|ftp|https?)://[^ ]+' /etc/apt/mirror.list`; do grep '^deb' /etc/apt/mirror.list | awk '{print $2}' | while IFS= read -r line
url=${i/http:\/\//''} do
target='/var/www/package/' 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" local dest=
dest=$target${distName[-1]} case "$line" in
if [ ! -h $dest ]; then *ubuntu*)
echo "Create $dest" dest="$target/ubuntu"
ln -s /var/spool/apt-mirror/mirror/$url $dest ;;
*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 fi
done done
} }
# read mirror.list to link /var/www/package folder # To setup http server config at first time
mkdir /var/www/package if [ ! -d /var/www/package ]; then
sed -i '12s|DocumentRoot /var/www/html|DocumentRoot /var/www/package|' /etc/apache2/sites-enabled/000-default.conf mkdir -p /var/www/package
service apache2 restart 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 # If user doesn't provide mirror.list, using default setting
need_create_line=true if [ ! -e /etc/apt/mirror.list ]; then
if [ ! -e /etc/apt/mirror.list ]; then echo "[$(date)] Using default mirror.list"
echo "Using default mirror.list and apt source is: $MIRROR_URL" ln -s /mirror.list /etc/apt/mirror.list
ln -s /mirror.list /etc/apt/mirror.list fi
sed -i "s|http://archive.ubuntu.com/ubuntu|$MIRROR_URL|g" /etc/apt/mirror.list
create_link create_link
need_create_line=false
fi fi
while true; do while true; do
if $need_create_line; then echo "[$(date)] Starting apt-mirror"
create_link
fi
printf "\n\n====== Starting apt-mirror ======\n\n"
apt-mirror apt-mirror
printf "\n\n====== Completed ======\n\n" echo "[$(date)] Completed"
printf "====== Sleeping $TIMEOUT to execute apt-mirror again ======\n\n" echo "[$(date)] Sleeping $RESYNC_PERIOD to execute apt-mirror again ======"
sleep $TIMEOUT sleep "$RESYNC_PERIOD"
done done