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>
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

View File

@ -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)

View File

@ -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
# 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
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"
echo "[$(date)] 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
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