| 1 | # |
| 2 | # Authors: |
| 3 | # Tomas Halman <[email protected]> |
| 4 | # |
| 5 | # Copyright (C) 2019 Red Hat |
| 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License as published by |
| 9 | # the Free Software Foundation; either version 3 of the License, or |
| 10 | # (at your option) any later version. |
| 11 | # |
| 12 | # This program is distributed in the hope that it will be useful, |
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | # GNU General Public License for more details. |
| 16 | # |
| 17 | # You should have received a copy of the GNU General Public License |
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | # |
| 20 | # |
| 21 | # provides autocompletion for authselect command |
| 22 | # |
| 23 | |
| 24 | _authselect_completionsscip-shell shell shell-project 0.0.0 _authselect_completions().() |
| 25 | { |
| 26 | local COMMANDS |
| 27 | local command |
| 28 | local possibleopts |
| 29 | |
| 30 | function is_valid_commandscip-shell shell shell-project 0.0.0 is_valid_command().() { |
| 31 | local cmd |
| 32 | |
| 33 | for cmd in "${COMMANDS[@]}"; do |
| 34 | if [[ "$cmd" = "$1" ]]; then |
| 35 | return 0 |
| 36 | fi |
| 37 | done |
| 38 | return 1 |
| 39 | } |
| 40 | |
| 41 | function get_commandscip-shell shell shell-project 0.0.0 get_command().() { |
| 42 | local opt |
| 43 | |
| 44 | if [[ $COMP_CWORD -lt 2 ]] ; then |
| 45 | return |
| 46 | fi |
| 47 | for opt in "${COMP_WORDS[@]:0:$COMP_CWORD}"; do |
| 48 | if is_valid_commandscip-shell shell shell-project 0.0.0 is_valid_command(). "$opt"; then |
| 49 | echoscip-shell system . . echo. "$opt" |
| 50 | return |
| 51 | fi |
| 52 | done |
| 53 | } |
| 54 | |
| 55 | function get_command_paramscip-shell shell shell-project 0.0.0 get_command_param().() { |
| 56 | local havecmd=0 |
| 57 | local len=${#COMP_WORDS[@]}-1 |
| 58 | |
| 59 | if [[ "$command" = "" ]]; then |
| 60 | return |
| 61 | fi |
| 62 | havecmd=0 |
| 63 | for (( i=0; i<$len; i++ )); do |
| 64 | if [[ "$havecmd" = "1" ]] ; then |
| 65 | if [[ "${COMP_WORDS[$i]}" =~ ^[-=] || "${COMP_WORDS[$i-1]}" = "=" ]] ; then |
| 66 | continue |
| 67 | fi |
| 68 | echo "${COMP_WORDS[$i]}" |
| 69 | return |
| 70 | fi |
| 71 | if [[ "${COMP_WORDS[$i]}" = "$command" ]] ; then |
| 72 | havecmd=1 |
| 73 | fi |
| 74 | done |
| 75 | } |
| 76 | |
| 77 | function get_profilescip-shell shell shell-project 0.0.0 get_profile().() { |
| 78 | case "$command" in |
| 79 | select|show|requirements|test|list-features) |
| 80 | get_command_paramscip-shell shell shell-project 0.0.0 get_command_param(). |
| 81 | ;; |
| 82 | enable-feature|disable-feature) |
| 83 | authselect current 2>/dev/nullscip-shell filesystem . . `/dev/null`. | headscip-shell system . . head. -n1 | cutscip-shell system . . cut. -d" " -f3 |
| 84 | ;; |
| 85 | esac |
| 86 | } |
| 87 | |
| 88 | function get_command_keywordsscip-shell shell shell-project 0.0.0 get_command_keywords().() { |
| 89 | local profile |
| 90 | |
| 91 | case "$command" in |
| 92 | select|requirements|test) |
| 93 | profile="$(get_profilescip-shell shell shell-project 0.0.0 get_profile().)" |
| 94 | if [[ "$profile" != "" ]] ; then |
| 95 | authselect list-features "$profile" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 96 | fi |
| 97 | ;; |
| 98 | esac |
| 99 | } |
| 100 | |
| 101 | function get_command_optionsscip-shell shell shell-project 0.0.0 get_command_options().() { |
| 102 | if [[ "${COMP_WORDS[$COMP_CWORD]}" =~ ^- ]] ; then |
| 103 | case "$command" in |
| 104 | select) |
| 105 | echoscip-shell system . . echo. "--force --quiet --nobackup --backup=" |
| 106 | ;; |
| 107 | apply-changes|disable-feature) |
| 108 | echoscip-shell system . . echo. "--backup=" |
| 109 | ;; |
| 110 | enable-feature) |
| 111 | echoscip-shell system . . echo. "--backup= --quiet" |
| 112 | ;; |
| 113 | current|backup-list) |
| 114 | echoscip-shell system . . echo. "--raw" |
| 115 | ;; |
| 116 | create-profile) |
| 117 | echoscip-shell system . . echo. "--vendor --base-on= --base-on-default" \ |
| 118 | "--symlink-meta --symlink-nsswitch --symlink-pam" \ |
| 119 | "--symlink-dconf --symlink=" |
| 120 | ;; |
| 121 | test) |
| 122 | echoscip-shell system . . echo. "--all --nsswitch --system-auth --password-auth" \ |
| 123 | "--smartcard-auth --fingerprint-auth --postlogin" \ |
| 124 | "--dconf-db --dconf-lock" |
| 125 | ;; |
| 126 | esac |
| 127 | fi |
| 128 | } |
| 129 | |
| 130 | function get_global_optionsscip-shell shell shell-project 0.0.0 get_global_options().() { |
| 131 | if [[ "${COMP_WORDS[$COMP_CWORD]}" =~ ^- ]] ; then |
| 132 | echoscip-shell system . . echo. "--debug --trace --warn --help" |
| 133 | fi |
| 134 | } |
| 135 | |
| 136 | function get_option_paramsscip-shell shell shell-project 0.0.0 get_option_params().() { |
| 137 | local opt |
| 138 | |
| 139 | if [[ $COMP_CWORD -gt 2 && "${COMP_WORDS[$COMP_CWORD-1]}" = "=" ]] ; then |
| 140 | opt="${COMP_WORDS[$COMP_CWORD-2]}" |
| 141 | else |
| 142 | if [[ $COMP_CWORD -gt 1 ]] ; then |
| 143 | opt="${COMP_WORDS[$COMP_CWORD-1]}" |
| 144 | fi |
| 145 | fi |
| 146 | case "$opt" in |
| 147 | --base-on) |
| 148 | authselect list 2>/dev/nullscip-shell filesystem . . `/dev/null`. | cutscip-shell system . . cut. -d" " -f2 |
| 149 | ;; |
| 150 | --symlink) |
| 151 | echoscip-shell system . . echo. "dconf-db dconf-locks fingerprint-auth nsswitch.conf" \ |
| 152 | "password-auth postlogin smartcard-auth system-auth" \ |
| 153 | "README REQUIREMENTS" |
| 154 | ;; |
| 155 | esac |
| 156 | |
| 157 | } |
| 158 | |
| 159 | function get_command_paramsscip-shell shell shell-project 0.0.0 get_command_params().() { |
| 160 | local i |
| 161 | local profile |
| 162 | |
| 163 | if [[ "$command" = "" ]]; then |
| 164 | return |
| 165 | fi |
| 166 | for (( i=$COMP_CWORD-1; i>1; i-- )); do |
| 167 | opt="${COMP_WORDS[$i]}" |
| 168 | if [[ "$opt" = "$command" ]] ; then |
| 169 | break |
| 170 | fi |
| 171 | if [[ "$opt" =~ ^[-=] || "${COMP_WORDS[$i-1]}" = "=" ]] ; then |
| 172 | continue |
| 173 | fi |
| 174 | return |
| 175 | done |
| 176 | case "$command" in |
| 177 | select|show|requirements|test|list-features) |
| 178 | authselect list 2>/dev/nullscip-shell filesystem . . `/dev/null`. | cutscip-shell system . . cut. -d" " -f2 |
| 179 | ;; |
| 180 | backup-remove|backup-restore) |
| 181 | authselect backup-list 2>/dev/nullscip-shell filesystem . . `/dev/null`. | cutscip-shell system . . cut. -d" " -f1 |
| 182 | ;; |
| 183 | enable-feature|disable-feature) |
| 184 | profile="$(get_profilescip-shell shell shell-project 0.0.0 get_profile().)" |
| 185 | if [[ "$profile" != "" ]] ; then |
| 186 | authselect list-features "$profile" 2>/dev/nullscip-shell filesystem . . `/dev/null`. |
| 187 | fi |
| 188 | ;; |
| 189 | esac |
| 190 | } |
| 191 | |
| 192 | COMMANDS=(select apply-changes list list-features show requirements current |
| 193 | check test enable-feature disable-feature create-profile |
| 194 | backup-list backup-remove backup-restore opt-out) |
| 195 | |
| 196 | possibleopts="$(get_option_paramsscip-shell shell shell-project 0.0.0 get_option_params().)" |
| 197 | if [[ "$possibleopts" != "" ]]; then |
| 198 | if [[ "${COMP_WORDS[$COMP_CWORD]}" = "=" ]]; then |
| 199 | COMPREPLY=($(compgen -W "$possibleopts")) |
| 200 | else |
| 201 | COMPREPLY=($(compgen -W "$possibleopts" -- "${COMP_WORDS[$COMP_CWORD]}")) |
| 202 | fi |
| 203 | else |
| 204 | command="$(get_commandscip-shell shell shell-project 0.0.0 get_command().)" |
| 205 | if [[ "$command" = "" ]]; then |
| 206 | possibleopts="$(get_global_optionsscip-shell shell shell-project 0.0.0 get_global_options().) ${COMMANDS[@]}" |
| 207 | else |
| 208 | possibleopts="$(get_global_optionsscip-shell shell shell-project 0.0.0 get_global_options().) $(get_command_paramsscip-shell shell shell-project 0.0.0 get_command_params().) $(get_command_keywordsscip-shell shell shell-project 0.0.0 get_command_keywords().) $(get_command_optionsscip-shell shell shell-project 0.0.0 get_command_options().)" |
| 209 | fi |
| 210 | COMPREPLY=($(compgen -W "$possibleopts" -- "${COMP_WORDS[$COMP_CWORD]}")) |
| 211 | fi |
| 212 | } |
| 213 | |
| 214 | complete -F _authselect_completions authselect |