aboutsummaryrefslogtreecommitdiffstats
path: root/main/alpine-conf/0001-setup-apkrepos-allow-specify-the-repos-from-cmdline.patch
blob: 81a8beb9d9f533cd246f9521b5d1ab16f720eb59 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
From a5ad7c4c0a1e649033699a3ba832c3810fb576dc Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Tue, 1 Jul 2014 11:01:09 +0200
Subject: [PATCH] setup-apkrepos: allow specify the repos from cmdline

ref #2862
---
 setup-apkrepos.in | 60 ++++++++++++++++++++++++++++++-------------------------
 1 file changed, 33 insertions(+), 27 deletions(-)

diff --git a/setup-apkrepos.in b/setup-apkrepos.in
index 7744d8b..e29572e 100644
--- a/setup-apkrepos.in
+++ b/setup-apkrepos.in
@@ -137,7 +137,7 @@ edit_repositories() {
 
 usage() {
 	cat <<__EOF__
-usage: setup-apkrepos [-hr]
+usage: setup-apkrepos [-hr] [REPO...]
 
 Setup apk repositories
 
@@ -155,7 +155,7 @@ while getopts "hr" opt; do
                 r) JUSTADDRANDOM=1;;
         esac
 done
-
+shift $(($OPTIND - 1))
 
 # main
 # install alpine-mirrors if its not already there
@@ -175,35 +175,41 @@ if [ -r "$APKREPOS_PATH" ]; then
 	APKREPOS=`cat "$APKREPOS_PATH"`
 fi
 
-
-
 get_alpine_release
 default_answer=f
-changed=
-while true; do
-	if [ -n "$JUSTADDRANDOM" ]; then
-		show_mirror_list > /dev/null
-		add_random_mirror && changed=1 && break
-	else
-		show_mirror_list
-		prompt_setup_method $default_answer
-
-		default_read answer $default_answer
-		case "$answer" in
-			"done") break;;
-			[0-9]*) add_from_list $answer && changed=1;;
-			/*|http://*|ftp://*|https://*) add_from_url "$answer" && changed=1;;
-			r) add_random_mirror && changed=1;;
-			f) add_fastest_mirror && changed=1;;
-			e) edit_repositories && changed=1 && break;;
-		esac
-		if [ -n "$changed" ]; then
-			break
-		fi
-	fi
+changed=false
+
+if [ $# -gt 0 ]; then
+	# replace the apk repos with the specified ones
+	rm -f "$APKREPOS_PATH"
+	for i; do
+		echo "$i" >> "$APKREPOS_PATH"
+	done
+	changed=true
+fi
+
+if [ -n "$JUSTADDRANDOM" ]; then
+	show_mirror_list > /dev/null
+	add_random_mirror && changed=true
+fi
+
+while ! $changed; do
+	show_mirror_list
+	prompt_setup_method $default_answer
+
+	default_read answer $default_answer
+	case "$answer" in
+		"done") break;;
+		[0-9]*) add_from_list $answer && changed=true;;
+		/*|http://*|ftp://*|https://*) add_from_url "$answer" \
+			&& changed=true;;
+		r) add_random_mirror && changed=true;;
+		f) add_fastest_mirror && changed=true;;
+		e) edit_repositories && changed=true;;
+	esac
 done
 
-if [ -n "$changed" ]; then
+if $changed; then
 	echo -n "Updating repository indexes... "
 	apk update --quiet $apk_root_opt && echo "done."
 fi
-- 
2.0.0