This file is indexed.

/etc/bash_completion.d/drbdadm is in drbd8-utils 2:8.3.11-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#
# /etc/bash_completion.d/drbdadm
#
# Bash completion for the DRBD top-level management application, drbdadm.
#
# If you have bash completion enabled, this module will
#
# - provide tab completion for drbdadm sub-commands (up, down, primary,
#   secondary etc.);
#
# - try to detect your current resource state and provide appropriate
#   command completion for the sub-command you provided. For example,
#   when if you have entered the "primary" sub-command, it will list
#   only those resources that are currently in the Secondary role;
#
# - differentiate between stacked and unstacked resources.
#
# This module does NOT guarantee that the DRBD state engine will in
# fact agree to do what you ask it to. For example, resources that are
# currently Primary and not connected are not excluded from the
# completion list for the "detach" sub-command.
#
# Finally, this module is only capable of parsing resources correctly
# if you are using the default location for your DRBD configuration
# file (/etc/drbd.conf).

__drbdadm_all_resources() {
	# Detects all resources currently listed in drbd.conf
	local resources="$(${DRBDADM} sh-resources) all"
	COMPREPLY=( $(compgen -W "$resources" -- "$current") )
}

__drbdadm_resources_by_status() {
	# Detects only those resources that match a particular status
	local status_type="$1"
	shift 1
	local status_filter="$*"
	local resources="$(${DRBDADM} sh-resources)"
	local filtered_resources
	local res
	for res in $resources; do
		local resource_status="$(${DRBDADM} $status_type $res 2>/dev/null)"
		local i
		for i in $status_filter; do
			if [ "${resource_status%%/*}" = $i ]; then
				filtered_resources="$filtered_resources $res"
			fi
		done
	done
	COMPREPLY=( $(compgen -W "$filtered_resources" -- "$current") )
}

__drbdadm_commands() {
	# Lists drbdadm sub-commands
	local commands='attach detach connect disconnect up down primary secondary invalidate invalidate-remote outdate verify syncer pause-sync resume-sync resize adjust wait-connect role state cstate dstate dump wait-connect wait-con-int create-md dump-md wipe-md get-gi show-gi help hidden-commands'
	COMPREPLY=( $(compgen -W "$commands" -- "$current") )
}

__drbdadm_options() {
	# Lists global drbdadm options
	local options='-d --dry-run -v --verbose -S --stacked'
	COMPREPLY=( $(compgen -W "$options" -- "$current") )
}

__drbdadm_drbdsetup_options() {
	# Lists those drbdadm options that are in fact options for drbdsetup,
	# and which are passed though using "--" syntax
	local drbdsetup_options='-D --discard-my-data -o --overwrite-data-of-peer'
	COMPREPLY=( $(compgen -W "$drbdsetup_options" -- "$current") )
}

_drbdadm() {
	local DRBDADM=${COMP_WORDS[0]}

	# Redefine the drbdadm we use in __drbdadm_all_resources and
	# __drbdadm_resources_by_status, if running in stacked mode
	case "$COMP_LINE " in
	*" -S "*|*" --stacked "*)
		DRBDADM="$DRBDADM --stacked"
		;;
	esac
	
	local current previous
	# The word currently being evaluated for completion
	current=${COMP_WORDS[COMP_CWORD]}
	# The word that precedes the currently-evaluated one
	previous=${COMP_WORDS[COMP_CWORD-1]}

	case "$previous" in
		drbdadm)
			case "$current" in
				-*)
					__drbdadm_options
					;;
				*)
					__drbdadm_commands
					;;
			esac
			;;
		--)
			__drbdadm_drbdsetup_options
			;;
		-D|--discard-my-data)
			COMPREPLY=( $(compgen -W "connect" -- "$current") )
			;;
		-o|--overwrite-data-of-peer)
			COMPREPLY=( $(compgen -W "primary" -- "$current") )
			;;
		-*)
			__drbdadm_commands
			;;
		primary)
			__drbdadm_resources_by_status "role" "Secondary"
			;;
		secondary)
			__drbdadm_resources_by_status "role" "Primary"
			;;
		detach)
			__drbdadm_resources_by_status "dstate" "UpToDate" "Inconsistent" "Outdated"
			;;
		outdate)
			__drbdadm_resources_by_status "dstate" "UpToDate"
			;;
		attach|up)
			__drbdadm_resources_by_status "dstate" "Diskless" "Unconfigured"
			;;
		connect)
			__drbdadm_resources_by_status "cstate" "StandAlone" "Unconfigured"
			;;
		invalidate-remote)
			__drbdadm_resources_by_status "cstate" "Connected"
			;;
		disconnect)
			__drbdadm_resources_by_status "cstate" "Connected" "WFConnection" "VerifyT" "VerifyS"
			;;
		verify)
			__drbdadm_resources_by_status "cstate" "Connected"
			;;
		pause-sync)
			__drbdadm_resources_by_status "cstate" "SyncSource" "SyncTarget"
			;;
		resume-sync)
			__drbdadm_resources_by_status "cstate" "PausedSyncS" "PausedSyncT"
			;;
		*) 
			__drbdadm_all_resources
			;;
	esac
}

complete -o default -F _drbdadm drbdadm