Skip to content

Instantly share code, notes, and snippets.

@NICHOLAS85
Last active May 1, 2020 21:04
Show Gist options
  • Save NICHOLAS85/f31351e30ca6d67c400320917bcf5ec2 to your computer and use it in GitHub Desktop.
Save NICHOLAS85/f31351e30ca6d67c400320917bcf5ec2 to your computer and use it in GitHub Desktop.
brl all concept script
#!/bedrock/libexec/busybox sh
#
# brl all
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# version 2 as published by the Free Software Foundation.
#
# Copyright (c) 2012-2019 Daniel Thau <danthau@bedrocklinux.org>
#
# Run command in multiple strata
. /bedrock/share/common-code
print_help() {
printf "Usage: ${color_cmd}brl all ${color_sub}[options]${color_norm}
Runs command in multiple ${color_term}strata${color_norm}.
Options:
${color_sub}<none>${color_norm} defaults to ${color_cmd}--enabled${color_norm}
${color_cmd}-e${color_norm},${color_cmd} --enabled-strata ${color_norm}${color_term}enabled${color_norm} ${color_term}stratum${color_norm}
${color_cmd}-E${color_norm},${color_cmd} --enabled-aliases ${color_norm}${color_term}aliases${color_norm} to ${color_term}enabled${color_norm} ${color_term}stratum${color_norm}
${color_cmd}-a${color_norm},${color_cmd} --all-strata ${color_norm}all ${color_term}strata${color_norm}
${color_cmd}-A${color_norm},${color_cmd} --all-aliases ${color_norm}all ${color_term}aliases${color_norm}
${color_cmd}-i${color_norm},${color_cmd} --include-hidden ${color_norm}include ${color_term}hidden strata${color_norm} in list
may require pairing with ${color_cmd}-E${color_norm} or ${color_cmd}-a${color_norm}
${color_cmd}-v${color_norm},${color_cmd} --everything ${color_norm}equivalent to ${color_cmd}-aAir
${color_cmd}-r${color_norm},${color_cmd} --restrict ${color_norm}disable cross-stratum hooks
${color_cmd}-u${color_norm},${color_cmd} --unrestrict ${color_norm}do not disable cross-stratum hooks
${color_cmd}-q${color_norm},${color_cmd} --quiet ${color_norm}lesson output verbosity
${color_cmd}-h${color_norm},${color_cmd} --help ${color_norm}print this message
Examples:
#todo
"
}
handle_help "${@:-}"
list_enabled_strata=false
list_enabled_aliases=false
include_hidden=false
quiet=false
stratopt=""
cmds=""
OPTL="enabled-strata,enabled-aliases,include-hidden,everything,restrict,unrestrict,quiet"
OPTO="eEivruq"
eval set -- "$(getopt -q -l "${OPTL}" -- "${OPTO}" "${@}")" || true
endopts=false
while [ -n "${1:-}" ]; do
case "${1}" in
-e | --enabled-strata)
list_enabled_strata=true
shift
;;
-E | --enabled-aliases)
list_enabled_aliases=true
shift
;;
-i | --include-hidden)
include_hidden=true
shift
;;
-v | --everything)
list_enabled_strata=true
list_enabled_aliases=true
include_hidden=true
shift
;;
-r | --restrict)
stratopt="--restrict "
shift
;;
-u | --unrestrict)
stratopt="--unrestrict "
shift
;;
-q | --quiet)
quiet=true
shift
;;
--)
if "${endopts}"; then
cmds="${cmds} ${1}"
else
endopts=true
fi
shift
;;
-*)
if "${endopts}"; then
cmds="${cmds} ${1}"
else
abort "Unrecognized argument: ${1}"
fi
shift
;;
*)
cmds="${cmds} ${1}"
shift
;;
esac
done
cmd='/bedrock/bin/strat ${stratopt}${stratum}${cmds}'
eval set -- "${cmds}" || true
if ! "${list_enabled_strata}" &&
! "${list_enabled_aliases}"; then
list_enabled_strata=true
fi
(
if "${list_enabled_strata}"; then
list_strata
fi
if "${list_enabled_aliases}"; then
list_aliases
fi
) | sort | while read -r stratum; do
if ! "${include_hidden}" && ! has_attr "/bedrock/strata/$stratum" show_list; then
continue
elif ! /bedrock/bin/strat -r "${stratum}" /bedrock/libexec/busybox which "${1}" >/dev/null 2>&1; then
continue
elif "${list_enabled_strata}" && is_stratum "${stratum}" && is_enabled "${stratum}"; then
if ! "${quiet}"; then eval "printf \"* ${color_cmd}%s${color_norm}\\n\" \"$cmd\""; fi
eval "$cmd"
elif "${list_enabled_aliases}" && is_alias "${stratum}" && is_enabled "${stratum}"; then
if ! "${quiet}"; then eval "printf \"* ${color_cmd}%s${color_norm}\\n\" \"$cmd\""; fi
eval "$cmd"
fi
done
exit_success
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment