aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/%HOME%
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2022-04-01 16:49:35 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2022-04-01 16:49:35 +0300
commit0f80f96ec6a01d7fd9d916a22961934db277d3cb (patch)
tree80eda01b367582d079cf2ee6327ecf7e26ba14fc /%HOME%
parentrename the project (diff)
downloadlinux-home-0f80f96ec6a01d7fd9d916a22961934db277d3cb.tar.gz
linux-home-0f80f96ec6a01d7fd9d916a22961934db277d3cb.zip
add .local/bin/vagrant-update-all-boxes.sh
Diffstat (limited to '%HOME%')
-rwxr-xr-x%HOME%/.local/bin/vagrant-update-all-boxes.sh60
1 files changed, 60 insertions, 0 deletions
diff --git a/%HOME%/.local/bin/vagrant-update-all-boxes.sh b/%HOME%/.local/bin/vagrant-update-all-boxes.sh
new file mode 100755
index 0000000..e433c16
--- /dev/null
+++ b/%HOME%/.local/bin/vagrant-update-all-boxes.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/env bash
+
+# Copyright (c) 2022 Egor Tensin <Egor.Tensin@gmail.com>
+# This file is part of the "linux-home" project.
+# For details, see https://github.com/egor-tensin/linux-home.
+# Distributed under the MIT License.
+
+set -o errexit -o nounset -o pipefail
+
+dump() {
+ local msg
+ for msg; do
+ local prefix="${FUNCNAME[0]}"
+ [ "${#FUNCNAME[@]}" -gt 1 ] && prefix="${FUNCNAME[1]}"
+ echo "$prefix: $msg"
+ done
+}
+
+update_box_from_line() {
+ local orig_line
+ for orig_line; do
+ local line="$orig_line"
+ line="${line//'*'/}"
+ line="${line//"'"/}"
+
+ local box
+ box="$( echo "$line" | cut -d ' ' -f 2 )"
+ local provider
+ provider="$( echo "$line" | cut -d ' ' -f 4 )"
+
+ local sanity_check
+ sanity_check="$( echo "$line" | cut -d ' ' -f 3 )"
+
+ if [ "$sanity_check" != 'for' ]; then
+ dump "this line is malformed:" "$orig_line" >&2
+ return 1
+ fi
+
+ dump "updating box '$box' for provider '$provider'..."
+ vagrant box update --box "$box" --provider "$provider"
+ done
+}
+
+update_all_boxes() {
+ local line
+ while IFS= read -r line; do
+ update_box_from_line "$line"
+ done < <( vagrant box outdated --global | grep -F outdated )
+}
+
+clean_old_boxes() {
+ vagrant box prune --force --keep-active-boxes
+}
+
+main() {
+ update_all_boxes
+ clean_old_boxes
+}
+
+main