summaryrefslogtreecommitdiff
path: root/automated/lib
diff options
context:
space:
mode:
authorChase Qi <chase.qi@linaro.org>2016-10-25 16:38:30 +0800
committerMilosz Wasilewski <milosz.wasilewski@linaro.org>2016-10-28 10:21:31 +0000
commite7eda1e40a30bfe9bdce4b334aec1fc37a7bdedc (patch)
treea292282857d4a1d11b267eae72fe049547c5d869 /automated/lib
parent3864dbf0b33f31a88b66811ab3eb527f6fc3df35 (diff)
downloadtest-definitions-pipe-e7eda1e40a30bfe9bdce4b334aec1fc37a7bdedc.tar.gz
v2: sh-test-lib: added support for adding 3rd-party repo
Change-Id: Icae2293f011b7ed59061452cf119e4e1b077d6cd Signed-off-by: Chase Qi <chase.qi@linaro.org>
Diffstat (limited to 'automated/lib')
-rwxr-xr-xautomated/lib/sh-test-lib59
1 files changed, 59 insertions, 0 deletions
diff --git a/automated/lib/sh-test-lib b/automated/lib/sh-test-lib
index 4894875..a5b2d58 100755
--- a/automated/lib/sh-test-lib
+++ b/automated/lib/sh-test-lib
@@ -230,3 +230,62 @@ convert_to_mb() {
echo "${value}"
}
+
+dist_info() {
+ if ! command -v lsb_release > /dev/null; then
+ dist_name
+ case "${dist}" in
+ Debian|Ubuntu) install_deps "lsb-release" ;;
+ CentOS|Fedora) install_deps "redhat-lsb-core" ;;
+ *) error_msg "Unsupported distro: dist_info skipped"
+ esac
+ fi
+
+ # shellcheck disable=SC2034
+ Release=$(lsb_release -r | awk '{print $2}')
+ Codename=$(lsb_release -c | awk '{print $2}')
+}
+
+add_key() {
+ [ "$#" -ne 1 ] && error_msg "Usage: add_key url"
+ local url="$1"
+
+ dist_name
+ case "${dist}" in
+ Debian|Ubuntu) wget -O - "${url}" | apt-key add - ;;
+ CentOS|Fedora) infor_msg "add_key isn't needed on ${dist}" ;;
+ *) error_msg "Unsupported distro: add_key skipped"
+ esac
+}
+
+add_repo() {
+ [ "$#" -lt 1 ] && error_msg "Usage: add_repo <url> [backports]"
+ local url="$1"
+
+ dist_name
+ case "${dist}" in
+ # Detect Debian/Ubuntu codename and add repo automatically. The same url
+ # should work on all distributions supported by the repo.
+ Debian|Ubuntu)
+ dist_info
+ if [ -z "$2" ]; then
+ backports=""
+ elif [ "$2" = "backports" ]; then
+ backports="-backports"
+ else
+ echo "Usage: add_repo <url> [backports]"
+ error_msg "$2 is not a supported argument, should be 'backports'"
+ fi
+ echo "deb ${url} ${Codename}${backports} main" \
+ >> "/etc/apt/sources.list.d/3rd-party-repo.list"
+ ;;
+ # It is not easy to amend url with distro version as its format may vary
+ # by repo. Test definition/plan should provide a correct repo url.
+ CentOS|Fedora)
+ wget -O - "${url}" >> "/etc/yum.repos.d/3rd-party.repo"
+ ;;
+ *)
+ error_msg "Unsupported distro: add_repo skipped"
+ ;;
+ esac
+}