SHARE
TWEET

Invoice Ninja Automatic Update Script v4.5.7

TitanFail Jul 3rd, 2017 (edited) 341 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash -ue
  2. #Invoice Ninja Self-Hosted Automatic Update
  3. #This version will check https://invoiceninja.org for an updated version and install if found.
  4. #Tested and works with cron. Lines 51, 54, & 79 output timestamps so you can pipe to a logfile.
  5. #USE AT YOUR OWN RISK
  6. #Replace </path/to/ninja> (line 13) and </download/path> (line 57) with your specifics, obviously.
  7. #!!IMPORTANT!! Be sure to edit lines 16 & 17 if www-data is not the owner/group for /ninja/storage!
  8.  
  9.  
  10. #SET INITIAL VARIABLES
  11. #Remaining variables will be set if an update is required
  12. #--------------------------------------------------------
  13. ninja_home="</path/to/ninja>"
  14. ninja_storage="$ninja_home/storage"
  15. versiontxt="$ninja_storage/version.txt"
  16. storage_owner="www-data"
  17. storage_group="www-data"
  18.  
  19.  
  20. #GET INSTALLED AND CURRENT VERSION NUMBERS
  21. #--------------------------------------------------------
  22. ninja_installed=$(cat "$versiontxt")
  23. ninja_current=$((wget -qO- https://invoiceninja.org/index.php) | (grep -oP 'Download Version \K[0-9]+\.[0-9]+(\.[0-9]+)'))
  24.  
  25.  
  26. #SEE IF AN UPDATE IS REQUIRED
  27. #--------------------------------------------------------
  28. update_required="no"
  29. set -f
  30. array_ninja_installed=(${ninja_installed//./ })
  31. array_ninja_current=(${ninja_current//./ })
  32.  
  33. if (( ${#array_ninja_installed[@]} == "2" ))
  34. then
  35.     array_ninja_installed+=("0")
  36. fi
  37.  
  38. for ((i=0; i<${#array_ninja_installed[@]}; i++))
  39. do
  40.     if (( ${array_ninja_installed[$i]} < ${array_ninja_current[$i]} ))
  41.     then
  42.     update_required="yes"
  43.     fi
  44. done
  45.  
  46.  
  47. #MAIN UPDATE SECTION
  48. #--------------------------------------------------------
  49. case $update_required in
  50.     no)
  51.     printf '%s - Invoice Ninja v%s is installed and is current. No update required.\n' "$(date)" "$ninja_installed"
  52.     ;;
  53.     yes)
  54.     printf '\n%s - Updating Invoice Ninja from v%s to v%s.\n\n' "$(date)" "$ninja_installed" "$ninja_current"
  55.  
  56.     #Set remaining variables
  57.     tempdir="</download/path>/InvoiceNinja"
  58.     ninja_temp="$tempdir/ninja"    
  59.     ninja_file="ninja-v$ninja_current.zip"
  60.     ninja_url="https://download.invoiceninja.com/$ninja_file"
  61.     ninja_zip="$tempdir/$ninja_file"
  62.    
  63.     printf 'Downloading Invoice Ninja v%s archive "%s" ...\n\n' "$ninja_current" "$ninja_url"
  64.     wget -P "$tempdir/" "$ninja_url"
  65.    
  66.     printf 'Extracting to temporary folder "%s" ...\n\n' "$tempdir"
  67.     unzip -q "$ninja_zip" -d "$tempdir/"
  68.    
  69.     printf 'Syncing to install folder "%s" ...\n' "$ninja_home"
  70.     sudo rsync -tr --stats "$ninja_temp/" "$ninja_home/"
  71.    
  72.     printf '\nResetting permissions for "%s" ...\n\n' "$ninja_storage"
  73.     sudo chown -R "$storage_owner":"$storage_group" "$ninja_storage/"
  74.     sudo chmod -R 775 "$ninja_storage/"
  75.    
  76.     printf 'Removing downloaded ZIP file "%s" ...\n\nRemoving temporary folder "%s" ...\n\n' "$ninja_zip" "$tempdir"
  77.     rm -rf "$tempdir/"
  78.    
  79.     printf '%s - Invoice Ninja successfully updated to v%s!\n\n' "$(date)" "$ninja_current"
  80.     ;;
  81. esac
RAW Paste Data
Top