Ubuntu Pastebin

Paste from smoser at Wed, 14 Jun 2017 17:51:35 +0000

Download as text
  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
103
diff --git a/tools/run-centos b/tools/run-centos
index f812e93e..593463e5 100755
--- a/tools/run-centos
+++ b/tools/run-centos
@@ -26,6 +26,7 @@ Usage: ${0##*/} [ options ] version
       -k | --keep     keep container after tests
       -r | --rpm      build .rpm
       -s | --srpm     build .src.rpm
+      -S | --static-mirrors  update known repos to not use mirrorlist.
       -u | --unittest run unit tests
 
     Example:
@@ -102,12 +103,26 @@ inject_cloud_init(){
     return 0
 }
 
+set_static_mirrors() {
+    local ydir="/etc/yum.repos.d" f=""
+    if [ $# -eq 0 ]; then
+        set -- "$ydir/epel.repo" "$ydir/CentOS-Base.repo"
+    fi
+    for f in "$@"; do
+        [ -f "$f" ] || continue
+        sed -i \
+            -e 's/^mirrorlist=/#mirrorlist=/' -e 's/^#baseurl/baseurl/' \
+            "$f" || return
+    done
+    return 0
+}
+
 prep() {
     # we need some very basic things not present in the container.
     #  - git
     #  - tar (CentOS 6 lxc container does not have it)
     #  - python-argparse (or python3)
-    local needed=""
+    local needed="" static="$1" epel_added=false
     needed=""
     for pair in tar:tar git:git; do
         pkg=${pair#*:}
@@ -118,13 +133,23 @@ prep() {
         python -c "import argparse" >/dev/null 2>&1 ||
             needed="${needed} python-argparse"
     fi
+    if [ ! -e /etc/yum.repos.d/epel.repo ]; then
+        needed="${needed} epel-release"
+        epel_added=true
+    fi
     needed=${needed# }
     if [ -z "$needed" ]; then
         error "No prep packages needed"
         return 0
     fi
-    error "Installing prep packages: ${needed}"
-    yum install --assumeyes ${needed}
+
+    if [ "$static" = "true" ]; then
+        set_static_mirrors || return
+    fi
+    yum install --assumeyes ${needed} || return
+    if ${epel_added} && [ "$static" = "true" ]; then
+        set_static_mirrors || return
+    fi
 }
 
 start_container() {
@@ -163,8 +188,9 @@ delete_container() {
 }
 
 main() {
-    local short_opts="ahkrsuv"
-    local long_opts="artifact,help,keep,rpm,srpm,unittest,verbose"
+    local short_opts="ahkrsSuv"
+    local long_opts="artifact,help,keep,rpm,srpm,static-mirrors"
+    long_opts="${long_opts},unittest,verbose"
     local getopt_out=""
     getopt_out=$(getopt --name "${0##*/}" \
         --options "${short_opts}" --long "${long_opts}" -- "$@") &&
@@ -173,6 +199,7 @@ main() {
 
     local cur="" next=""
     local artifact="" keep="" rpm="" srpm="" unittest="" version=""
+    local static_mirrors="false"
 
     while [ $# -ne 0 ]; do
         cur="${1:-}"; next="${2:-}";
@@ -182,6 +209,7 @@ main() {
             -k|--keep) KEEP=true;;
             -r|--rpm) rpm=1;;
             -s|--srpm) srpm=1;;
+            -S|--static-mirrors) static_mirrors=true;;
             -u|--unittest) unittest=1;;
             -v|--verbose) VERBOSITY=$((${VERBOSITY}+1));;
             --) shift; break;;
@@ -209,7 +237,7 @@ main() {
     start_container "images:centos/$version" "$name"
 
     # prep the container (install very basic dependencies)
-    inside "$name" bash -s prep <"$0" ||
+    inside "$name" bash -s prep "$static_mirrors" <"$0" ||
         { errorrc "Failed to prep container $name"; return; }
 
     # add the user
Download as text