-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
71 additions
and
4 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.gitignore |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ vendor | |
work | ||
.vscode/ | ||
.coverage* | ||
.git |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
FROM alpine:latest | ||
|
||
EXPOSE 3080 | ||
EXPOSE 3081 | ||
EXPOSE 6000 | ||
|
||
ADD ./ proxy | ||
RUN sh ./proxy/docker/apk-fastest-mirror.sh | ||
RUN apk add git make go | ||
RUN cd proxy && make build && cp bin/* /bin/ && cp -a conf /etc/proxy && cd .. && rm -rf proxy | ||
RUN apk del git make go |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/bin/sh | ||
# shellcheck disable=SC3043 | ||
|
||
get_hostname_url() { | ||
local n | ||
n="${1#*://}" | ||
echo "${n%%/*}" | ||
} | ||
|
||
time_cmd() { | ||
local proc start end | ||
|
||
proc=$(cut -d ' ' -f1 /proc/uptime) | ||
start="$(echo "$proc" | cut -d . -f1)$(echo "$proc" | cut -d . -f2)" | ||
"$@" >/dev/null 2>&1 || return | ||
proc=$(cut -d ' ' -f1 /proc/uptime) | ||
end="$(echo "$proc" | cut -d . -f1)$(echo "$proc" | cut -d . -f2)" | ||
echo $((end - start)) | ||
} | ||
|
||
DATA="" | ||
MIRRORS=$(wget -qO- "http://rsync.alpinelinux.org/alpine/MIRRORS.txt") | ||
DST=/etc/apk/mirrors.txt | ||
|
||
#find best | ||
for URL in $MIRRORS; do | ||
TIME=$(time_cmd wget -T 1 -t 1 -q "${URL%/}" -O /dev/null) | ||
|
||
if [ -n "$TIME" ]; then | ||
echo "$(get_hostname_url "$URL") was $TIME" | ||
DATA="$DATA$TIME $URL\n" | ||
if [ "$TIME" -lt "50" ]; then | ||
break | ||
fi | ||
fi | ||
|
||
done | ||
|
||
if printf '%b' "$DATA" | sort -n | tail -n +2 > $DST; then | ||
echo file $DST created | ||
fi | ||
|
||
BEST=$(head -n1 $DST | cut -d ' ' -f2) | ||
echo "Best mirror is: $BEST" | ||
|
||
sed -i -r 's#^http.+/(.+/main)#'"${BEST%/}"'/\1#' /etc/apk/repositories | ||
sed -i -r 's#^http.+/(.+/community)#'"${BEST%/}"'/\1#' /etc/apk/repositories | ||
sed -i -r 's#^http.+/(.+/testing)#'"${BEST%/}"'/\1#' /etc/apk/repositories |
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