Guest User

Untitled

a guest
Jan 19th, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. #!/bin/bash
  2. ## Switch php version
  3. ## Command line need only one argument, it's php version
  4.  
  5. exists()
  6. {
  7. command -v "$1" >/dev/null 2>&1
  8. }
  9.  
  10. ##< Allowed only for admin
  11. if ! [ $(id -u) = 0 ]; then
  12. echo "The script need to be run as root." >&2
  13. exit 1
  14. fi
  15.  
  16. ##< Check existing parameters
  17. if [ $# -gt 0 ]; then
  18.  
  19. if exists "php$1"; then
  20. echo 'This version php exists!'
  21. echo "Starting switching to php$1..."
  22.  
  23. ##< Unlinking the old PHP version
  24. if [ -f /usr/bin/php ]; then
  25. unlink /usr/bin/php
  26. fi;
  27. unlink /etc/alternatives/php
  28.  
  29. ##< Linking new PHP version
  30. ln -s /usr/bin/php$1 /etc/alternatives/php
  31. if ! [ -f /usr/bin/php ]; then
  32. ln -s /etc/alternatives/php /usr/bin/php
  33. fi;
  34.  
  35. echo "PHP version have switched:"
  36. php -v
  37. exit 0
  38.  
  39. else
  40. echo 'Your system does not have this php version. Firstly install it...'
  41. fi
  42.  
  43. else
  44. echo "Your command line contains no arguments, specify version of php..."
  45. fi
Add Comment
Please, Sign In to add comment