|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | # This file is part of BOINC. |
4 | | -# http://boinc.berkeley.edu |
5 | | -# Copyright (C) 2024 University of California |
| 4 | +# https://boinc.berkeley.edu |
| 5 | +# Copyright (C) 2025 University of California |
6 | 6 | # |
7 | 7 | # BOINC is free software; you can redistribute it and/or modify it |
8 | 8 | # under the terms of the GNU Lesser General Public License |
@@ -144,42 +144,26 @@ if [[ "$IS_MIRROR" -eq "0" ]]; then |
144 | 144 |
|
145 | 145 | # keep only 3 last versions of each package before adding new ones |
146 | 146 | packets=$(aptly -config=$CONF_FILE repo search boinc-$TYPE | grep -o '[^[:space:]]*_\([[:digit:]]*\.\)\{2\}[[:digit:]]*-\([[:digit:]]*_\)[^[:space:]]*' | sort -t '_' -k 2 -V | uniq) |
147 | | - declare -A split_lists |
148 | | - packets_list=() |
149 | | - while IFS= read -r line; do |
150 | | - packets_list+=("$line") |
151 | | - done <<< "$packets" |
152 | | - for item in "${packets_list[@]}"; do |
153 | | - prefix="${item%%_*}" # Extract the prefix (text before the first underscore) |
154 | | - split_lists["$prefix"]+="$item"$'\n' # Append the item to the corresponding prefix's list |
155 | | - done |
156 | | - |
157 | | - for prefix in "${!split_lists[@]}"; do |
158 | | - echo "List for prefix: $prefix" |
159 | | - echo "${split_lists[$prefix]}" |
160 | | - count=$(echo "${split_lists[$prefix]}" | wc -l) |
161 | | - number=$(expr $count - 1) |
162 | | - echo "count=$number" |
163 | | - i=0 |
164 | | - exceed=$(expr $number - 3) |
165 | | - echo "exceed=$exceed" |
166 | | - if (( exceed > 0)); then |
167 | | - values_list=() |
168 | | - while IFS= read -r line; do |
169 | | - values_list+=("$line") |
170 | | - done <<< "${split_lists[$prefix]}" |
171 | | - for value in "${values_list[@]}"; do |
172 | | - if (( i < exceed )); then |
173 | | - echo "Remove: $value" |
174 | | - i=$((i+1)) |
175 | | - aptly -config=$CONF_FILE repo remove boinc-$TYPE $value |
| 147 | + prefixes=$(echo "$packets"| cut -d '_' -f 1 | sort -n | uniq) |
| 148 | + suffixes=$(echo "$packets"| cut -d '_' -f 3- | sort -V | uniq) |
| 149 | + for prefix in $prefixes; do |
| 150 | + echo $prefix |
| 151 | + for suffix in $suffixes; do |
| 152 | + echo " $suffix" |
| 153 | + matched_packets=$(echo "$packets" | grep "^${prefix}_.*_${suffix}$") |
| 154 | + count=$(echo "$matched_packets" | wc -l) |
| 155 | + echo " count: $count" |
| 156 | + exceed=$(expr $count - 3) |
| 157 | + echo " exceed: $exceed" |
| 158 | + if (( exceed > 0 )); then |
| 159 | + echo "$matched_packets" | head -n $exceed | while IFS= read -r packet; do |
| 160 | + echo " Remove: $packet" |
| 161 | + aptly -config=$CONF_FILE repo remove boinc-$TYPE $packet |
176 | 162 | exit_on_fail "Failed to remove the package" |
177 | | - else |
178 | | - break |
179 | | - fi |
180 | | - done |
181 | | - fi |
182 | | - done |
| 163 | + done |
| 164 | + fi |
| 165 | + done |
| 166 | + done |
183 | 167 |
|
184 | 168 | # creates the snapshot of the old situation |
185 | 169 | aptly -config=$CONF_FILE snapshot create old-boinc-$TYPE-snap from repo boinc-$TYPE |
|
192 | 176 | if [[ "$TYPE" == "stable" ]]; then |
193 | 177 | # get only one latest packages of each type from the alpha repo |
194 | 178 | alpha_packets=$(aptly -config=$CONF_FILE mirror search boinc-alpha-mirror | grep -o '[^[:space:]]*_\([[:digit:]]*\.\)\{2\}[[:digit:]]*-\([[:digit:]]*_\)[^[:space:]]*' | sort -t '_' -k 2 -V -r | uniq) |
195 | | - declare -A alpha_split_lists |
196 | | - alpha_packets_list=() |
197 | | - while IFS= read -r line; do |
198 | | - alpha_packets_list+=("$line") |
199 | | - done <<< "$alpha_packets" |
200 | | - for item in "${alpha_packets_list[@]}"; do |
201 | | - prefix="${item%%_*}" # Extract the prefix (text before the first underscore) |
202 | | - alpha_split_lists["$prefix"]+="$item"$'\n' # Append the item to the corresponding prefix's list |
203 | | - done |
204 | | - for prefix in "${!alpha_split_lists[@]}"; do |
205 | | - echo "List for prefix: $prefix" |
206 | | - echo "${alpha_split_lists[$prefix]}" |
207 | | - alpha_values_list=() |
208 | | - while IFS= read -r line; do |
209 | | - alpha_values_list+=("$line") |
210 | | - done <<< "${alpha_split_lists[$prefix]}" |
211 | | - for value in "${alpha_values_list[@]}"; do |
212 | | - # copy the latest package to the local repo |
213 | | - echo "Adding: $value" |
214 | | - aptly -config=$CONF_FILE repo import boinc-alpha-mirror boinc-$TYPE $value |
215 | | - break |
216 | | - done |
217 | | - done |
| 179 | + prefixes=$(echo "$packets"| cut -d '_' -f 1 | sort -n | uniq) |
| 180 | + suffixes=$(echo "$packets"| cut -d '_' -f 3- | sort -V | uniq) |
| 181 | + for prefix in $prefixes; do |
| 182 | + echo $prefix |
| 183 | + for suffix in $suffixes; do |
| 184 | + echo " $suffix" |
| 185 | + matched_packets=$(echo "$packets" | grep "^${prefix}_.*_${suffix}$") |
| 186 | + echo "$matched_packets" | tail -n 1 | while IFS= read -r packet; do |
| 187 | + echo " Adding: $packet" |
| 188 | + aptly -config=$CONF_FILE repo remove boinc-$TYPE $packet |
| 189 | + exit_on_fail "Failed to remove the package" |
| 190 | + done |
| 191 | + done |
| 192 | + done |
218 | 193 | else |
219 | 194 | # imports into the repo the new packages |
220 | 195 | aptly -config=$CONF_FILE repo add boinc-$TYPE $SRC/*.deb |
|
0 commit comments