loongbedrocklinux-userlandd/src/slash-bedrock/libexec/brl-rename

64 lines
1.9 KiB
Plaintext
Executable File

#!/bedrock/libexec/busybox sh
#
# brl rename
#
# 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) 2016-2018 Daniel Thau <danthau@bedrocklinux.org>
#
# Renames strata and aliases.
. /bedrock/share/common-code
print_help() {
printf "
Usage: ${color_cmd}brl rename ${color_sub}[options] <stratum> <new-name>${color_norm}
Renames ${color_term}strata${color_norm} and ${color_term}aliases${color_norm}. Requires root. Can only be applied to ${color_term}disabled${color_norm}
${color_term}strata${color_norm}.
Options:
${color_cmd}-h${color_norm}, ${color_cmd}--help${color_norm} print this message
Examples:
${color_cmd}$ brl list unignored | grep -e debian -e stretch
${color_strat}debian
${color_rcmd}# brl rename debian stretch
${color_cmd}$ brl list unignored | grep -e debian -e stretch
${color_strat}stretch
${color_norm}"
}
handle_help "${@:-}"
min_args "${#}" "2"
stratum="${1}"
new_name="${2}"
require_root
lock
if ! is_stratum_or_alias "${stratum}"; then
abort "No stratum or alias found called \"${stratum}\"."
elif is_stratum_or_alias "${new_name}"; then
abort "Pre-existing stratum or alias found called \"${new_name}\". Remove with \`brl remove ${stratum}\` first."
elif [ "${stratum}" = "init" ]; then
abort "Renaming init alias is disallowed."
elif is_bedrock "${stratum}"; then
abort "Renaming bedrock stratum is disallowed."
elif is_init "${stratum}"; then
abort "Renaming init-providing stratum is disallowed."
elif is_stratum "${stratum}" && is_enabled "${stratum}"; then
abort "\"${stratum}\" is enabled. Disable with \`brl disable ${stratum}\` first."
fi
ensure_legal_stratum_name "${new_name}"
if is_stratum "${stratum}"; then
disable_stratum "${stratum}"
fi
mv "/bedrock/strata/${stratum}" "/bedrock/strata/${new_name}"
exit_success