Commit 291d078e authored by Natanael Copa's avatar Natanael Copa

setup-apkrepos: improve $ROOT support

parent b4ddb7ef
...@@ -5,6 +5,9 @@ PREFIX= ...@@ -5,6 +5,9 @@ PREFIX=
. $PREFIX/lib/libalpine.sh . $PREFIX/lib/libalpine.sh
if [ "$ROOT" != "/" ]; then
apk_root_opt="--root $ROOT"
fi
get_hostname_from_url() { get_hostname_from_url() {
local n=${1#*://} local n=${1#*://}
...@@ -14,7 +17,7 @@ get_hostname_from_url() { ...@@ -14,7 +17,7 @@ get_hostname_from_url() {
prompt_setup_method() { prompt_setup_method() {
echo "r) Add random from the above list" echo "r) Add random from the above list"
echo "f) Detect and add fastest mirror from above list" echo "f) Detect and add fastest mirror from above list"
echo "e) Edit /etc/apk/repositores with text editor" echo "e) Edit "${ROOT}"etc/apk/repositores with text editor"
echo "" echo ""
echo -n "Enter mirror number (1-$mirror_count) or URL to add (or r/f/e/done) [$1]: " echo -n "Enter mirror number (1-$mirror_count) or URL to add (or r/f/e/done) [$1]: "
} }
...@@ -44,7 +47,7 @@ find_fastest_mirror() { ...@@ -44,7 +47,7 @@ find_fastest_mirror() {
export http_proxy= export http_proxy=
local url= local url=
for url in $MIRRORS; do for url in $MIRRORS; do
echo $(time_cmd apk update --quiet \ echo $(time_cmd apk update --quiet $apk_root_opt \
--repository $url/edge/main \ --repository $url/edge/main \
--repositories-file /dev/null) $url --repositories-file /dev/null) $url
done | awk ' { done | awk ' {
...@@ -94,7 +97,7 @@ add_from_list() { ...@@ -94,7 +97,7 @@ add_from_list() {
} }
get_alpine_release() { get_alpine_release() {
local version=$(cat /etc/alpine-release 2>/dev/null) local version=$(cat "${ROOT}"etc/alpine-release 2>/dev/null)
case "$version" in case "$version" in
*_git*|*_alpha*) release="edge";; *_git*|*_alpha*) release="edge";;
[0-9]*.[0-9]*.[0-9]*) [0-9]*.[0-9]*.[0-9]*)
...@@ -107,6 +110,7 @@ get_alpine_release() { ...@@ -107,6 +110,7 @@ get_alpine_release() {
add_mirror() { add_mirror() {
local mirror="$1" local mirror="$1"
mkdir -p "${APKREPOS_PATH%/*}"
echo "${mirror%/}/${release}/main" >> $APKREPOS_PATH echo "${mirror%/}/${release}/main" >> $APKREPOS_PATH
case "$release" in case "$release" in
v[0-9]*) v[0-9]*)
...@@ -118,15 +122,17 @@ add_mirror() { ...@@ -118,15 +122,17 @@ add_mirror() {
} }
add_from_url() { add_from_url() {
mkdir -p "${APKREPOS_PATH%/*}"
echo "$1" >> $APKREPOS_PATH echo "$1" >> $APKREPOS_PATH
echo "" >> $APKREPOS_PATH echo "" >> $APKREPOS_PATH
} }
edit_repositories() { edit_repositories() {
local md5=$(md5sum $APKREPOS_PATH) local md5=$(md5sum $APKREPOS_PATH 2>/dev/null)
mkdir -p "${APKREPOS_PATH%/*}"
${EDITOR:-vi} "$APKREPOS_PATH" ${EDITOR:-vi} "$APKREPOS_PATH"
# return true if file changed # return true if file changed
test "$(md5sum $APKREPOS_PATH)" != "$md5" test "$(md5sum $APKREPOS_PATH 2>/dev/null)" != "$md5"
} }
usage() { usage() {
...@@ -155,8 +161,8 @@ done ...@@ -155,8 +161,8 @@ done
# install alpine-mirrors if its not already there # install alpine-mirrors if its not already there
to_uninstall= to_uninstall=
if ! apk info --quiet --installed alpine-mirrors; then if ! apk info --quiet --installed alpine-mirrors; then
apk add --quiet alpine-mirrors apk add --quiet --virtual .setup-apkrepos alpine-mirrors
to_uninstall=alpine-mirrors to_uninstall=.setup-apkrepos
fi fi
MIRRORS_PATH=/usr/share/alpine-mirrors/MIRRORS.txt MIRRORS_PATH=/usr/share/alpine-mirrors/MIRRORS.txt
...@@ -164,7 +170,7 @@ if [ -z "$MIRRORS" ] && [ -r "$MIRRORS_PATH" ]; then ...@@ -164,7 +170,7 @@ if [ -z "$MIRRORS" ] && [ -r "$MIRRORS_PATH" ]; then
MIRRORS=`cat $MIRRORS_PATH` MIRRORS=`cat $MIRRORS_PATH`
fi fi
APKREPOS_PATH=/etc/apk/repositories APKREPOS_PATH="${ROOT}"etc/apk/repositories
if [ -r "$APKREPOS_PATH" ]; then if [ -r "$APKREPOS_PATH" ]; then
APKREPOS=`cat "$APKREPOS_PATH"` APKREPOS=`cat "$APKREPOS_PATH"`
fi fi
...@@ -199,7 +205,7 @@ done ...@@ -199,7 +205,7 @@ done
if [ -n "$changed" ]; then if [ -n "$changed" ]; then
echo -n "Updating repository indexes... " echo -n "Updating repository indexes... "
apk update --quiet && echo "done." apk update --quiet $apk_root_opt && echo "done."
fi fi
# clean up # clean up
......
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