Advertisement
Guest User

Untitled

a guest
Apr 19th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. configurePath=/etc/network/interfaces
  2. interface="$1"
  3. ip="$2"
  4. mask="$3"
  5. gateway="$4"
  6. dns="$5"
  7.  
  8. testPermission(){
  9. if [ $(id -u) -ne 0 ]; then
  10. echo "You need root access\n"
  11. exit 1
  12. fi
  13. }
  14.  
  15. clearFile(){
  16. if [ -f "$configurePath" ]; then
  17. sudo rm "$configurePath"
  18. fi
  19. }
  20.  
  21. stringInterface(){
  22. local stringInterface="auto $interface\n"
  23. stringInterface+="iface $interface inet static\n"
  24. stringInterface+=" address $ip\n"
  25. stringInterface+=" netmask $mask\n"
  26. stringInterface+=" gateway $gateway\n"
  27. stringInterface+=" dns-nameservers $dns\n"
  28.  
  29. echo "$stringInterface"
  30. }
  31.  
  32. createInterface(){
  33. sudo echo -e "$(stringInterface)" | sudo tee "$configurePath"
  34. }
  35.  
  36. testInterface(){
  37. sudo /etc/init.d/networking restart
  38. }
  39.  
  40. testPermission
  41. createInterface
  42. testInterface
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement