Advertisement
Guest User

Untitled

a guest
Jan 27th, 2015
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.54 KB | None | 0 0
  1. diff --git a/contrib/bash-completion b/contrib/bash-completion
  2. index 4f73fab..1463e17 100644
  3. --- a/contrib/bash-completion
  4. +++ b/contrib/bash-completion
  5. @@ -23,10 +23,10 @@ _netctl()
  6.  
  7. case $COMP_CWORD in
  8. 1)
  9. - COMPREPLY=( $(compgen -W "--help --version list store restore stop-all start stop restart switch-to status enable disable reenable is-enabled edit" -- "$cur") )
  10. + COMPREPLY=( $(compgen -W "--help --version list store restore stop-all start stop restart switch-to status enable disable reenable is-active is-enabled edit" -- "$cur") )
  11. ;;
  12. 2)
  13. - [[ ${COMP_WORDS[COMP_CWORD-1]} = @(start|stop|restart|switch-to|status|enable|disable|reenable|is-enabled|edit) ]] &&
  14. + [[ ${COMP_WORDS[COMP_CWORD-1]} = @(start|stop|restart|switch-to|status|enable|disable|reenable|is-active|is-enabled|edit) ]] &&
  15. mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$(_netctl_profiles)" -- "$cur")
  16. ;;
  17. esac
  18. @@ -40,10 +40,10 @@ _netctl_auto()
  19.  
  20. case $COMP_CWORD in
  21. 1)
  22. - COMPREPLY=( $(compgen -W "--help --version list current switch-to enable disable enable-all disable-all" -- "$cur") )
  23. + COMPREPLY=( $(compgen -W "--help --version list current switch-to enable disable enable-all disable-all is-active is-enabled" -- "$cur") )
  24. ;;
  25. 2)
  26. - [[ ${COMP_WORDS[COMP_CWORD-1]} = @(switch-to|enable|disable) ]] &&
  27. + [[ ${COMP_WORDS[COMP_CWORD-1]} = @(switch-to|enable|disable|is-active|is-enabled) ]] &&
  28. mapfile -t COMPREPLY < <(IFS=$'\n'; compgen -W "$(_netctl_profiles)" -- "$cur")
  29. ;;
  30. esac
  31. diff --git a/contrib/zsh-completion b/contrib/zsh-completion
  32. index 05c506f..26b8753 100644
  33. --- a/contrib/zsh-completion
  34. +++ b/contrib/zsh-completion
  35. @@ -11,7 +11,7 @@ _wireless_interfaces() {
  36.  
  37. (( $+function[_netctl_command] )) ||
  38. _netctl_command() {
  39. - [[ $words[1] = (start|stop|restart|switch-to|status|enable|disable|reenable|is-enabled|edit) ]] &&
  40. + [[ $words[1] = (start|stop|restart|switch-to|status|enable|disable|reenable|is-active|is-enabled|edit) ]] &&
  41. compadd "${(f)$(find -L /etc/netctl -maxdepth 1 -type f -not -name '.*' -not -name '*~' -not -name '*.conf' -not -name '*.service' -printf "%f\n")}"
  42. }
  43.  
  44. @@ -31,6 +31,7 @@ _netctl_commands() {
  45. 'enable:Enable the systemd unit for a profile'
  46. 'disable:Disable the systemd unit for a profile'
  47. 'reenable:Reenable the systemd unit for a profile'
  48. + 'is-active:Check whether a profile is active'
  49. 'is-enabled:Check whether a profile is enabled'
  50. 'edit:Edit a profile'
  51. )
  52. @@ -47,6 +48,8 @@ _netctl-auto_commands() {
  53. 'disable:Disable a profile temporarily for automatic selection'
  54. 'enable-all:Enable all profiles for automatic selection'
  55. 'disable-all:Disable all profiles temporarily for automatic selection'
  56. + 'is-active:Check whether a profile is active'
  57. + 'is-enabled:Check whether a profile is enabled'
  58. )
  59. _describe "netctl-auto commands" _commands
  60. }
  61. diff --git a/src/netctl-auto b/src/netctl-auto
  62. index b84c0de..ec51a46 100755
  63. --- a/src/netctl-auto
  64. +++ b/src/netctl-auto
  65. @@ -21,6 +21,8 @@ Commands:
  66. disable [PROFILE] Disable a profile temporarily for automatic selection
  67. enable-all Enable all profiles for automatic selection
  68. disable-all Disable all profiles temporarily for automatic selection
  69. + is-enabled [PROFILE] Check whether a profile is enabled
  70. + is-active [PROFILE] Check whether a profile is active
  71. END
  72. }
  73.  
  74. @@ -73,6 +75,44 @@ get_wpa_network_id() {
  75. return 1
  76. }
  77.  
  78. +## Print whether profile is active
  79. +# $2: profile name
  80. +is_active() {
  81. + local interface id flag profile exists
  82. + while read -r interface id flag profile; do
  83. + if [[ $profile == $1 ]]; then
  84. + if [[ $flag == 'a' ]]; then
  85. + printf "active\n"
  86. + return 0
  87. + else
  88. + printf "inactive\n"
  89. + return 1
  90. + fi
  91. + exists=0
  92. + fi
  93. + done < <(list_wpa_profiles)
  94. + [[ -z $exists ]] && (printf "unknown\n"; return 2)
  95. +}
  96. +
  97. +## Print whether profile is enabled
  98. +# $2: profile name
  99. +is_enabled() {
  100. + local interface id flag profile exists
  101. + while read -r interface id flag profile; do
  102. + if [[ $profile == $1 ]]; then
  103. + if [[ $flag == 'd' ]]; then
  104. + printf "disabled\n"
  105. + return 1
  106. + else
  107. + printf "enabled\n"
  108. + return 0
  109. + fi
  110. + exists=0
  111. + fi
  112. + done < <(list_wpa_profiles)
  113. + [[ -z $exists ]] && (printf "unknown\n"; return 2)
  114. +}
  115. +
  116. ## Enable or disable profiles in WPA supplicant
  117. # $1: profile action: "enable", "disable", "enable-all" or "disable-all"
  118. # $2: profile name if action is "enable" or "disable"
  119. @@ -245,6 +285,10 @@ case $# in
  120. esac;;
  121. 2)
  122. case $1 in
  123. + is-active)
  124. + is_active "$2";;
  125. + is-enabled)
  126. + is_enabled "$2";;
  127. enable|disable)
  128. profile_enable_disable "$1" "$2";;
  129. switch-to)
  130. diff --git a/src/netctl.in b/src/netctl.in
  131. index 2953ecf..bdac443 100644
  132. --- a/src/netctl.in
  133. +++ b/src/netctl.in
  134. @@ -22,6 +22,7 @@ Commands:
  135. disable [PROFILE] Disable the systemd unit for a profile
  136. reenable [PROFILE] Reenable the systemd unit for a profile
  137. is-enabled [PROFILE] Check whether a profile is enabled
  138. + is-active [PROFILE] Check whether a profile is active
  139. edit [PROFILE] Edit a profile
  140. END
  141. }
  142. @@ -48,6 +49,32 @@ sd_call() {
  143. systemctl $command $(printf 'netctl@%s.service\n' "$@")
  144. }
  145.  
  146. +is_active() {
  147. + if [[ ! $(list_profiles) =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
  148. + printf "unknown\n"
  149. + return 2
  150. + elif sd_call "is-active --quiet" "$1" 2> /dev/null; then
  151. + printf "active\n"
  152. + return 0
  153. + else
  154. + printf "inactive\n"
  155. + return 1
  156. + fi
  157. +}
  158. +
  159. +is_enabled() {
  160. + if [[ ! $(list_profiles) =~ (^|[[:space:]])$1($|[[:space:]]) ]]; then
  161. + printf "unknown\n"
  162. + return 2
  163. + elif sd_call "is-enabled --quiet" "$1" 2> /dev/null; then
  164. + printf "enabled\n"
  165. + return 0
  166. + else
  167. + printf "disabled\n"
  168. + return 1
  169. + fi
  170. +}
  171. +
  172. list() {
  173. local indicators=( '*' ' ' )
  174. list_profiles | while read -r Profile; do
  175. @@ -163,8 +190,12 @@ case $# in
  176. esac;;
  177. 2)
  178. case $1 in
  179. - start|stop|restart|status|is-enabled)
  180. + start|stop|restart|status)
  181. sd_call "$1" "$2";;
  182. + is-active)
  183. + is_active "$2";;
  184. + is-enabled)
  185. + is_enabled "$2";;
  186. switch-to)
  187. ensure_root "$(basename "$0")"
  188. switch_to "$2";;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement