Commit 677b92a0 authored by Natanael Copa's avatar Natanael Copa

setup-apkrepos: minor cleanup

- allow override MIRRORS via env var
- don't error if MIRRORS.txt is missing
- other minor cleanups
parent 04685637
...@@ -6,13 +6,19 @@ PREFIX= ...@@ -6,13 +6,19 @@ PREFIX=
. $PREFIX/lib/libalpine.sh . $PREFIX/lib/libalpine.sh
MIRRORS_PATH=/usr/share/alpine-mirrors/MIRRORS.txt MIRRORS_PATH=/usr/share/alpine-mirrors/MIRRORS.txt
MIRRORS=`cat $MIRRORS_PATH` if [ -z "$MIRRORS" ] && [ -r "$MIRRORS_PATH" ]; then
MIRRORS=`cat $MIRRORS_PATH`
fi
RELEASES_PATH=/usr/share/alpine-mirrors/RELEASES.txt RELEASES_PATH=/usr/share/alpine-mirrors/RELEASES.txt
RELEASES=`cat $RELEASES_PATH` if [ -z "$RELEASES" ] && [ -r "$RELEASES_PATH" ]; then
RELEASES=`cat $RELEASES_PATH`
fi
APKREPOS_PATH=/etc/apk/repositories APKREPOS_PATH=/etc/apk/repositories
APKREPOS=`cat "$APKREPOS_PATH"` if [ -r "$APKREPOS_PATH" ]; then
APKREPOS=`cat "$APKREPOS_PATH"`
fi
prompt_setup_method() { prompt_setup_method() {
while true; do while true; do
...@@ -84,6 +90,11 @@ get_fastest_mirror() { ...@@ -84,6 +90,11 @@ get_fastest_mirror() {
mirror=$mirror_lowest_rtt_mirror mirror=$mirror_lowest_rtt_mirror
} }
get_hostname_from_url() {
local n=${1#*://}
echo ${n%%/*}
}
prompt_mirror_list() { prompt_mirror_list() {
local i local i
local mirror_hostname local mirror_hostname
...@@ -91,12 +102,11 @@ prompt_mirror_list() { ...@@ -91,12 +102,11 @@ prompt_mirror_list() {
local mirror_count=`echo $MIRRORS | sed 's/ /\n/g' | wc -l` local mirror_count=`echo $MIRRORS | sed 's/ /\n/g' | wc -l`
while true; do while true; do
echo -en "\n" echo ""
i=1 i=1
for mirror in $MIRRORS; do for mirror in $MIRRORS; do
mirror_hostname=`echo $mirror | awk -F '://' '{print $2}' | awk -F '/' '{print $1}'` echo "$i) $(get_hostname_from_url $mirror)"
echo "$i) $mirror_hostname" i=$(($i + 1))
i=`expr $i + 1`
done done
echo -en "\nPlease select a mirror from the above list: " echo -en "\nPlease select a mirror from the above list: "
...@@ -111,11 +121,8 @@ prompt_mirror_list() { ...@@ -111,11 +121,8 @@ prompt_mirror_list() {
done done
set $MIRRORS set $MIRRORS
_tmp="\$$mirror_index" eval "mirror=\$$mirror_index"
mirror=`eval echo $_tmp` echo "Mirror chosen: $(get_hostname_from_url $mirror)"
mirror_hostname=`echo $mirror | awk -F '://' '{print $2}' | awk -F '/' '{print $1}'`
echo "Mirror chosen: $mirror_hostname"
} }
add_repo() { add_repo() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment