Advertisement
TitanFail

Invoice Ninja Checker

Apr 4th, 2018
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.30 KB | None | 0 0
  1. #Simple script to check the current release of Invoice Ninja against what you have installed.
  2. #If you're current, installed will show the version number in green. If not current, in red.
  3. #Set "ninja_installed" to whatever the path is to your install's version.txt.
  4. #If you're using the auto-update script with cron, uncomment the bottom section and change
  5. #"cronjobtime" to whatever time you have the script set to run (HH:MM format) and it will tell
  6. #you if the update is going to run "today" or "tomorrow" based on what time you run the checker
  7. #(no good way to check the cron list directly). Drop in your /etc/update-motd.d/ if you want this
  8. #to run every time you login via terminal or SSH. Just save it with the appropriate number to
  9. #control where in the motd the output appears. As usual, use at your own risk.
  10.  
  11. #!/bin/bash
  12. ninja_installed=$(cat "/var/www/ninja/storage/version.txt")
  13. ninja_current="$((wget -T 15 -qO- https://invoiceninja.org/index.php) | (grep -oP 'Download Version \K[0-9]+\.[0-9]+(\.[0-9]+)'))"
  14.  
  15. update_required="no"
  16. set -f
  17. array_ninja_installed=(${ninja_installed//./ })
  18. array_ninja_current=(${ninja_current//./ })
  19.  
  20. if (( ${#array_ninja_installed[@]} == "2" ))
  21. then
  22.     array_ninja_installed+=("0")
  23. fi
  24.  
  25. for ((i=0; i<${#array_ninja_installed[@]}; i++))
  26. do
  27.     if (( ${array_ninja_installed[$i]} < ${array_ninja_current[$i]} ))
  28.     then
  29.     update_required="yes"
  30.     fi
  31. done
  32.  
  33. printf '\n|==============================|'
  34. printf '\n| Invoice Ninja Version Status |'
  35. printf '\n|==============================|'
  36. printf '\n| Current Release       \033[1;32mv%s\033[0m%s |' "$ninja_current"
  37. case $update_required in
  38.     no)
  39.     printf '\n| Installed Version     \033[1;32mv%s\033[0m%s |' "$ninja_installed"
  40.     ;;
  41.     yes)
  42.     printf '\n| Installed Version     \033[1;31mv%s\033[0m%s |' "$ninja_installed"
  43.     ;;
  44. esac
  45. printf '\n|==============================|\n'
  46.  
  47. #case $update_required in
  48. #    no)
  49. #    ;;
  50. #    yes)
  51. #    connecttime=$(date "+%H%M")
  52. #    cronjobtime="18:00"
  53. #    if (( "10#$connecttime" < "10#${cronjobtime//:}" ))
  54. #        then
  55. #            printf '\n\033[1;31mInvoice Ninja will update TODAY at %s\033[0m\n' "$cronjobtime"
  56. #        else
  57. #            printf '\n\033[1;32mInvoice Ninja will update TOMORROW at %s\033[0m\n' "$cronjobtime"
  58. #    fi
  59. #    ;;
  60. #esac
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement