TitanFail

Invoice Ninja Automatic Update Script v4.7.1

Jul 3rd, 2017
9,167
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/bash -ue
  2. #Invoice Ninja Self-Hosted Update
  3. #PLEASE SEE THE README AT https://pastebin.com/nwcSH0TH
  4.  
  5.  
  6. #SET INVOICE NINJA INSTALL AND STORAGE PATHS
  7. #--------------------------------------------------------
  8. sudo updatedb
  9. ninja_home="$(locate -b '\composer.json' | xargs grep -l "invoiceninja/invoiceninja" | xargs -n 1 dirname)"
  10. ninja_storage="$ninja_home/storage"
  11.  
  12.  
  13. #GET INSTALLED AND CURRENT VERSION NUMBERS
  14. #--------------------------------------------------------
  15. versiontxt="$ninja_storage/version.txt"
  16. ninja_installed="$(cat "$versiontxt")"
  17. ninja_current="$((wget -T 15 -qO- https://invoiceninja.org/index.php) | (grep -oP 'Download Version \K[0-9]+\.[0-9]+(\.[0-9]+)'))"
  18.  
  19.  
  20. #SEE IF AN UPDATE IS REQUIRED
  21. #--------------------------------------------------------
  22. update_required="no"
  23. set -f
  24. array_ninja_installed=(${ninja_installed//./ })
  25. array_ninja_current=(${ninja_current//./ })
  26.  
  27. if (( ${#array_ninja_installed[@]} == "2" ))
  28. then
  29.     array_ninja_installed+=("0")
  30. fi
  31.  
  32. for ((i=0; i<${#array_ninja_installed[@]}; i++))
  33. do
  34.     if (( ${array_ninja_installed[$i]} < ${array_ninja_current[$i]} ))
  35.     then
  36.     update_required="yes"
  37.     fi
  38. done
  39.  
  40.  
  41. #MAIN UPDATE SECTION
  42. #--------------------------------------------------------
  43. case $update_required in
  44.     no)
  45.     printf '%s - Invoice Ninja v%s is installed and is current. No update required.\n' "$(date)" "$ninja_installed"
  46.     ;;
  47.     yes)
  48.     printf '\n%s - Updating Invoice Ninja from v%s to v%s.\n\n' "$(date)" "$ninja_installed" "$ninja_current"
  49.  
  50.     #Set remaining variables
  51.     tempdir="/usr/local/download/InvoiceNinja"
  52.     ninja_temp="$tempdir/ninja"
  53.     ninja_file="ninja-v$ninja_current.zip"
  54.     ninja_url="https://download.invoiceninja.com/$ninja_file"
  55.     ninja_zip="$tempdir/$ninja_file"
  56.     ninja_env="$ninja_home/.env"
  57.     update_url="$(grep -oP '(?<=APP_URL=).*' "$ninja_env")""/update"
  58.     storage_owner="$(stat -c "%U" "$ninja_storage")"
  59.     storage_group="$(stat -c "%G" "$ninja_storage")"
  60.  
  61.         printf 'Deleting file "%s" (if it exists)...\n\n' "$ninja_home/bootstrap/cache/compiled.php"
  62.         set +e
  63.         sudo rm "$ninja_home/bootstrap/cache/compiled.php"
  64.         set -e
  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)...\n\n' "$update_url"
  83.     case $(grep -c "UPDATE_SECRET" "$ninja_env") in
  84.     0)
  85.         wget -q --spider "$update_url"
  86.         ;;
  87.     1)
  88.         update_key="$(grep -oP '(?<=UPDATE_SECRET=).*' "$ninja_env")"
  89.         wget -q --spider "$update_url"?secret="$update_key"
  90.         ;;
  91.     esac
  92.  
  93.     printf '%s - Invoice Ninja successfully updated to v%s!\n\n' "$(date)" "$ninja_current"
  94.     ;;
  95. esac
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×