|
17 | 17 |
|
18 | 18 | set -euxo pipefail |
19 | 19 |
|
| 20 | +function os_id() ( set +x ; grep '^ID=' /etc/os-release | cut -d= -f2 | xargs ; ) |
| 21 | +function os_version() ( set +x ; grep '^VERSION_ID=' /etc/os-release | cut -d= -f2 | xargs ; ) |
| 22 | +function os_codename() ( set +x ; grep '^VERSION_CODENAME=' /etc/os-release | cut -d= -f2 | xargs ; ) |
| 23 | + |
| 24 | +function version_ge() ( set +x ; [ "$1" = "$(echo -e "$1\n$2" | sort -V | tail -n1)" ] ; ) |
| 25 | +function version_gt() ( set +x ; [ "$1" = "$2" ] && return 1 || version_ge $1 $2 ; ) |
| 26 | +function version_le() ( set +x ; [ "$1" = "$(echo -e "$1\n$2" | sort -V | head -n1)" ] ; ) |
| 27 | +function version_lt() ( set +x ; [ "$1" = "$2" ] && return 1 || version_le $1 $2 ; ) |
| 28 | + |
| 29 | +readonly -A supported_os=( |
| 30 | + ['debian']="10 11 12" |
| 31 | + ['rocky']="8 9" |
| 32 | + ['ubuntu']="18.04 20.04 22.04" |
| 33 | +) |
| 34 | + |
| 35 | +# dynamically define OS version test utility functions |
| 36 | +if [[ "$(os_id)" == "rocky" ]]; |
| 37 | +then _os_version=$(os_version | sed -e 's/[^0-9].*$//g') |
| 38 | +else _os_version="$(os_version)"; fi |
| 39 | +for os_id_val in 'rocky' 'ubuntu' 'debian' ; do |
| 40 | + eval "function is_${os_id_val}() ( set +x ; [[ \"$(os_id)\" == '${os_id_val}' ]] ; )" |
| 41 | + |
| 42 | + for osver in $(echo "${supported_os["${os_id_val}"]}") ; do |
| 43 | + eval "function is_${os_id_val}${osver%%.*}() ( set +x ; is_${os_id_val} && [[ \"${_os_version}\" == \"${osver}\" ]] ; )" |
| 44 | + eval "function ge_${os_id_val}${osver%%.*}() ( set +x ; is_${os_id_val} && version_ge \"${_os_version}\" \"${osver}\" ; )" |
| 45 | + eval "function le_${os_id_val}${osver%%.*}() ( set +x ; is_${os_id_val} && version_le \"${_os_version}\" \"${osver}\" ; )" |
| 46 | + done |
| 47 | +done |
| 48 | + |
| 49 | +function is_debuntu() ( set +x ; is_debian || is_ubuntu ; ) |
| 50 | + |
20 | 51 | # Only run on the master node |
21 | 52 | ROLE="$(/usr/share/google/get_metadata_value attributes/dataproc-role)" |
22 | 53 |
|
@@ -52,22 +83,24 @@ if (! test -v DATAPROC_IMAGE_VERSION) && test -v DATAPROC_VERSION; then |
52 | 83 | DATAPROC_IMAGE_VERSION="${DATAPROC_VERSION}" |
53 | 84 | fi |
54 | 85 |
|
55 | | -function remove_old_backports { |
| 86 | +function repair_old_backports { |
| 87 | + if ! is_debuntu ; then return ; fi |
56 | 88 | # This script uses 'apt-get update' and is therefore potentially dependent on |
57 | 89 | # backports repositories which have been archived. In order to mitigate this |
58 | 90 | # problem, we will remove any reference to backports repos older than oldstable |
59 | 91 |
|
60 | 92 | # https://github.com/GoogleCloudDataproc/initialization-actions/issues/1157 |
61 | | - oldstable=$(curl -s https://deb.debian.org/debian/dists/oldstable/Release | awk '/^Codename/ {print $2}'); |
62 | | - stable=$(curl -s https://deb.debian.org/debian/dists/stable/Release | awk '/^Codename/ {print $2}'); |
63 | | - |
64 | | - matched_files="$(grep -rsil '\-backports' /etc/apt/sources.list*)" |
65 | | - if [[ -n "$matched_files" ]]; then |
66 | | - for filename in "$matched_files"; do |
67 | | - grep -e "$oldstable-backports" -e "$stable-backports" "$filename" || \ |
68 | | - sed -i -e 's/^.*-backports.*$//' "$filename" |
69 | | - done |
70 | | - fi |
| 93 | + debdists="https://deb.debian.org/debian/dists" |
| 94 | + oldoldstable=$(curl -s "${debdists}/oldoldstable/Release" | awk '/^Codename/ {print $2}'); |
| 95 | + oldstable=$( curl -s "${debdists}/oldstable/Release" | awk '/^Codename/ {print $2}'); |
| 96 | + stable=$( curl -s "${debdists}/stable/Release" | awk '/^Codename/ {print $2}'); |
| 97 | + |
| 98 | + matched_files=( $(grep -rsil '\-backports' /etc/apt/sources.list*||:) ) |
| 99 | + |
| 100 | + for filename in "${matched_files[@]}"; do |
| 101 | + perl -pi -e "s{^(deb[^\s]*) https?://[^/]+/debian ${oldoldstable}-backports } |
| 102 | + {\$1 https://archive.debian.org/debian ${oldoldstable}-backports }g" "${filename}" |
| 103 | + done |
71 | 104 | } |
72 | 105 |
|
73 | 106 | function update_apt_get() { |
@@ -116,7 +149,7 @@ function install_package() { |
116 | 149 |
|
117 | 150 | if [[ "${ROLE}" == 'Master' ]]; then |
118 | 151 | if [[ ${OS_ID} == debian ]] && [[ $(echo "${DATAPROC_IMAGE_VERSION} <= 2.1" | bc -l) == 1 ]]; then |
119 | | - remove_old_backports |
| 152 | + repair_old_backports |
120 | 153 | fi |
121 | 154 | if [[ -n ${USER_PASSWORD} ]] && ((${#USER_PASSWORD} < 7)); then |
122 | 155 | echo "You must specify a password of at least 7 characters for user '$USER_NAME' through metadata 'rstudio-password'." |
|
0 commit comments