aboutsummaryrefslogtreecommitdiffstats
path: root/bosun
diff options
context:
space:
mode:
authorWolfgang Müller2019-06-19 19:06:16 +0200
committerWolfgang Müller2019-06-19 19:06:16 +0200
commitbb1b277db0f3ab996d579fcfb42cea4ec72b86d9 (patch)
tree489a024c330069cc3c9c3e46ecfdaf89ce02d42a /bosun
parent064c5abf7731ca1213358a2c9a3ab803db41bc21 (diff)
downloadbosun-bb1b277db0f3ab996d579fcfb42cea4ec72b86d9.tar.gz
Rename to "bosun"1.0.0
Diffstat (limited to 'bosun')
-rwxr-xr-xbosun74
1 files changed, 74 insertions, 0 deletions
diff --git a/bosun b/bosun
new file mode 100755
index 0000000..3351dbc
--- /dev/null
+++ b/bosun
@@ -0,0 +1,74 @@
+#!/bin/sh
+
+STOW_DIR=/etc/portage/stow
+TARGET=/etc/portage
+
+stowcmd="stow -d "$STOW_DIR" -t "$TARGET""
+
+need_root() {
+ if test $(id -u) -ne 0; then
+ printf 'This action requires superuser access.\n'
+ exit 1
+ fi
+}
+
+add() {
+ need_root
+ $stowcmd -S "$@"
+}
+
+remove() {
+ need_root
+ $stowcmd -D "$@"
+}
+
+flush() {
+ need_root
+ list | xargs -- $stowcmd -D
+}
+
+rebuild() {
+ need_root
+ list | xargs -- $stowcmd -R
+}
+
+list() {
+ subcmd="$1"
+ shift
+ case $subcmd in
+ active) list_active;;
+ all) list_all;;
+ available) list_available;;
+ *) list_active;;
+ esac
+}
+
+list_active() {
+ # XXX: -r for xargs is a GNU extension
+ find /etc/portage/ -lname "*stow/*" -print0 2>/dev/null \
+ | xargs -r0 readlink \
+ | sed 's:.*stow/\([^/]\+\)/.*:\1:' \
+ | sort -u
+}
+
+list_all() {
+ ls -1 "$STOW_DIR"
+}
+
+list_available() {
+ tmp="$(mktemp)" || exit 1
+ list_active > "$tmp"
+ list_all | comm -13 "$tmp" -
+ rm -f "$tmp"
+}
+
+cmd="$1"
+shift
+case $cmd in
+ add) add "$@";;
+ flush) flush;;
+ list) list "$@";;
+ rebuild) rebuild;;
+ remove) remove "$@";;
+ *) list_active;;
+esac