upwifi 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #!/bin/sh
  2. #============Header=================================================|
  3. #AUTHOR
  4. # Jefferson Rocha <lrcjefferson@gmail.com>
  5. #
  6. #PROGRAM
  7. # UPWIFI - FOR SLACKWARE
  8. #===================================================================|
  9. #=====VARIABLES===================|
  10. # Your interface, example wlan0.
  11. # Sua interface exemplo wlan0.
  12. interface=""
  13. # Your network
  14. # Use command iwlist
  15. # Sua rede
  16. # Use o comando iwlist
  17. network=""
  18. # Your Password
  19. # Seu password da rede
  20. password=""
  21. # wpa-supplicant.conf
  22. supplicant="/etc/wpa_supplicant.conf"
  23. #=====TESTS=======================|
  24. # Root?
  25. [ "$UID" -ne "0" ] && { echo "Only Root."; exit 1;}
  26. # Vars null?
  27. for conf in "$interface" "$network" "$password"; do
  28. if [ -z "$conf" ]; then
  29. printf '%b\n' "\e[31;1mERROR, VARIABLE NULL IN SOURCE PROGRAM.\e[m"
  30. printf '%s\n' "USE ' upwifi help ' FOR HELP"
  31. exit 1
  32. fi
  33. done
  34. #=====FUNCTIONS==================|
  35. _start(){ # Function Only UP WIFI
  36. # Up wireless interface
  37. if ifconfig "${interface}" up; then
  38. printf '%b\n' "\e[32;1mINTERFACE ${interface} UP...[OK]\e[m"
  39. fi
  40. if wpa_supplicant -i "$interface" -c "supplicant" -B -D wext; then
  41. printf '%b\n' "\e[32;1mDaemon Mode...[OK]\e[m"
  42. else
  43. printf '%b\n' "\e[31;1mDaemon Mode ERROR!\e[m"
  44. exit 1
  45. fi
  46. # UP WIFI
  47. if dhclient "$interface"; then
  48. printf '%b\n' "\e[32;1mdhclient...[OK]\e[m"
  49. else
  50. printf '%b\n' "\e[32;1mdhclient ERROR...[X]"
  51. exit 1
  52. fi
  53. }
  54. _create(){ # Function Create all conf for run WIFI
  55. # Up wireless interface
  56. if ifconfig "${interface}" up; then
  57. printf '%b\n' "\e[32;1mINTERFACE ${interface} UP...[OK]\e[m"
  58. else
  59. printf '%b\n' "\e[31;1mINTERFACE ${interface} NO UP...[X]"
  60. exit 1
  61. fi
  62. if wpa_passphrase "$network" "$password" > "$supplicant"; then
  63. printf '%b\n' "\e[32;1m${supplicant} CREATED...[OK]\e[m"
  64. else
  65. printf '%b\n' "\e[31;1m${supplicant} NOT CREATED...[X]\e[m"
  66. exit 1
  67. fi
  68. }
  69. _usage(){
  70. clear
  71. cat <<END
  72. upwifi [OPTIONS]
  73. Manual USAGE.
  74. OPTIONS IN LINE:
  75. -----------------------------------------------------
  76. start
  77. Your conf file created? ok, now run upwifi:
  78. # upwifi start
  79. -----------------------------------------------------
  80. create
  81. For Create a new configuration use:
  82. # upwifi create
  83. Do not forget to fill in all variables present
  84. internally in the program ...
  85. !! FILL ALL THE FIELDS !!
  86. interface="INTERFACE HERE"
  87. network="NETWORK HERE"
  88. password="PASSWORD HERE"
  89. -----------------------------------------------------
  90. END
  91. }
  92. ############
  93. #START #
  94. ############
  95. # Call functions
  96. case "$1" in
  97. start) _start ;;
  98. create) _create ;;
  99. help) _usage ;;
  100. *) _usage ;;
  101. esac