comparison sbin/fpkg @ 692:d1cb22ba641d

fpkg: Modernize fpkg: local variables, jail enumeration and sorting. Also now allow spaces in all jail names.
author Franz Glasner <fzglas.hg@dom66.de>
date Tue, 01 Oct 2024 16:01:44 +0200
parents b9194bec5504
children 3633a41b862b
comparison
equal deleted inserted replaced
691:3395d7e9cd15 692:d1cb22ba641d
155 155
156 command_uversion() { 156 command_uversion() {
157 : ' Do a local `freebsd-version -u` and also for all running jails 157 : ' Do a local `freebsd-version -u` and also for all running jails
158 158
159 ' 159 '
160 echo "LOCALHOST: $(/bin/freebsd-version -u)" 160 local _jail _OLDIFS
161 for _jail in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 161
162 echo "${_jail}: $(jexec -l -- "${_jail}" /bin/freebsd-version -u)" 162 printf 'LOCALHOST: %s\n' "$(/bin/freebsd-version -u)"
163 done 163 _OLDIFS="$IFS"
164 IFS=$'\n'
165 for _jail in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
166 printf '%s: %s\n' "${_jail}" "$(jexec -l -- "${_jail}" /bin/freebsd-version -u)"
167 done
168 IFS="$_OLDIFS"
164 } 169 }
165 170
166 171
167 command_audit() { 172 command_audit() {
168 : 'Do a local `pkg audit -Fr` and also for all running jails 173 : 'Do a local `pkg audit -Fr` and also for all running jails
169 174
170 ' 175 '
171 echo "${FPKG_SIGN}LOCALHOST" 176 local _j _OLDIFS
177
178 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
172 pkg audit ${FPKG_AUDIT_FLAGS} 179 pkg audit ${FPKG_AUDIT_FLAGS}
173 for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 180 _OLDIFS="$IFS"
174 echo "" 181 IFS=$'\n'
175 echo "${FPKG_SIGN}JAIL: ${_j}" 182 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
183 printf '\n%sJAIL: %s\n' "${FPKG_SIGN}" "${_j}"
176 if has_same_userland_version "${_j}"; then 184 if has_same_userland_version "${_j}"; then
177 pkg -j "${_j}" audit ${FPKG_AUDIT_FLAGS} 185 pkg -j "${_j}" audit ${FPKG_AUDIT_FLAGS}
178 else 186 else
179 echo "${FPKG_SKIPSIGN}SKIPPED because of different userland" 187 printf '%s%s\n' "${FPKG_SKIPSIGN}" "SKIPPED because of different userland"
180 fi 188 fi
181 done 189 done
190 IFS="$_OLDIFS"
182 } 191 }
183 192
184 193
185 command_update() { 194 command_update() {
186 : 'Do a local `pkg update` and also for all running jails 195 : 'Do a local `pkg update` and also for all running jails
187 196
188 ' 197 '
189 echo "${FPKG_SIGN}LOCALHOST" 198 local _j _OLDIFS
199
200 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
190 pkg update ${FPKG_UPDATE_FLAGS} 201 pkg update ${FPKG_UPDATE_FLAGS}
191 for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 202 _OLDIFS="$IFS"
192 echo "" 203 IFS=$'\n'
193 echo "${FPKG_SIGN}JAIL: ${_j}" 204 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
205 printf '\n%sJAIL: %s\n' "${FPKG_SIGN}" "${_j}"
194 if has_same_userland_version "${_j}"; then 206 if has_same_userland_version "${_j}"; then
195 pkg -j "${_j}" update ${FPKG_UPDATE_FLAGS} 207 pkg -j "${_j}" update ${FPKG_UPDATE_FLAGS}
196 else 208 else
197 echo "${FPKG_SKIPSIGN}SKIPPED because of different userland" 209 printf '%s%s\n' "${FPKG_SKIPSIGN}" "SKIPPED because of different userland"
198 fi 210 fi
199 done 211 done
212 IFS="$_OLDIFS"
200 } 213 }
201 214
202 215
203 command_upgrade() { 216 command_upgrade() {
204 : 'Do a local `pkg upgrade` and also for all running jails 217 : 'Do a local `pkg upgrade` and also for all running jails
205 218
206 ' 219 '
207 echo "${FPKG_SIGN}LOCALHOST" 220 local _j _OLDIFS
221
222 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
208 pkg upgrade ${FPKG_UPGRADE_FLAGS} 223 pkg upgrade ${FPKG_UPGRADE_FLAGS}
209 for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 224 _OLDIFS="$IFS"
210 echo "" 225 IFS=$'\n'
211 echo "${FPKG_SIGN}JAIL: ${_j}" 226 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
227 printf '\n%sJAIL: %s\n' "${FPKG_SIGN}" "${_j}"
212 if has_same_userland_version "${_j}"; then 228 if has_same_userland_version "${_j}"; then
213 pkg -j "${_j}" upgrade ${FPKG_UPGRADE_FLAGS} 229 pkg -j "${_j}" upgrade ${FPKG_UPGRADE_FLAGS}
214 else 230 else
215 echo "${FPKG_SKIPSIGN}SKIPPED because of different userland" 231 printf '%s%s\n' "${FPKG_SKIPSIGN}" "SKIPPED because of different userland"
216 fi 232 fi
217 done 233 done
234 IFS="$_OLDIFS"
218 } 235 }
219 236
220 237
221 command_check_upgrade() { 238 command_check_upgrade() {
222 : 'Do a local `pkg upgrade -n` and also for all running jails 239 : 'Do a local `pkg upgrade -n` and also for all running jails
223 240
224 ' 241 '
225 echo "${FPKG_SIGN}LOCALHOST" 242 local _j _OLDIFS
243
244 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
226 pkg upgrade -n ${FPKG_UPGRADE_FLAGS} 245 pkg upgrade -n ${FPKG_UPGRADE_FLAGS}
227 for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 246 _OLDIFS="$IFS"
228 echo "" 247 IFS=$'\n'
229 echo "${FPKG_SIGN}JAIL: ${_j}" 248 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
249 printf '\n%sJAIL: %s\n' "${FPKG_SIGN}" "${_j}"
230 if has_same_userland_version "${_j}"; then 250 if has_same_userland_version "${_j}"; then
231 pkg -j "${_j}" upgrade -n ${FPKG_UPGRADE_FLAGS} 251 pkg -j "${_j}" upgrade -n ${FPKG_UPGRADE_FLAGS}
232 else 252 else
233 echo "${FPKG_SKIPSIGN}SKIPPED because of different userland" 253 printf '%s%s\n' "${FPKG_SKIPSIGN}" "SKIPPED because of different userland"
234 fi 254 fi
235 done 255 done
256 IFS="$_OLDIFS"
236 } 257 }
237 258
238 259
239 command_check_fasttrack() { 260 command_check_fasttrack() {
240 : 'Check the fast-track repository versions against the canonical 261 : 'Check the fast-track repository versions against the canonical
243 Input (Globals): 264 Input (Globals):
244 FREEBSD_REPO: the (canonical) FreeBSD repository name 265 FREEBSD_REPO: the (canonical) FreeBSD repository name
245 LOCALBSDPORTS_REPO: the fast-track repository name 266 LOCALBSDPORTS_REPO: the fast-track repository name
246 267
247 ' 268 '
248 local _name _repo _j 269 local _name _repo _j _OLDIFS
249 270
250 echo "${FPKG_SIGN}LOCALHOST" 271 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
251 pkg query '%n %R' | 272 pkg query '%n %R' |
252 while read -r _name _repo; do 273 while read -r _name _repo; do
253 if [ "${_repo}" = "${LOCALBSDPORTS_REPO}" ]; then 274 if [ "${_repo}" = "${LOCALBSDPORTS_REPO}" ]; then
254 echo " ${_name}" 275 printf ' %s\n' "${_name}"
255 printf ' %-15s : %s\n' "${LOCALBSDPORTS_REPO}" "$(pkg version -U -r "${LOCALBSDPORTS_REPO}" -n "${_name}" -v)" 276 printf ' %-15s : %s\n' "${LOCALBSDPORTS_REPO}" "$(pkg version -U -r "${LOCALBSDPORTS_REPO}" -n "${_name}" -v)"
256 printf ' %-15s : %s\n' "${FREEBSD_REPO}" "$(pkg version -U -r "${FREEBSD_REPO}" -n "${_name}" -v)" 277 printf ' %-15s : %s\n' "${FREEBSD_REPO}" "$(pkg version -U -r "${FREEBSD_REPO}" -n "${_name}" -v)"
257 fi 278 fi
258 done 279 done
259 for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 280 _OLDIFS="$IFS"
260 echo "" 281 IFS=$'\n'
261 echo "${FPKG_SIGN}JAIL: ${_j}" 282 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
283 printf '\n%sJAIL: %s\n' "${FPKG_SIGN}" "${_j}"
262 if has_same_userland_version "${_j}"; then 284 if has_same_userland_version "${_j}"; then
263 pkg -j "${_j}" query '%n %R' | 285 pkg -j "${_j}" query '%n %R' |
264 while read -r _name _repo; do 286 while IFS="$_OLDIFS" read -r _name _repo; do
265 if [ "${_repo}" = "${LOCALBSDPORTS_REPO}" ]; then 287 if [ "${_repo}" = "${LOCALBSDPORTS_REPO}" ]; then
266 echo " ${_name}" 288 printf ' %s\n' "${_name}"
267 printf ' %s-15s : %s\n' "${LOCALBSDPORTS_REPO}" "$(pkg -j "${_j}" version -U -r "${LOCALBSDPORTS_REPO}" -n "${_name}" -v)" 289 printf ' %s-15s : %s\n' "${LOCALBSDPORTS_REPO}" "$(pkg -j "${_j}" version -U -r "${LOCALBSDPORTS_REPO}" -n "${_name}" -v)"
268 printf ' %-15s : %s\n' "${FREEBSD_REPO}" "$(pkg -j "${_j}" version -U -r "${FREEBSD_REPO}" -n "${_name}" -v)" 290 printf ' %-15s : %s\n' "${FREEBSD_REPO}" "$(pkg -j "${_j}" version -U -r "${FREEBSD_REPO}" -n "${_name}" -v)"
269 fi 291 fi
270 done 292 done
271 else 293 else
272 echo "${FPKG_SKIPSIGN}SKIPPED because of different userland" 294 printf '%s%s\n' "${FPKG_SKIPSIGN}" "SKIPPED because of different userland"
273 fi 295 fi
274 done 296 done
297 IFS="$_OLDIFS"
275 } 298 }
276 299
277 300
278 command_config() { 301 command_config() {
279 : 'The `pkg config name` command on the host and all running 302 : 'The `pkg config name` command on the host and all running jails
280 compatible jails
281 303
282 Args: 304 Args:
283 _name: the configuration option to retrieve to 305 _name: the configuration option to retrieve to
284 306
285 ' 307 '
286 local _name 308 local _name _j _OLDIFS
287 309
288 _name="$1" 310 _name="$1"
289 311
290 if [ -z "${_name}" ]; then 312 if [ -z "${_name}" ]; then
291 echo "Usage: fpkg config <name>" >&2 313 echo "Usage: fpkg config <name>" >&2
292 return 1 314 return 1
293 fi 315 fi
294 echo "${FPKG_SIGN}LOCALHOST" 316 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
295 pkg config "${_name}" 317 pkg config "${_name}"
296 for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 318 _OLDIFS="$IFS"
297 echo "" 319 IFS=$'\n'
298 echo "${FPKG_SIGN}JAIL: ${_j}" 320 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
299 if has_same_userland_version "${_j}"; then 321 printf '\n%sJAIL: %s\n' "${FPKG_SIGN}" "${_j}"
300 # This prints the value on the *host* also 322 # This prints the value on the *host* also
301 #pkg -j "${_j}" config "${_name}" 323 #pkg -j "${_j}" config "${_name}"
302 jexec -- "${_j}" pkg config "${_name}" 324 # with jexec it can be run on all jails
303 else 325 LC_ALL=C.UTF-8 /usr/sbin/jexec -- "${_j}" pkg config "${_name}"
304 echo "${FPKG_SKIPSIGN}SKIPPED because of different userland" 326 done
305 fi 327 IFS="$_OLDIFS"
306 done
307 } 328 }
308 329
309 330
310 command_vv() { 331 command_vv() {
311 : 'The `pkg -vv` command on the host and all running compatible jails 332 : 'The `pkg -vv` command on the host and all running compatible jails
312 333
313 ' 334 '
314 echo "${FPKG_SIGN}LOCALHOST" 335 local _j _OLDIFS
336
337 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
315 pkg -vv 338 pkg -vv
316 for _j in $(jls -N | awk '{if(NR>1)print $1}' | sort); do 339 _OLDIFS="$IFS"
317 echo "" 340 IFS=$'\n'
318 echo "${FPKG_SIGN}JAIL: ${_j}" 341 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do
342 printf '\n%sJAIL: %s\n' "${FPKG_SIGN}" "${_j}"
319 if has_same_userland_version "${_j}"; then 343 if has_same_userland_version "${_j}"; then
320 pkg -j "${_j}" -vv 344 pkg -j "${_j}" -vv
321 else 345 else
322 echo "${FPKG_SKIPSIGN}SKIPPED because of different userland" 346 printf '%s%s\n' "${FPKG_SKIPSIGN}" "SKIPPED because of different userland"
323 fi 347 fi
324 done 348 done
349 IFS="$_OLDIFS"
325 } 350 }
326 351
327 352
328 command_etcupdate_status() { 353 command_etcupdate_status() {
329 : 'Call `etcupdate status` on the host and all running jails 354 : 'Call `etcupdate status` on the host and all running jails
330 355
331 ' 356 '
332 local _j _OLDIFS 357 local _j _OLDIFS
333 358
334 printf '%sLOCALHOST\n' "${FPKG_SIGN}" 359 printf '%sLOCALHOST\n' "${FPKG_SIGN}"
335 /usr/sbin/etcupdate status 360 /usr/sbin/etcupdate status
336 _OLDIFS="$IFS" 361 _OLDIFS="$IFS"
337 IFS=$'\n' 362 IFS=$'\n'
338 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do 363 for _j in $(/usr/sbin/jls name | LC_ALL=C.UTF-8 /usr/bin/sort); do