daily pastebin goal
53%
SHARE
TWEET

Invoice Ninja Automatic Update Script v4.6.3

TitanFail Jul 3rd, 2017 (edited) 1,845 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 - USE AT YOUR OWN RISK
  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. #This does NOT backup the MySQL database. Use mysqldump if you would like to create a backup.
  6. #Replace lines 14 and 58 with your specifics (omit <>), obviously.
  7. #If using UPDATE_SECRET in the .env file, uncomment lines 64 & 83, and comment out line 84.
  8. #!!IMPORTANT!! Be sure to edit lines 17 & 18 if www-data is not the owner/group for /ninja/storage!
  9.  
  10.  
  11. #SET INITIAL VARIABLES
  12. #Remaining variables will be set if an update is required
  13. #--------------------------------------------------------
  14. ninja_home="</path/to/ninja>"
  15. ninja_storage="$ninja_home/storage"
  16. versiontxt="$ninja_storage/version.txt"
  17. storage_owner="www-data"
  18. storage_group="www-data"
  19.  
  20.  
  21. #GET INSTALLED AND CURRENT VERSION NUMBERS
  22. #--------------------------------------------------------
  23. ninja_installed=$(cat "$versiontxt")
  24. ninja_current=$((wget -qO- https://invoiceninja.org/index.php) | (grep -oP 'Download Version \K[0-9]+\.[0-9]+(\.[0-9]+)'))
  25.  
  26.  
  27. #SEE IF AN UPDATE IS REQUIRED
  28. #--------------------------------------------------------
  29. update_required="no"
  30. set -f
  31. array_ninja_installed=(${ninja_installed//./ })
  32. array_ninja_current=(${ninja_current//./ })
  33.  
  34. if (( ${#array_ninja_installed[@]} == "2" ))
  35. then
  36.     array_ninja_installed+=("0")
  37. fi
  38.  
  39. for ((i=0; i<${#array_ninja_installed[@]}; i++))
  40. do
  41.     if (( ${array_ninja_installed[$i]} < ${array_ninja_current[$i]} ))
  42.     then
  43.     update_required="yes"
  44.     fi
  45. done
  46.  
  47.  
  48. #MAIN UPDATE SECTION
  49. #--------------------------------------------------------
  50. case $update_required in
  51.     no)
  52.     printf '%s - Invoice Ninja v%s is installed and is current. No update required.\n' "$(date)" "$ninja_installed"
  53.     ;;
  54.     yes)
  55.     printf '\n%s - Updating Invoice Ninja from v%s to v%s.\n\n' "$(date)" "$ninja_installed" "$ninja_current"
  56.  
  57.     #Set remaining variables
  58.     tempdir="</download/path>/InvoiceNinja"
  59.     ninja_temp="$tempdir/ninja"    
  60.     ninja_file="ninja-v$ninja_current.zip"
  61.     ninja_url="https://download.invoiceninja.com/$ninja_file"
  62.     ninja_zip="$tempdir/$ninja_file"
  63.     app_url="$(grep -oP '(?<=APP_URL=).*' "$ninja_home/.env")"
  64.     #update_key="$(grep -oP '(?<=UPDATE_SECRET).*' "$ninja_home/.env")"
  65.    
  66.     printf 'Downloading Invoice Ninja v%s archive "%s" ...\n\n' "$ninja_current" "$ninja_url"
  67.     wget -P "$tempdir/" "$ninja_url"
  68.    
  69.     printf 'Extracting to temporary folder "%s" ...\n\n' "$tempdir"
  70.     unzip -q "$ninja_zip" -d "$tempdir/"
  71.    
  72.     printf 'Syncing to install folder "%s" ...\n' "$ninja_home"
  73.     sudo rsync -tr --stats "$ninja_temp/" "$ninja_home/"
  74.    
  75.     printf '\nResetting permissions for "%s" ...\n\n' "$ninja_storage"
  76.     sudo chown -R "$storage_owner":"$storage_group" "$ninja_storage/"
  77.     sudo chmod -R 775 "$ninja_storage/"
  78.    
  79.     printf 'Removing downloaded ZIP file "%s" ...\n\nRemoving temporary folder "%s" ...\n\n' "$ninja_zip" "$tempdir"
  80.     rm -rf "$tempdir/"
  81.    
  82.     printf 'Running update migration commands (%s/update)...\n\n' "$app_url"
  83.     #wget -q --spider "$app_url/update?secret=$update_key"
  84.     wget -q --spider "$app_url/update"
  85.    
  86.     printf '%s - Invoice Ninja successfully updated to v%s!\n\n' "$(date)" "$ninja_current"
  87.     ;;
  88. esac
RAW Paste Data
Top