summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2012-11-25 03:21:56 +0100
committerDave Reisner <dreisner@archlinux.org>2012-11-26 02:08:57 +0100
commit8155250bcdce4737a0fdb1d3009d9878f61ee324 (patch)
tree8454ec34f25224e6cdd6085584644c534172da12
parent78fb526649cc730d9c20be47112db945a4a8427b (diff)
downloadmkinitcpio-8155250bcdce4737a0fdb1d3009d9878f61ee324.tar.gz
mkinitcpio-8155250bcdce4737a0fdb1d3009d9878f61ee324.tar.xz
handle deprecation notices in -H and -L
Separate out the printing from these flags to separate functions and examine each hook more closely, pointing out where it might be deprecated, and what should be used in place of it. Signed-off-by: Dave Reisner <dreisner@archlinux.org>
-rw-r--r--functions12
-rwxr-xr-xmkinitcpio96
2 files changed, 90 insertions, 18 deletions
diff --git a/functions b/functions
index f46a9ae..10a072c 100644
--- a/functions
+++ b/functions
@@ -193,6 +193,18 @@ in_array() {
return 1 # Not Found
}
+index_of() {
+ # get the array index of an item. size limit of 254 items!
+ local item=$1; shift
+
+ for (( i=1; i <= $#; i++ )); do
+ [[ $item = ${!i} ]] && return $(( --i ))
+ done
+
+ # not found
+ return 255
+}
+
funcgrep() {
awk -v funcmatch="$1" '
/^[[:space:]]*[[:alnum:]_]+[[:space:]]*\([[:space:]]*\)/ {
diff --git a/mkinitcpio b/mkinitcpio
index fbcef82..e7b19c1 100755
--- a/mkinitcpio
+++ b/mkinitcpio
@@ -108,6 +108,81 @@ resolve_kernver() {
return 1
}
+hook_help() {
+ local resolved script=$(PATH=$_d_install type -p "$1")
+
+ # this will be true for broken symlinks as well
+ if [[ -z $script ]]; then
+ error "Hook '%s' not found" "$1"
+ return 1
+ fi
+
+ if [[ -L $script ]]; then
+ resolved=$(readlink -e "$script")
+ msg "This hook is deprecated. See the '%s' hook" "${resolved##*/}"
+ return 0
+ fi
+
+ . "$script"
+ if ! declare -f help >/dev/null; then
+ error "No help for hook $1"
+ return 1
+ fi
+
+ msg "Help for hook '$1':"
+ help
+
+ list_hookpoints "$1"
+}
+
+hook_list() {
+ local n p hook resolved
+ local -a paths hooklist depr
+
+ IFS=: read -ra paths <<<"$_d_install"
+
+ for path in "${paths[@]}"; do
+ for hook in "$path"/*; do
+ [[ -e $hook || -L $hook ]] || continue
+
+ # handle deprecated hooks and point to replacement
+ if [[ -L $hook ]]; then
+ resolved=$(readlink -e "$hook")
+
+ if [[ -z $resolved ]]; then
+ error "found broken symlink '%s'" "$hook"
+ continue
+ fi
+
+ resolved=${resolved##*/}
+
+ index_of "$resolved" "${depr[@]}"
+
+ n=$?
+ if (( n == 255 )); then
+ # deprecated hook
+ depr+=("$resolved")
+ n=$(( ${#depr[*]} - 1 ))
+ fi
+
+ hook=$hook[$n]
+ fi
+
+ hooklist+=("${hook##*/}")
+ done
+ done
+
+ msg "Available hooks"
+ printf '%s\n' "${hooklist[@]}" | sort -u | column -c$(tput cols)
+
+ if (( ${#depr[*]} )); then
+ echo
+ for p in "${!depr[@]}"; do
+ printf "[%s]: This hook is deprecated in favor of '%s'\n" "$p" "${depr[p]}"
+ done
+ fi
+}
+
compute_hookset() {
local h
@@ -315,25 +390,10 @@ while :; do
unset skip ;;
-H|--hookhelp)
shift
- if PATH=$_d_install . "$1"; then
- if ! declare -f help >/dev/null; then
- error "No help for hook $1"
- exit 1
- fi
- else
- error "No hook '$1'"
- exit 1
- fi
- msg "Help for hook '$1':"
- help
- list_hookpoints "$1"
- exit 0 ;;
+ hook_help "$1"
+ exit ;;
-L|--listhooks)
- msg "Available hooks"
- IFS=: read -ra _dirs <<<"$_d_install"
- for dir in "${_dirs[@]}"; do
- ( cd "$dir" &>/dev/null && printf ' %s\n' * )
- done | sort -u | column -c$(tput cols)
+ hook_list
exit 0 ;;
-M|--automods)
_optshowautomods=1 ;;